Skip to content

Commit

Permalink
libcollections: Use iterators instead of old-style loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
luqmana committed Jul 9, 2014
1 parent 1eb4ce0 commit a9d112b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 38 deletions.
44 changes: 10 additions & 34 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,18 +1426,14 @@ mod tests {
fn test_small_clear() {
let mut b = Bitv::with_capacity(14, true);
b.clear();
BitvSet::from_bitv(b).iter().advance(|i| {
fail!("found 1 at {:?}", i)
});
assert!(b.none());
}

#[test]
fn test_big_clear() {
let mut b = Bitv::with_capacity(140, true);
b.clear();
BitvSet::from_bitv(b).iter().advance(|i| {
fail!("found 1 at {:?}", i)
});
assert!(b.none());
}

#[test]
Expand Down Expand Up @@ -1494,14 +1490,9 @@ mod tests {
assert!(b.insert(5));
assert!(b.insert(3));

let mut i = 0;
let expected = [3, 5, 11, 77];
a.intersection(&b).advance(|x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
let actual = a.intersection(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
}

#[test]
Expand All @@ -1518,14 +1509,9 @@ mod tests {
assert!(b.insert(3));
assert!(b.insert(200));

let mut i = 0;
let expected = [1, 5, 500];
a.difference(&b).advance(|x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
let actual = a.difference(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
}

#[test]
Expand All @@ -1544,14 +1530,9 @@ mod tests {
assert!(b.insert(14));
assert!(b.insert(220));

let mut i = 0;
let expected = [1, 5, 11, 14, 220];
a.symmetric_difference(&b).advance(|x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
let actual = a.symmetric_difference(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
}

#[test]
Expand All @@ -1573,14 +1554,9 @@ mod tests {
assert!(b.insert(13));
assert!(b.insert(19));

let mut i = 0;
let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160];
a.union(&b).advance(|x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
let actual = a.union(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ mod test_set {
#[test]
fn test_intersection() {
fn check_intersection(a: &[int], b: &[int], expected: &[int]) {
check(a, b, expected, |x, y, f| x.intersection(y).advance(f))
check(a, b, expected, |x, y, f| x.intersection(y).all(f))
}

check_intersection([], [], []);
Expand All @@ -1786,7 +1786,7 @@ mod test_set {
#[test]
fn test_difference() {
fn check_difference(a: &[int], b: &[int], expected: &[int]) {
check(a, b, expected, |x, y, f| x.difference(y).advance(f))
check(a, b, expected, |x, y, f| x.difference(y).all(f))
}

check_difference([], [], []);
Expand All @@ -1804,7 +1804,7 @@ mod test_set {
fn test_symmetric_difference() {
fn check_symmetric_difference(a: &[int], b: &[int],
expected: &[int]) {
check(a, b, expected, |x, y, f| x.symmetric_difference(y).advance(f))
check(a, b, expected, |x, y, f| x.symmetric_difference(y).all(f))
}

check_symmetric_difference([], [], []);
Expand All @@ -1819,7 +1819,7 @@ mod test_set {
fn test_union() {
fn check_union(a: &[int], b: &[int],
expected: &[int]) {
check(a, b, expected, |x, y, f| x.union(y).advance(f))
check(a, b, expected, |x, y, f| x.union(y).all(f))
}

check_union([], [], []);
Expand Down

0 comments on commit a9d112b

Please sign in to comment.