summary refs log tree commit diff
path: root/library/alloc/tests/vec_deque.rs
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-11-05 10:29:35 +0100
committerGitHub <noreply@github.com>2020-11-05 10:29:35 +0100
commit55f4b802fb91ee366ebca8a333dc01f04e0d71e5 (patch)
tree32474b1ad6c09f641d29536d546069688e397ec8 /library/alloc/tests/vec_deque.rs
parent8c2070121905b66698ebbfb105eab30f3484e602 (diff)
parent1bdee96c5e6de445f09df34447a42553294f21ed (diff)
downloadrust-55f4b802fb91ee366ebca8a333dc01f04e0d71e5.tar.gz
rust-55f4b802fb91ee366ebca8a333dc01f04e0d71e5.zip
Rollup merge of #76718 - poliorcetics:vec-ui-to-unit-test, r=jyn514
Move Vec UI tests to unit tests when possible

Helps with #76268.

I'm moving the tests using `Vec` or `VecDeque`.

````@rustbot```` modify labels: A-testsuite C-cleanup T-libs
Diffstat (limited to 'library/alloc/tests/vec_deque.rs')
-rw-r--r--library/alloc/tests/vec_deque.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/library/alloc/tests/vec_deque.rs b/library/alloc/tests/vec_deque.rs
index 05cb3a2c03d..705f0d62fbb 100644
--- a/library/alloc/tests/vec_deque.rs
+++ b/library/alloc/tests/vec_deque.rs
@@ -1698,3 +1698,33 @@ fn test_binary_search_by_key() {
     assert_eq!(deque.binary_search_by_key(&3, |&(v,)| v), Ok(2));
     assert_eq!(deque.binary_search_by_key(&4, |&(v,)| v), Err(3));
 }
+
+#[test]
+fn test_zero_sized_push() {
+    const N: usize = 8;
+
+    // Zero sized type
+    struct Zst;
+
+    // Test that for all possible sequences of push_front / push_back,
+    // we end up with a deque of the correct size
+
+    for len in 0..N {
+        let mut tester = VecDeque::with_capacity(len);
+        assert_eq!(tester.len(), 0);
+        assert!(tester.capacity() >= len);
+        for case in 0..(1 << len) {
+            assert_eq!(tester.len(), 0);
+            for bit in 0..len {
+                if case & (1 << bit) != 0 {
+                    tester.push_front(Zst);
+                } else {
+                    tester.push_back(Zst);
+                }
+            }
+            assert_eq!(tester.len(), len);
+            assert_eq!(tester.iter().count(), len);
+            tester.clear();
+        }
+    }
+}