Skip to content

Commit

Permalink
run rustfmt on libcollectionstest
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivasreddy committed Oct 25, 2016
1 parent 6dc035e commit e820a86
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 62 deletions.
4 changes: 3 additions & 1 deletion src/libcollectionstest/binary_heap.rs
Expand Up @@ -299,5 +299,7 @@ fn test_extend_specialization() {

#[allow(dead_code)]
fn assert_covariance() {
fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> { d }
fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> {
d
}
}
4 changes: 1 addition & 3 deletions src/libcollectionstest/btree/map.rs
Expand Up @@ -533,9 +533,7 @@ create_append_test!(test_append_1700, 1700);

fn rand_data(len: usize) -> Vec<(u32, u32)> {
let mut rng = DeterministicRng::new();
Vec::from_iter(
(0..len).map(|_| (rng.next(), rng.next()))
)
Vec::from_iter((0..len).map(|_| (rng.next(), rng.next())))
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/libcollectionstest/btree/mod.rs
Expand Up @@ -25,7 +25,7 @@ impl DeterministicRng {
x: 0x193a6754,
y: 0xa8a7d469,
z: 0x97830e05,
w: 0x113ba7bb
w: 0x113ba7bb,
}
}

Expand Down
74 changes: 42 additions & 32 deletions src/libcollectionstest/btree/set.rs
Expand Up @@ -15,45 +15,51 @@ use super::DeterministicRng;

#[test]
fn test_clone_eq() {
let mut m = BTreeSet::new();
let mut m = BTreeSet::new();

m.insert(1);
m.insert(2);
m.insert(1);
m.insert(2);

assert!(m.clone() == m);
assert!(m.clone() == m);
}

#[test]
fn test_hash() {
let mut x = BTreeSet::new();
let mut y = BTreeSet::new();
let mut x = BTreeSet::new();
let mut y = BTreeSet::new();

x.insert(1);
x.insert(2);
x.insert(3);
x.insert(1);
x.insert(2);
x.insert(3);

y.insert(3);
y.insert(2);
y.insert(1);
y.insert(3);
y.insert(2);
y.insert(1);

assert!(::hash(&x) == ::hash(&y));
assert!(::hash(&x) == ::hash(&y));
}

fn check<F>(a: &[i32], b: &[i32], expected: &[i32], f: F) where
F: FnOnce(&BTreeSet<i32>, &BTreeSet<i32>, &mut FnMut(&i32) -> bool) -> bool,
fn check<F>(a: &[i32], b: &[i32], expected: &[i32], f: F)
where F: FnOnce(&BTreeSet<i32>, &BTreeSet<i32>, &mut FnMut(&i32) -> bool) -> bool
{
let mut set_a = BTreeSet::new();
let mut set_b = BTreeSet::new();

for x in a { assert!(set_a.insert(*x)) }
for y in b { assert!(set_b.insert(*y)) }
for x in a {
assert!(set_a.insert(*x))
}
for y in b {
assert!(set_b.insert(*y))
}

let mut i = 0;
f(&set_a, &set_b, &mut |&x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
f(&set_a,
&set_b,
&mut |&x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
}

Expand Down Expand Up @@ -82,9 +88,7 @@ fn test_difference() {
check_difference(&[], &[], &[]);
check_difference(&[1, 12], &[], &[1, 12]);
check_difference(&[], &[1, 2, 3, 9], &[]);
check_difference(&[1, 3, 5, 9, 11],
&[3, 9],
&[1, 5, 11]);
check_difference(&[1, 3, 5, 9, 11], &[3, 9], &[1, 5, 11]);
check_difference(&[-5, 11, 22, 33, 40, 42],
&[-12, -5, 14, 23, 34, 38, 39, 50],
&[11, 22, 33, 40, 42]);
Expand Down Expand Up @@ -245,10 +249,18 @@ fn test_recovery() {
fn test_variance() {
use std::collections::btree_set::{IntoIter, Iter, Range};

fn set<'new>(v: BTreeSet<&'static str>) -> BTreeSet<&'new str> { v }
fn iter<'a, 'new>(v: Iter<'a, &'static str>) -> Iter<'a, &'new str> { v }
fn into_iter<'new>(v: IntoIter<&'static str>) -> IntoIter<&'new str> { v }
fn range<'a, 'new>(v: Range<'a, &'static str>) -> Range<'a, &'new str> { v }
fn set<'new>(v: BTreeSet<&'static str>) -> BTreeSet<&'new str> {
v
}
fn iter<'a, 'new>(v: Iter<'a, &'static str>) -> Iter<'a, &'new str> {
v
}
fn into_iter<'new>(v: IntoIter<&'static str>) -> IntoIter<&'new str> {
v
}
fn range<'a, 'new>(v: Range<'a, &'static str>) -> Range<'a, &'new str> {
v
}
}

