File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1698,3 +1698,33 @@ fn test_binary_search_by_key() {
1698
1698
assert_eq ! ( deque. binary_search_by_key( & 3 , |& ( v, ) | v) , Ok ( 2 ) ) ;
1699
1699
assert_eq ! ( deque. binary_search_by_key( & 4 , |& ( v, ) | v) , Err ( 3 ) ) ;
1700
1700
}
1701
+
1702
+ #[ test]
1703
+ fn test_zero_sized_push ( ) {
1704
+ const N : usize = 8 ;
1705
+
1706
+ // Zero sized type
1707
+ struct Zst ;
1708
+
1709
+ // Test that for all possible sequences of push_front / push_back,
1710
+ // we end up with a deque of the correct size
1711
+
1712
+ for len in 0 ..N {
1713
+ let mut tester = VecDeque :: with_capacity ( len) ;
1714
+ assert_eq ! ( tester. len( ) , 0 ) ;
1715
+ assert ! ( tester. capacity( ) >= len) ;
1716
+ for case in 0 ..( 1 << len) {
1717
+ assert_eq ! ( tester. len( ) , 0 ) ;
1718
+ for bit in 0 ..len {
1719
+ if case & ( 1 << bit) != 0 {
1720
+ tester. push_front ( Zst ) ;
1721
+ } else {
1722
+ tester. push_back ( Zst ) ;
1723
+ }
1724
+ }
1725
+ assert_eq ! ( tester. len( ) , len) ;
1726
+ assert_eq ! ( tester. iter( ) . count( ) , len) ;
1727
+ tester. clear ( ) ;
1728
+ }
1729
+ }
1730
+ }
You can’t perform that action at this time.
0 commit comments