libcollections: fix unit tests

This commit is contained in:
Jorge Aparicio 2014-12-03 21:05:25 -05:00
parent 10a14d5f04
commit b3cd05642c
3 changed files with 54 additions and 27 deletions

View File

@ -603,10 +603,23 @@ mod test {
assert!(hash::hash(&x) == hash::hash(&y));
}
fn check(a: &[int],
b: &[int],
expected: &[int],
f: |&BTreeSet<int>, &BTreeSet<int>, f: |&int| -> bool| -> bool) {
struct Counter<'a, 'b> {
i: &'a mut uint,
expected: &'b [int],
}
impl<'a, 'b> FnMut(&int) -> bool for Counter<'a, 'b> {
extern "rust-call" fn call_mut(&mut self, (&x,): (&int,)) -> bool {
assert_eq!(x, self.expected[*self.i]);
*self.i += 1;
true
}
}
fn check<F>(a: &[int], b: &[int], expected: &[int], f: F) where
// FIXME Replace Counter with `Box<FnMut(_) -> _>`
F: FnOnce(&BTreeSet<int>, &BTreeSet<int>, Counter) -> bool,
{
let mut set_a = BTreeSet::new();
let mut set_b = BTreeSet::new();
@ -614,11 +627,7 @@ mod test {
for y in b.iter() { assert!(set_b.insert(*y)) }
let mut i = 0;
f(&set_a, &set_b, |x| {
assert_eq!(*x, expected[i]);
i += 1;
true
});
f(&set_a, &set_b, Counter { i: &mut i, expected: expected });
assert_eq!(i, expected.len());
}

View File

@ -936,10 +936,23 @@ mod test {
assert!(hash::hash(&x) == hash::hash(&y));
}
fn check(a: &[int],
b: &[int],
expected: &[int],
f: |&TreeSet<int>, &TreeSet<int>, f: |&int| -> bool| -> bool) {
struct Counter<'a, 'b> {
i: &'a mut uint,
expected: &'b [int],
}
impl<'a, 'b> FnMut(&int) -> bool for Counter<'a, 'b> {
extern "rust-call" fn call_mut(&mut self, (&x,): (&int,)) -> bool {
assert_eq!(x, self.expected[*self.i]);
*self.i += 1;
true
}
}
fn check<F>(a: &[int], b: &[int], expected: &[int], f: F) where
// FIXME Replace `Counter` with `Box<FnMut(&int) -> bool>`
F: FnOnce(&TreeSet<int>, &TreeSet<int>, Counter) -> bool,
{
let mut set_a = TreeSet::new();
let mut set_b = TreeSet::new();
@ -947,11 +960,7 @@ mod test {
for y in b.iter() { assert!(set_b.insert(*y)) }
let mut i = 0;
f(&set_a, &set_b, |x| {
assert_eq!(*x, expected[i]);
i += 1;
true
});
f(&set_a, &set_b, Counter { i: &mut i, expected: expected });
assert_eq!(i, expected.len());
}

View File

@ -743,10 +743,23 @@ mod test {
assert!(a < b && a <= b);
}
fn check(a: &[uint],
b: &[uint],
expected: &[uint],
f: |&TrieSet, &TrieSet, f: |uint| -> bool| -> bool) {
struct Counter<'a, 'b> {
i: &'a mut uint,
expected: &'b [uint],
}
impl<'a, 'b> FnMut(uint) -> bool for Counter<'a, 'b> {
extern "rust-call" fn call_mut(&mut self, (x,): (uint,)) -> bool {
assert_eq!(x, self.expected[*self.i]);
*self.i += 1;
true
}
}
fn check<F>(a: &[uint], b: &[uint], expected: &[uint], f: F) where
// FIXME Replace `Counter` with `Box<FnMut(&uint) -> bool>`
F: FnOnce(&TrieSet, &TrieSet, Counter) -> bool,
{
let mut set_a = TrieSet::new();
let mut set_b = TrieSet::new();
@ -754,11 +767,7 @@ mod test {
for y in b.iter() { assert!(set_b.insert(*y)) }
let mut i = 0;
f(&set_a, &set_b, |x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
f(&set_a, &set_b, Counter { i: &mut i, expected: expected });
assert_eq!(i, expected.len());
}