From cb5e4292911f3651aa3453ad1d81b2794f4b2583 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 11 Mar 2015 19:44:02 -0500 Subject: [PATCH] move some tests back to libcollections --- mk/tests.mk | 2 +- src/libcollections/lib.rs | 4 + src/libcollections/linked_list.rs | 191 +++++++++++++++++++ src/libcollections/macros.rs | 15 ++ src/libcollections/slice.rs | 93 +++++++++ src/libcollections/str.rs | 1 + src/libcollections/string.rs | 9 + src/libcollections/vec.rs | 6 + src/libcollections/vec_deque.rs | 245 ++++++++++++++++++++++++ src/libcollectionstest/linked_list.rs | 192 ------------------- src/libcollectionstest/slice.rs | 56 ------ src/libcollectionstest/vec_deque.rs | 262 -------------------------- 12 files changed, 565 insertions(+), 511 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index 0851909a776..0d1067a87e0 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -22,7 +22,7 @@ $(eval $(call RUST_CRATE,coretest)) DEPS_collectionstest := $(eval $(call RUST_CRATE,collectionstest)) -TEST_TARGET_CRATES = $(filter-out collections core unicode,$(TARGET_CRATES)) \ +TEST_TARGET_CRATES = $(filter-out core unicode,$(TARGET_CRATES)) \ collectionstest coretest TEST_DOC_CRATES = $(DOC_CRATES) TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve rustc_trans rustc_lint,\ diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 0d53215a596..b75f346c188 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -47,6 +47,9 @@ extern crate core; extern crate unicode; extern crate alloc; +#[cfg(test)] #[macro_use] extern crate std; +#[cfg(test)] extern crate test; + pub use binary_heap::BinaryHeap; pub use bit_vec::BitVec; pub use bit_set::BitSet; @@ -131,6 +134,7 @@ pub mod btree_set { #[doc(hidden)] pub fn fixme_14344_be_sure_to_link_to_collections() {} +#[cfg(not(test))] mod std { pub use core::ops; // RangeFull } diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index 0799e14e657..9e0a6d04381 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -938,3 +938,194 @@ impl Hash for LinkedList { } } } + +#[cfg(test)] +mod test { + use std::clone::Clone; + use std::iter::{Iterator, IteratorExt}; + use std::option::Option::{Some, None, self}; + use std::rand; + use std::thread; + use std::vec::Vec; + + use super::{LinkedList, Node}; + + #[cfg(test)] + fn list_from(v: &[T]) -> LinkedList { + v.iter().cloned().collect() + } + + pub fn check_links(list: &LinkedList) { + let mut len = 0; + let mut last_ptr: Option<&Node> = None; + let mut node_ptr: &Node; + match list.list_head { + None => { assert_eq!(0, list.length); return } + Some(ref node) => node_ptr = &**node, + } + loop { + match (last_ptr, node_ptr.prev.resolve_immut()) { + (None , None ) => {} + (None , _ ) => panic!("prev link for list_head"), + (Some(p), Some(pptr)) => { + assert_eq!(p as *const Node, pptr as *const Node); + } + _ => panic!("prev link is none, not good"), + } + match node_ptr.next { + Some(ref next) => { + last_ptr = Some(node_ptr); + node_ptr = &**next; + len += 1; + } + None => { + len += 1; + break; + } + } + } + assert_eq!(len, list.length); + } + + #[test] + fn test_append() { + // Empty to empty + { + let mut m = LinkedList::::new(); + let mut n = LinkedList::new(); + m.append(&mut n); + check_links(&m); + assert_eq!(m.len(), 0); + assert_eq!(n.len(), 0); + } + // Non-empty to empty + { + let mut m = LinkedList::new(); + let mut n = LinkedList::new(); + n.push_back(2); + m.append(&mut n); + check_links(&m); + assert_eq!(m.len(), 1); + assert_eq!(m.pop_back(), Some(2)); + assert_eq!(n.len(), 0); + check_links(&m); + } + // Empty to non-empty + { + let mut m = LinkedList::new(); + let mut n = LinkedList::new(); + m.push_back(2); + m.append(&mut n); + check_links(&m); + assert_eq!(m.len(), 1); + assert_eq!(m.pop_back(), Some(2)); + check_links(&m); + } + + // Non-empty to non-empty + let v = vec![1,2,3,4,5]; + let u = vec![9,8,1,2,3,4,5]; + let mut m = list_from(&v); + let mut n = list_from(&u); + m.append(&mut n); + check_links(&m); + let mut sum = v; + sum.push_all(&u); + assert_eq!(sum.len(), m.len()); + for elt in sum { + assert_eq!(m.pop_front(), Some(elt)) + } + assert_eq!(n.len(), 0); + // let's make sure it's working properly, since we + // did some direct changes to private members + n.push_back(3); + assert_eq!(n.len(), 1); + assert_eq!(n.pop_front(), Some(3)); + check_links(&n); + } + + #[test] + fn test_insert_prev() { + let mut m = list_from(&[0,2,4,6,8]); + let len = m.len(); + { + let mut it = m.iter_mut(); + it.insert_next(-2); + loop { + match it.next() { + None => break, + Some(elt) => { + it.insert_next(*elt + 1); + match it.peek_next() { + Some(x) => assert_eq!(*x, *elt + 2), + None => assert_eq!(8, *elt), + } + } + } + } + it.insert_next(0); + it.insert_next(1); + } + check_links(&m); + assert_eq!(m.len(), 3 + len * 2); + assert_eq!(m.into_iter().collect::>(), [-2,0,1,2,3,4,5,6,7,8,9,0,1]); + } + + #[test] + fn test_send() { + let n = list_from(&[1,2,3]); + thread::spawn(move || { + check_links(&n); + let a: &[_] = &[&1,&2,&3]; + assert_eq!(a, n.iter().collect::>()); + }).join().ok().unwrap(); + } + + #[test] + fn test_fuzz() { + for _ in 0..25 { + fuzz_test(3); + fuzz_test(16); + fuzz_test(189); + } + } + + #[cfg(test)] + fn fuzz_test(sz: i32) { + let mut m: LinkedList<_> = LinkedList::new(); + let mut v = vec![]; + for i in 0..sz { + check_links(&m); + let r: u8 = rand::random(); + match r % 6 { + 0 => { + m.pop_back(); + v.pop(); + } + 1 => { + if !v.is_empty() { + m.pop_front(); + v.remove(0); + } + } + 2 | 4 => { + m.push_front(-i); + v.insert(0, -i); + } + 3 | 5 | _ => { + m.push_back(i); + v.push(i); + } + } + } + + check_links(&m); + + let mut i = 0; + for (a, &b) in m.into_iter().zip(v.iter()) { + i += 1; + assert_eq!(a, b); + } + assert_eq!(i, v.len()); + } +} diff --git a/src/libcollections/macros.rs b/src/libcollections/macros.rs index cb84e01e4f7..be3d8f8dbb6 100644 --- a/src/libcollections/macros.rs +++ b/src/libcollections/macros.rs @@ -71,6 +71,7 @@ macro_rules! vec { /// Note that unlike array expressions this syntax supports all elements /// which implement `Clone` and the number of elements doesn't have to be /// a constant. +#[cfg(not(test))] #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] macro_rules! vec { @@ -83,6 +84,20 @@ macro_rules! vec { ($($x:expr,)*) => (vec![$($x),*]) } +// HACK: `impl [T]` is not available in cfg(test), use `::slice::into_vec`, instead of +// `<[T]>::to_vec` +#[cfg(not(stage0))] +#[cfg(test)] +macro_rules! vec { + ($elem:expr; $n:expr) => ( + $crate::vec::from_elem($elem, $n) + ); + ($($x:expr),*) => ( + $crate::slice::into_vec($crate::boxed::Box::new([$($x),*])) + ); + ($($x:expr,)*) => (vec![$($x),*]) +} + /// Use the syntax described in `std::fmt` to create a value of type `String`. /// See `std::fmt` for more information. /// diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 15b67376887..dafe0edbf32 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1083,9 +1083,36 @@ impl SliceExt for [T] { } } +// HACK: With cfg(test) `impl [T]` is not available, these three functions are actually methods +// that are in `impl [T]` but not in `core::slice::SliceExt` - this is only need for testing +#[cfg(test)] +pub fn into_vec(mut b: Box<[T]>) -> Vec { + unsafe { + let xs = Vec::from_raw_parts(b.as_mut_ptr(), b.len(), b.len()); + mem::forget(b); + xs + } +} + +#[cfg(test)] +pub fn permutations(s: &[T]) -> Permutations where T: Clone { + Permutations{ + swaps: ElementSwaps::new(s.len()), + v: ::slice::to_vec(s), + } +} + +#[cfg(test)] +pub fn to_vec(s: &[T]) -> Vec where T: Clone { + let mut vector = Vec::with_capacity(s.len()); + vector.push_all(s); + vector +} + #[cfg(not(stage0))] /// Allocating extension methods for slices. #[lang = "slice"] +#[cfg(not(test))] #[stable(feature = "rust1", since = "1.0.0")] impl [T] { /// Sorts the slice, in place, using `compare` to compare @@ -2022,7 +2049,13 @@ impl BorrowMut<[T]> for Vec { #[stable(feature = "rust1", since = "1.0.0")] impl ToOwned for [T] { type Owned = Vec; + #[cfg(not(test))] fn to_owned(&self) -> Vec { self.to_vec() } + + // HACK: `impl [T]` is not available in cfg(test), use `::slice::to_vec` instead of + // `<[T]>::to_vec` + #[cfg(test)] + fn to_owned(&self) -> Vec { ::slice::to_vec(self) } } //////////////////////////////////////////////////////////////////////////////// @@ -2339,3 +2372,63 @@ fn merge_sort(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order old } } + +#[cfg(test)] +mod test { + use core::iter::{Iterator, IteratorExt}; + use core::option::Option::{None, Some}; + use string::ToString; + + #[test] + fn test_permutations() { + { + let v: [i32; 0] = []; + let mut it = ::slice::permutations(&v); + let (min_size, max_opt) = it.size_hint(); + assert_eq!(min_size, 1); + assert_eq!(max_opt.unwrap(), 1); + assert_eq!(it.next(), Some(::slice::to_vec(&v))); + assert_eq!(it.next(), None); + } + { + let v = ["Hello".to_string()]; + let mut it = ::slice::permutations(&v); + let (min_size, max_opt) = it.size_hint(); + assert_eq!(min_size, 1); + assert_eq!(max_opt.unwrap(), 1); + assert_eq!(it.next(), Some(::slice::to_vec(&v))); + assert_eq!(it.next(), None); + } + { + let v = [1, 2, 3]; + let mut it = ::slice::permutations(&v); + let (min_size, max_opt) = it.size_hint(); + assert_eq!(min_size, 3*2); + assert_eq!(max_opt.unwrap(), 3*2); + assert_eq!(it.next().unwrap(), [1,2,3]); + assert_eq!(it.next().unwrap(), [1,3,2]); + assert_eq!(it.next().unwrap(), [3,1,2]); + let (min_size, max_opt) = it.size_hint(); + assert_eq!(min_size, 3); + assert_eq!(max_opt.unwrap(), 3); + assert_eq!(it.next().unwrap(), [3,2,1]); + assert_eq!(it.next().unwrap(), [2,3,1]); + assert_eq!(it.next().unwrap(), [2,1,3]); + assert_eq!(it.next(), None); + } + { + // check that we have N! permutations + let v = ['A', 'B', 'C', 'D', 'E', 'F']; + let mut amt = 0; + let mut it = ::slice::permutations(&v); + let (min_size, max_opt) = it.size_hint(); + for _perm in it.by_ref() { + amt += 1; + } + assert_eq!(amt, it.swaps.swaps_made); + assert_eq!(amt, min_size); + assert_eq!(amt, 2 * 3 * 4 * 5 * 6); + assert_eq!(amt, max_opt.unwrap()); + } + } +} diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index fc93b0b75a7..a99372f178b 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1562,6 +1562,7 @@ impl StrExt for str { #[cfg(not(stage0))] /// Any string that can be represented as a slice. #[lang = "str"] +#[cfg(not(test))] #[stable(feature = "rust1", since = "1.0.0")] impl str { /// Escapes each char in `s` with `char::escape_default`. diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 6d1b929cf60..fdc7cf993b1 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -113,10 +113,19 @@ impl String { #[inline] #[unstable(feature = "collections", reason = "needs investigation to see if to_string() can match perf")] + #[cfg(not(test))] pub fn from_str(string: &str) -> String { String { vec: <[_]>::to_vec(string.as_bytes()) } } + // HACK: `impl [T]` is not available in cfg(test), use `::slice::to_vec` instead of + // `<[T]>::to_vec` + #[inline] + #[cfg(test)] + pub fn from_str(string: &str) -> String { + String { vec: ::slice::to_vec(string.as_bytes()) } + } + /// Returns the vector as a string buffer, if possible, taking care not to /// copy it. /// diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 22da0a191ca..6aaebe08f5c 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1287,8 +1287,14 @@ impl Clone for Vec { fn clone(&self) -> Vec { ::slice::SliceExt::to_vec(&**self) } #[cfg(not(stage0))] + #[cfg(not(test))] fn clone(&self) -> Vec { <[T]>::to_vec(&**self) } + // HACK: `impl [T]` not available in cfg(test), use `::slice::to_vec` instead of `<[T]>::to_vec` + #[cfg(not(stage0))] + #[cfg(test)] + fn clone(&self) -> Vec { ::slice::to_vec(&**self) } + fn clone_from(&mut self, other: &Vec) { // drop anything in self that will not be overwritten if self.len() > other.len() { diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 700ee059a7f..95d43fa8fc0 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -1768,3 +1768,248 @@ impl fmt::Debug for VecDeque { write!(f, "]") } } + +#[cfg(test)] +mod test { + use core::iter::{IteratorExt, self}; + use core::option::Option::Some; + + use test; + + use super::VecDeque; + + #[bench] + fn bench_push_back_100(b: &mut test::Bencher) { + let mut deq = VecDeque::with_capacity(101); + b.iter(|| { + for i in 0..100 { + deq.push_back(i); + } + deq.head = 0; + deq.tail = 0; + }) + } + + #[bench] + fn bench_push_front_100(b: &mut test::Bencher) { + let mut deq = VecDeque::with_capacity(101); + b.iter(|| { + for i in 0..100 { + deq.push_front(i); + } + deq.head = 0; + deq.tail = 0; + }) + } + + #[bench] + fn bench_pop_back_100(b: &mut test::Bencher) { + let mut deq= VecDeque::::with_capacity(101); + + b.iter(|| { + deq.head = 100; + deq.tail = 0; + while !deq.is_empty() { + test::black_box(deq.pop_back()); + } + }) + } + + #[bench] + fn bench_pop_front_100(b: &mut test::Bencher) { + let mut deq = VecDeque::::with_capacity(101); + + b.iter(|| { + deq.head = 100; + deq.tail = 0; + while !deq.is_empty() { + test::black_box(deq.pop_front()); + } + }) + } + + #[test] + fn test_swap_front_back_remove() { + fn test(back: bool) { + // This test checks that every single combination of tail position and length is tested. + // Capacity 15 should be large enough to cover every case. + let mut tester = VecDeque::with_capacity(15); + let usable_cap = tester.capacity(); + let final_len = usable_cap / 2; + + for len in 0..final_len { + let expected = if back { + (0..len).collect() + } else { + (0..len).rev().collect() + }; + for tail_pos in 0..usable_cap { + tester.tail = tail_pos; + tester.head = tail_pos; + if back { + for i in 0..len * 2 { + tester.push_front(i); + } + for i in 0..len { + assert_eq!(tester.swap_back_remove(i), Some(len * 2 - 1 - i)); + } + } else { + for i in 0..len * 2 { + tester.push_back(i); + } + for i in 0..len { + let idx = tester.len() - 1 - i; + assert_eq!(tester.swap_front_remove(idx), Some(len * 2 - 1 - i)); + } + } + assert!(tester.tail < tester.cap); + assert!(tester.head < tester.cap); + assert_eq!(tester, expected); + } + } + } + test(true); + test(false); + } + + #[test] + fn test_insert() { + // This test checks that every single combination of tail position, length, and + // insertion position is tested. Capacity 15 should be large enough to cover every case. + + let mut tester = VecDeque::with_capacity(15); + // can't guarantee we got 15, so have to get what we got. + // 15 would be great, but we will definitely get 2^k - 1, for k >= 4, or else + // this test isn't covering what it wants to + let cap = tester.capacity(); + + + // len is the length *after* insertion + for len in 1..cap { + // 0, 1, 2, .., len - 1 + let expected = iter::count(0, 1).take(len).collect(); + for tail_pos in 0..cap { + for to_insert in 0..len { + tester.tail = tail_pos; + tester.head = tail_pos; + for i in 0..len { + if i != to_insert { + tester.push_back(i); + } + } + tester.insert(to_insert, to_insert); + assert!(tester.tail < tester.cap); + assert!(tester.head < tester.cap); + assert_eq!(tester, expected); + } + } + } + } + + #[test] + fn test_remove() { + // This test checks that every single combination of tail position, length, and + // removal position is tested. Capacity 15 should be large enough to cover every case. + + let mut tester = VecDeque::with_capacity(15); + // can't guarantee we got 15, so have to get what we got. + // 15 would be great, but we will definitely get 2^k - 1, for k >= 4, or else + // this test isn't covering what it wants to + let cap = tester.capacity(); + + // len is the length *after* removal + for len in 0..cap - 1 { + // 0, 1, 2, .., len - 1 + let expected = iter::count(0, 1).take(len).collect(); + for tail_pos in 0..cap { + for to_remove in 0..len + 1 { + tester.tail = tail_pos; + tester.head = tail_pos; + for i in 0..len { + if i == to_remove { + tester.push_back(1234); + } + tester.push_back(i); + } + if to_remove == len { + tester.push_back(1234); + } + tester.remove(to_remove); + assert!(tester.tail < tester.cap); + assert!(tester.head < tester.cap); + assert_eq!(tester, expected); + } + } + } + } + + #[test] + fn test_shrink_to_fit() { + // This test checks that every single combination of head and tail position, + // is tested. Capacity 15 should be large enough to cover every case. + + let mut tester = VecDeque::with_capacity(15); + // can't guarantee we got 15, so have to get what we got. + // 15 would be great, but we will definitely get 2^k - 1, for k >= 4, or else + // this test isn't covering what it wants to + let cap = tester.capacity(); + tester.reserve(63); + let max_cap = tester.capacity(); + + for len in 0..cap + 1 { + // 0, 1, 2, .., len - 1 + let expected = iter::count(0, 1).take(len).collect(); + for tail_pos in 0..max_cap + 1 { + tester.tail = tail_pos; + tester.head = tail_pos; + tester.reserve(63); + for i in 0..len { + tester.push_back(i); + } + tester.shrink_to_fit(); + assert!(tester.capacity() <= cap); + assert!(tester.tail < tester.cap); + assert!(tester.head < tester.cap); + assert_eq!(tester, expected); + } + } + } + + #[test] + fn test_split_off() { + // This test checks that every single combination of tail position, length, and + // split position is tested. Capacity 15 should be large enough to cover every case. + + let mut tester = VecDeque::with_capacity(15); + // can't guarantee we got 15, so have to get what we got. + // 15 would be great, but we will definitely get 2^k - 1, for k >= 4, or else + // this test isn't covering what it wants to + let cap = tester.capacity(); + + // len is the length *before* splitting + for len in 0..cap { + // index to split at + for at in 0..len + 1 { + // 0, 1, 2, .., at - 1 (may be empty) + let expected_self = iter::count(0, 1).take(at).collect(); + // at, at + 1, .., len - 1 (may be empty) + let expected_other = iter::count(at, 1).take(len - at).collect(); + + for tail_pos in 0..cap { + tester.tail = tail_pos; + tester.head = tail_pos; + for i in 0..len { + tester.push_back(i); + } + let result = tester.split_off(at); + assert!(tester.tail < tester.cap); + assert!(tester.head < tester.cap); + assert!(result.tail < result.cap); + assert!(result.head < result.cap); + assert_eq!(tester, expected_self); + assert_eq!(result, expected_other); + } + } + } + } +} diff --git a/src/libcollectionstest/linked_list.rs b/src/libcollectionstest/linked_list.rs index 95d49885b3b..fd73938095f 100644 --- a/src/libcollectionstest/linked_list.rs +++ b/src/libcollectionstest/linked_list.rs @@ -13,41 +13,6 @@ use std::hash::{SipHasher, self}; use test; -// FIXME(japaric) privacy -/* -pub fn check_links(list: &LinkedList) { - let mut len = 0; - let mut last_ptr: Option<&Node> = None; - let mut node_ptr: &Node; - match list.list_head { - None => { assert_eq!(0, list.length); return } - Some(ref node) => node_ptr = &**node, - } - loop { - match (last_ptr, node_ptr.prev.resolve_immut()) { - (None , None ) => {} - (None , _ ) => panic!("prev link for list_head"), - (Some(p), Some(pptr)) => { - assert_eq!(p as *const Node, pptr as *const Node); - } - _ => panic!("prev link is none, not good"), - } - match node_ptr.next { - Some(ref next) => { - last_ptr = Some(node_ptr); - node_ptr = &**next; - len += 1; - } - None => { - len += 1; - break; - } - } - } - assert_eq!(len, list.length); -} -*/ - #[test] fn test_basic() { let mut m = LinkedList::>::new(); @@ -98,66 +63,6 @@ fn list_from(v: &[T]) -> LinkedList { v.iter().cloned().collect() } -// FIXME(japaric) privacy -/* -#[test] -fn test_append() { - // Empty to empty - { - let mut m = LinkedList::::new(); - let mut n = LinkedList::new(); - m.append(&mut n); - check_links(&m); - assert_eq!(m.len(), 0); - assert_eq!(n.len(), 0); - } - // Non-empty to empty - { - let mut m = LinkedList::new(); - let mut n = LinkedList::new(); - n.push_back(2); - m.append(&mut n); - check_links(&m); - assert_eq!(m.len(), 1); - assert_eq!(m.pop_back(), Some(2)); - assert_eq!(n.len(), 0); - check_links(&m); - } - // Empty to non-empty - { - let mut m = LinkedList::new(); - let mut n = LinkedList::new(); - m.push_back(2); - m.append(&mut n); - check_links(&m); - assert_eq!(m.len(), 1); - assert_eq!(m.pop_back(), Some(2)); - check_links(&m); - } - - // Non-empty to non-empty - let v = vec![1,2,3,4,5]; - let u = vec![9,8,1,2,3,4,5]; - let mut m = list_from(&v); - let mut n = list_from(&u); - m.append(&mut n); - check_links(&m); - let mut sum = v; - sum.push_all(&u); - assert_eq!(sum.len(), m.len()); - for elt in sum { - assert_eq!(m.pop_front(), Some(elt)) - } - assert_eq!(n.len(), 0); - // let's make sure it's working properly, since we - // did some direct changes to private members - n.push_back(3); - assert_eq!(n.len(), 1); - assert_eq!(n.pop_front(), Some(3)); - check_links(&n); -} -*/ - #[test] fn test_split_off() { // singleton @@ -318,36 +223,6 @@ fn test_iterator_mut_double_end() { assert!(it.next().is_none()); } -// FIXME(japaric) privacy -/* -#[test] -fn test_insert_prev() { - let mut m = list_from(&[0,2,4,6,8]); - let len = m.len(); - { - let mut it = m.iter_mut(); - it.insert_next(-2); - loop { - match it.next() { - None => break, - Some(elt) => { - it.insert_next(*elt + 1); - match it.peek_next() { - Some(x) => assert_eq!(*x, *elt + 2), - None => assert_eq!(8, *elt), - } - } - } - } - it.insert_next(0); - it.insert_next(1); - } - check_links(&m); - assert_eq!(m.len(), 3 + len * 2); - assert_eq!(m.into_iter().collect::>(), [-2,0,1,2,3,4,5,6,7,8,9,0,1]); -} -*/ - #[test] fn test_mut_rev_iter() { let mut m = generate_test(); @@ -362,19 +237,6 @@ fn test_mut_rev_iter() { assert!(it.next().is_none()); } -// FIXME(japaric) privacy -/* -#[test] -fn test_send() { - let n = list_from(&[1,2,3]); - thread::spawn(move || { - check_links(&n); - let a: &[_] = &[&1,&2,&3]; - assert_eq!(a, n.iter().collect::>()); - }).join().ok().unwrap(); -} -*/ - #[test] fn test_eq() { let mut n = list_from(&[]); @@ -450,18 +312,6 @@ fn test_ord_nan() { assert!(s >= one); } -// FIXME(japaric) privacy -/* -#[test] -fn test_fuzz() { - for _ in 0..25 { - fuzz_test(3); - fuzz_test(16); - fuzz_test(189); - } -} -*/ - #[test] fn test_show() { let list: LinkedList<_> = (0..10).collect(); @@ -471,48 +321,6 @@ fn test_show() { assert_eq!(format!("{:?}", list), "[\"just\", \"one\", \"test\", \"more\"]"); } -// FIXME(japaric) privacy -/* -#[cfg(test)] -fn fuzz_test(sz: i32) { - let mut m: LinkedList<_> = LinkedList::new(); - let mut v = vec![]; - for i in 0..sz { - check_links(&m); - let r: u8 = rand::random(); - match r % 6 { - 0 => { - m.pop_back(); - v.pop(); - } - 1 => { - if !v.is_empty() { - m.pop_front(); - v.remove(0); - } - } - 2 | 4 => { - m.push_front(-i); - v.insert(0, -i); - } - 3 | 5 | _ => { - m.push_back(i); - v.push(i); - } - } - } - - check_links(&m); - - let mut i = 0; - for (a, &b) in m.into_iter().zip(v.iter()) { - i += 1; - assert_eq!(a, b); - } - assert_eq!(i, v.len()); -} -*/ - #[bench] fn bench_collect_into(b: &mut test::Bencher) { let v = &[0; 64]; diff --git a/src/libcollectionstest/slice.rs b/src/libcollectionstest/slice.rs index 7d50a1a13f2..0c3c82eea78 100644 --- a/src/libcollectionstest/slice.rs +++ b/src/libcollectionstest/slice.rs @@ -406,62 +406,6 @@ fn test_element_swaps() { } } -// FIXME(japaric) privacy -/* -#[test] -fn test_permutations() { - { - let v: [i32; 0] = []; - let mut it = v.permutations(); - let (min_size, max_opt) = it.size_hint(); - assert_eq!(min_size, 1); - assert_eq!(max_opt.unwrap(), 1); - assert_eq!(it.next(), Some(v.to_vec())); - assert_eq!(it.next(), None); - } - { - let v = ["Hello".to_string()]; - let mut it = v.permutations(); - let (min_size, max_opt) = it.size_hint(); - assert_eq!(min_size, 1); - assert_eq!(max_opt.unwrap(), 1); - assert_eq!(it.next(), Some(v.to_vec())); - assert_eq!(it.next(), None); - } - { - let v = [1, 2, 3]; - let mut it = v.permutations(); - let (min_size, max_opt) = it.size_hint(); - assert_eq!(min_size, 3*2); - assert_eq!(max_opt.unwrap(), 3*2); - assert_eq!(it.next(), Some(vec![1,2,3])); - assert_eq!(it.next(), Some(vec![1,3,2])); - assert_eq!(it.next(), Some(vec![3,1,2])); - let (min_size, max_opt) = it.size_hint(); - assert_eq!(min_size, 3); - assert_eq!(max_opt.unwrap(), 3); - assert_eq!(it.next(), Some(vec![3,2,1])); - assert_eq!(it.next(), Some(vec![2,3,1])); - assert_eq!(it.next(), Some(vec![2,1,3])); - assert_eq!(it.next(), None); - } - { - // check that we have N! permutations - let v = ['A', 'B', 'C', 'D', 'E', 'F']; - let mut amt = 0; - let mut it = v.permutations(); - let (min_size, max_opt) = it.size_hint(); - for _perm in it.by_ref() { - amt += 1; - } - assert_eq!(amt, it.swaps.swaps_made); - assert_eq!(amt, min_size); - assert_eq!(amt, 2 * 3 * 4 * 5 * 6); - assert_eq!(amt, max_opt.unwrap()); - } -} -*/ - #[test] fn test_lexicographic_permutations() { let v : &mut[_] = &mut[1, 2, 3, 4, 5]; diff --git a/src/libcollectionstest/vec_deque.rs b/src/libcollectionstest/vec_deque.rs index ba2ed36de21..38f358c1505 100644 --- a/src/libcollectionstest/vec_deque.rs +++ b/src/libcollectionstest/vec_deque.rs @@ -137,68 +137,6 @@ fn bench_new(b: &mut test::Bencher) { }) } -// FIXME(japaric) privacy -/* -#[bench] -fn bench_push_back_100(b: &mut test::Bencher) { - let mut deq = VecDeque::with_capacity(101); - b.iter(|| { - for i in 0..100 { - deq.push_back(i); - } - deq.head = 0; - deq.tail = 0; - }) -} -*/ - -// FIXME(japaric) privacy -/* -#[bench] -fn bench_push_front_100(b: &mut test::Bencher) { - let mut deq = VecDeque::with_capacity(101); - b.iter(|| { - for i in 0..100 { - deq.push_front(i); - } - deq.head = 0; - deq.tail = 0; - }) -} -*/ - -// FIXME(japaric) privacy -/* -#[bench] -fn bench_pop_back_100(b: &mut test::Bencher) { - let mut deq= VecDeque::::with_capacity(101); - - b.iter(|| { - deq.head = 100; - deq.tail = 0; - while !deq.is_empty() { - test::black_box(deq.pop_back()); - } - }) -} -*/ - -// FIXME(japaric) privacy -/* -#[bench] -fn bench_pop_front_100(b: &mut test::Bencher) { - let mut deq = VecDeque::::with_capacity(101); - - b.iter(|| { - deq.head = 100; - deq.tail = 0; - while !deq.is_empty() { - test::black_box(deq.pop_front()); - } - }) -} -*/ - #[bench] fn bench_grow_1025(b: &mut test::Bencher) { b.iter(|| { @@ -860,165 +798,6 @@ fn test_get_mut() { assert_eq!(ring.get_mut(2), None); } -// FIXME(japaric) privacy -/* -#[test] -fn test_swap_front_back_remove() { - fn test(back: bool) { - // This test checks that every single combination of tail position and length is tested. - // Capacity 15 should be large enough to cover every case. - let mut tester = VecDeque::with_capacity(15); - let usable_cap = tester.capacity(); - let final_len = usable_cap / 2; - - for len in 0..final_len { - let expected = if back { - (0..len).collect() - } else { - (0..len).rev().collect() - }; - for tail_pos in 0..usable_cap { - tester.tail = tail_pos; - tester.head = tail_pos; - if back { - for i in 0..len * 2 { - tester.push_front(i); - } - for i in 0..len { - assert_eq!(tester.swap_back_remove(i), Some(len * 2 - 1 - i)); - } - } else { - for i in 0..len * 2 { - tester.push_back(i); - } - for i in 0..len { - let idx = tester.len() - 1 - i; - assert_eq!(tester.swap_front_remove(idx), Some(len * 2 - 1 - i)); - } - } - assert!(tester.tail < tester.cap); - assert!(tester.head < tester.cap); - assert_eq!(tester, expected); - } - } - } - test(true); - test(false); -} -*/ - -// FIXME(japaric) privacy -/* -#[test] -fn test_insert() { - // This test checks that every single combination of tail position, length, and - // insertion position is tested. Capacity 15 should be large enough to cover every case. - - let mut tester = VecDeque::with_capacity(15); - // can't guarantee we got 15, so have to get what we got. - // 15 would be great, but we will definitely get 2^k - 1, for k >= 4, or else - // this test isn't covering what it wants to - let cap = tester.capacity(); - - - // len is the length *after* insertion - for len in 1..cap { - // 0, 1, 2, .., len - 1 - let expected = iter::count(0, 1).take(len).collect(); - for tail_pos in 0..cap { - for to_insert in 0..len { - tester.tail = tail_pos; - tester.head = tail_pos; - for i in 0..len { - if i != to_insert { - tester.push_back(i); - } - } - tester.insert(to_insert, to_insert); - assert!(tester.tail < tester.cap); - assert!(tester.head < tester.cap); - assert_eq!(tester, expected); - } - } - } -} -*/ - -// FIXME(japaric) privacy -/* -#[test] -fn test_remove() { - // This test checks that every single combination of tail position, length, and - // removal position is tested. Capacity 15 should be large enough to cover every case. - - let mut tester = VecDeque::with_capacity(15); - // can't guarantee we got 15, so have to get what we got. - // 15 would be great, but we will definitely get 2^k - 1, for k >= 4, or else - // this test isn't covering what it wants to - let cap = tester.capacity(); - - // len is the length *after* removal - for len in 0..cap - 1 { - // 0, 1, 2, .., len - 1 - let expected = iter::count(0, 1).take(len).collect(); - for tail_pos in 0..cap { - for to_remove in 0..len + 1 { - tester.tail = tail_pos; - tester.head = tail_pos; - for i in 0..len { - if i == to_remove { - tester.push_back(1234); - } - tester.push_back(i); - } - if to_remove == len { - tester.push_back(1234); - } - tester.remove(to_remove); - assert!(tester.tail < tester.cap); - assert!(tester.head < tester.cap); - assert_eq!(tester, expected); - } - } - } -} -*/ - -// FIXME(japaric) privacy -/* -#[test] -fn test_shrink_to_fit() { - // This test checks that every single combination of head and tail position, - // is tested. Capacity 15 should be large enough to cover every case. - - let mut tester = VecDeque::with_capacity(15); - // can't guarantee we got 15, so have to get what we got. - // 15 would be great, but we will definitely get 2^k - 1, for k >= 4, or else - // this test isn't covering what it wants to - let cap = tester.capacity(); - tester.reserve(63); - let max_cap = tester.capacity(); - - for len in 0..cap + 1 { - // 0, 1, 2, .., len - 1 - let expected = iter::count(0, 1).take(len).collect(); - for tail_pos in 0..max_cap + 1 { - tester.tail = tail_pos; - tester.head = tail_pos; - tester.reserve(63); - for i in 0..len { - tester.push_back(i); - } - tester.shrink_to_fit(); - assert!(tester.capacity() <= cap); - assert!(tester.tail < tester.cap); - assert!(tester.head < tester.cap); - assert_eq!(tester, expected); - } - } -} -*/ - #[test] fn test_front() { let mut ring = VecDeque::new(); @@ -1087,47 +866,6 @@ fn test_as_mut_slices() { assert_eq!(ring.capacity() as i32, cap); } -// FIXME(japaric) privacy -/* -#[test] -fn test_split_off() { - // This test checks that every single combination of tail position, length, and - // split position is tested. Capacity 15 should be large enough to cover every case. - - let mut tester = VecDeque::with_capacity(15); - // can't guarantee we got 15, so have to get what we got. - // 15 would be great, but we will definitely get 2^k - 1, for k >= 4, or else - // this test isn't covering what it wants to - let cap = tester.capacity(); - - // len is the length *before* splitting - for len in 0..cap { - // index to split at - for at in 0..len + 1 { - // 0, 1, 2, .., at - 1 (may be empty) - let expected_self = iter::count(0, 1).take(at).collect(); - // at, at + 1, .., len - 1 (may be empty) - let expected_other = iter::count(at, 1).take(len - at).collect(); - - for tail_pos in 0..cap { - tester.tail = tail_pos; - tester.head = tail_pos; - for i in 0..len { - tester.push_back(i); - } - let result = tester.split_off(at); - assert!(tester.tail < tester.cap); - assert!(tester.head < tester.cap); - assert!(result.tail < result.cap); - assert!(result.head < result.cap); - assert_eq!(tester, expected_self); - assert_eq!(result, expected_other); - } - } - } -} -*/ - #[test] fn test_append() { let mut a: VecDeque<_> = vec![1, 2, 3].into_iter().collect();