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,\
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;
#[doc(hidden)]
pub fn fixme_14344_be_sure_to_link_to_collections() {}
+#[cfg(not(test))]
mod std {
pub use core::ops; // RangeFull
}
}
}
}
+
+#[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<T: Clone>(v: &[T]) -> LinkedList<T> {
+ v.iter().cloned().collect()
+ }
+
+ pub fn check_links<T>(list: &LinkedList<T>) {
+ let mut len = 0;
+ let mut last_ptr: Option<&Node<T>> = None;
+ let mut node_ptr: &Node<T>;
+ 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<T>, pptr as *const Node<T>);
+ }
+ _ => 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::<i32>::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::<Vec<_>>(), [-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::<Vec<_>>());
+ }).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());
+ }
+}
/// 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 {
($($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.
///
}
}
+// 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<T>(mut b: Box<[T]>) -> Vec<T> {
+ unsafe {
+ let xs = Vec::from_raw_parts(b.as_mut_ptr(), b.len(), b.len());
+ mem::forget(b);
+ xs
+ }
+}
+
+#[cfg(test)]
+pub fn permutations<T>(s: &[T]) -> Permutations<T> where T: Clone {
+ Permutations{
+ swaps: ElementSwaps::new(s.len()),
+ v: ::slice::to_vec(s),
+ }
+}
+
+#[cfg(test)]
+pub fn to_vec<T>(s: &[T]) -> Vec<T> 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> [T] {
/// Sorts the slice, in place, using `compare` to compare
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone> ToOwned for [T] {
type Owned = Vec<T>;
+ #[cfg(not(test))]
fn to_owned(&self) -> Vec<T> { 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<T> { ::slice::to_vec(self) }
}
////////////////////////////////////////////////////////////////////////////////
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());
+ }
+ }
+}
#[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`.
#[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.
///
fn clone(&self) -> Vec<T> { ::slice::SliceExt::to_vec(&**self) }
#[cfg(not(stage0))]
+ #[cfg(not(test))]
fn clone(&self) -> Vec<T> { <[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<T> { ::slice::to_vec(&**self) }
+
fn clone_from(&mut self, other: &Vec<T>) {
// drop anything in self that will not be overwritten
if self.len() > other.len() {
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::<i32>::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::<i32>::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);
+ }
+ }
+ }
+ }
+}
use test;
-// FIXME(japaric) privacy
-/*
-pub fn check_links<T>(list: &LinkedList<T>) {
- let mut len = 0;
- let mut last_ptr: Option<&Node<T>> = None;
- let mut node_ptr: &Node<T>;
- 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<T>, pptr as *const Node<T>);
- }
- _ => 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::<Box<_>>::new();
v.iter().cloned().collect()
}
-// FIXME(japaric) privacy
-/*
-#[test]
-fn test_append() {
- // Empty to empty
- {
- let mut m = LinkedList::<i32>::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
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::<Vec<_>>(), [-2,0,1,2,3,4,5,6,7,8,9,0,1]);
-}
-*/
-
#[test]
fn test_mut_rev_iter() {
let mut m = generate_test();
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::<Vec<_>>());
- }).join().ok().unwrap();
-}
-*/
-
#[test]
fn test_eq() {
let mut n = list_from(&[]);
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();
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];
}
}
-// 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];
})
}
-// 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::<i32>::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::<i32>::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(|| {
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();
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();