#[test]
Expand Down Expand Up @@ -277,9 +289,7 @@ fn test_append() {

fn rand_data(len: usize) -> Vec<u32> {
let mut rng = DeterministicRng::new();
Vec::from_iter(
(0..len).map(|_| rng.next())
)
Vec::from_iter((0..len).map(|_| rng.next()))
}

#[test]
Expand Down
4 changes: 3 additions & 1 deletion src/libcollectionstest/lib.rs
Expand Up @@ -36,7 +36,9 @@ extern crate rustc_unicode;
use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher;

#[cfg(test)] #[macro_use] mod bench;
#[cfg(test)]
#[macro_use]
mod bench;

mod binary_heap;
mod btree;
Expand Down
36 changes: 18 additions & 18 deletions src/libcollectionstest/slice.rs
Expand Up @@ -420,12 +420,12 @@ fn test_sort_stability() {
// number this element is, i.e. the second elements
// will occur in sorted order.
let mut v: Vec<_> = (0..len)
.map(|_| {
let n = thread_rng().gen::<usize>() % 10;
counts[n] += 1;
(n, counts[n])
})
.collect();
.map(|_| {
let n = thread_rng().gen::<usize>() % 10;
counts[n] += 1;
(n, counts[n])
})
.collect();

// only sort on the first element, so an unstable sort
// may mix up the counts.
Expand Down Expand Up @@ -1116,13 +1116,13 @@ fn test_box_slice_clone_panics() {
};

spawn(move || {
// When xs is dropped, +5.
let xs = vec![canary.clone(), canary.clone(), canary.clone(), panic, canary]
.into_boxed_slice();
// When xs is dropped, +5.
let xs = vec![canary.clone(), canary.clone(), canary.clone(), panic, canary]
.into_boxed_slice();

// When panic is cloned, +3.
xs.clone();
})
// When panic is cloned, +3.
xs.clone();
})
.join()
.unwrap_err();

Expand Down Expand Up @@ -1374,8 +1374,8 @@ mod bench {
let mut rng = thread_rng();
b.iter(|| {
let mut v = rng.gen_iter::<BigSortable>()
.take(5)
.collect::<Vec<BigSortable>>();
.take(5)
.collect::<Vec<BigSortable>>();
v.sort();
});
b.bytes = 5 * mem::size_of::<BigSortable>() as u64;
Expand All @@ -1386,8 +1386,8 @@ mod bench {
let mut rng = thread_rng();
b.iter(|| {
let mut v = rng.gen_iter::<BigSortable>()
.take(100)
.collect::<Vec<BigSortable>>();
.take(100)
.collect::<Vec<BigSortable>>();
v.sort();
});
b.bytes = 100 * mem::size_of::<BigSortable>() as u64;
Expand All @@ -1398,8 +1398,8 @@ mod bench {
let mut rng = thread_rng();
b.iter(|| {
let mut v = rng.gen_iter::<BigSortable>()
.take(10000)
.collect::<Vec<BigSortable>>();
.take(10000)
.collect::<Vec<BigSortable>>();
v.sort();
});
b.bytes = 10000 * mem::size_of::<BigSortable>() as u64;
Expand Down
8 changes: 6 additions & 2 deletions src/libcollectionstest/vec.rs
Expand Up @@ -599,8 +599,12 @@ fn test_cow_from() {

#[allow(dead_code)]
fn assert_covariance() {
fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> { d }
fn into_iter<'new>(i: IntoIter<&'static str>) -> IntoIter<&'new str> { i }
fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> {
d
}
fn into_iter<'new>(i: IntoIter<&'static str>) -> IntoIter<&'new str> {
i
}
}

#[bench]
Expand Down
10 changes: 6 additions & 4 deletions src/libcollectionstest/vec_deque.rs
Expand Up @@ -686,9 +686,9 @@ fn test_show() {
assert_eq!(format!("{:?}", ringbuf), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");

let ringbuf: VecDeque<_> = vec!["just", "one", "test", "more"]
.iter()
.cloned()
.collect();
.iter()
.cloned()
.collect();
assert_eq!(format!("{:?}", ringbuf),
"[\"just\", \"one\", \"test\", \"more\"]");
}
Expand Down Expand Up @@ -1003,5 +1003,7 @@ fn test_contains() {

#[allow(dead_code)]
fn assert_covariance() {
fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> { d }
fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> {
d
}
}

0 comments on commit e820a86

Please sign in to comment.