Skip to content

Commit a9d112b

Browse files
committed
libcollections: Use iterators instead of old-style loops.
1 parent 1eb4ce0 commit a9d112b

File tree

2 files changed

+14
-38
lines changed

2 files changed

+14
-38
lines changed

src/libcollections/bitv.rs

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,18 +1426,14 @@ mod tests {
14261426
fn test_small_clear() {
14271427
let mut b = Bitv::with_capacity(14, true);
14281428
b.clear();
1429-
BitvSet::from_bitv(b).iter().advance(|i| {
1430-
fail!("found 1 at {:?}", i)
1431-
});
1429+
assert!(b.none());
14321430
}
14331431

14341432
#[test]
14351433
fn test_big_clear() {
14361434
let mut b = Bitv::with_capacity(140, true);
14371435
b.clear();
1438-
BitvSet::from_bitv(b).iter().advance(|i| {
1439-
fail!("found 1 at {:?}", i)
1440-
});
1436+
assert!(b.none());
14411437
}
14421438

14431439
#[test]
@@ -1494,14 +1490,9 @@ mod tests {
14941490
assert!(b.insert(5));
14951491
assert!(b.insert(3));
14961492

1497-
let mut i = 0;
14981493
let expected = [3, 5, 11, 77];
1499-
a.intersection(&b).advance(|x| {
1500-
assert_eq!(x, expected[i]);
1501-
i += 1;
1502-
true
1503-
});
1504-
assert_eq!(i, expected.len());
1494+
let actual = a.intersection(&b).collect::<Vec<uint>>();
1495+
assert_eq!(actual.as_slice(), expected.as_slice());
15051496
}
15061497

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

1521-
let mut i = 0;
15221512
let expected = [1, 5, 500];
1523-
a.difference(&b).advance(|x| {
1524-
assert_eq!(x, expected[i]);
1525-
i += 1;
1526-
true
1527-
});
1528-
assert_eq!(i, expected.len());
1513+
let actual = a.difference(&b).collect::<Vec<uint>>();
1514+
assert_eq!(actual.as_slice(), expected.as_slice());
15291515
}
15301516

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

1547-
let mut i = 0;
15481533
let expected = [1, 5, 11, 14, 220];
1549-
a.symmetric_difference(&b).advance(|x| {
1550-
assert_eq!(x, expected[i]);
1551-
i += 1;
1552-
true
1553-
});
1554-
assert_eq!(i, expected.len());
1534+
let actual = a.symmetric_difference(&b).collect::<Vec<uint>>();
1535+
assert_eq!(actual.as_slice(), expected.as_slice());
15551536
}
15561537

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

1576-
let mut i = 0;
15771557
let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160];
1578-
a.union(&b).advance(|x| {
1579-
assert_eq!(x, expected[i]);
1580-
i += 1;
1581-
true
1582-
});
1583-
assert_eq!(i, expected.len());
1558+
let actual = a.union(&b).collect::<Vec<uint>>();
1559+
assert_eq!(actual.as_slice(), expected.as_slice());
15841560
}
15851561

15861562
#[test]

src/libcollections/treemap.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ mod test_set {
17701770
#[test]
17711771
fn test_intersection() {
17721772
fn check_intersection(a: &[int], b: &[int], expected: &[int]) {
1773-
check(a, b, expected, |x, y, f| x.intersection(y).advance(f))
1773+
check(a, b, expected, |x, y, f| x.intersection(y).all(f))
17741774
}
17751775

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

17921792
check_difference([], [], []);
@@ -1804,7 +1804,7 @@ mod test_set {
18041804
fn test_symmetric_difference() {
18051805
fn check_symmetric_difference(a: &[int], b: &[int],
18061806
expected: &[int]) {
1807-
check(a, b, expected, |x, y, f| x.symmetric_difference(y).advance(f))
1807+
check(a, b, expected, |x, y, f| x.symmetric_difference(y).all(f))
18081808
}
18091809

18101810
check_symmetric_difference([], [], []);
@@ -1819,7 +1819,7 @@ mod test_set {
18191819
fn test_union() {
18201820
fn check_union(a: &[int], b: &[int],
18211821
expected: &[int]) {
1822-
check(a, b, expected, |x, y, f| x.union(y).advance(f))
1822+
check(a, b, expected, |x, y, f| x.union(y).all(f))
18231823
}
18241824

18251825
check_union([], [], []);

0 commit comments

Comments
 (0)