]> git.lizzy.rs Git - rust.git/commitdiff
libcollections: Use iterators instead of old-style loops.
authorLuqman Aden <laden@csclub.uwaterloo.ca>
Thu, 12 Jun 2014 09:19:55 +0000 (05:19 -0400)
committerLuqman Aden <me@luqman.ca>
Wed, 9 Jul 2014 22:50:20 +0000 (15:50 -0700)
src/libcollections/bitv.rs
src/libcollections/treemap.rs

index 905c27ee82c9470cc1c2af5e70af59115727993f..23be65cc4e21e8077fdc899e2b762cd6119b142b 100644 (file)
@@ -1426,18 +1426,14 @@ fn test_big_difference() {
     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]
@@ -1494,14 +1490,9 @@ fn test_bitv_set_intersection() {
         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]
@@ -1518,14 +1509,9 @@ fn test_bitv_set_difference() {
         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]
@@ -1544,14 +1530,9 @@ fn test_bitv_set_symmetric_difference() {
         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]
@@ -1573,14 +1554,9 @@ fn test_bitv_set_union() {
         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]
index e0242af3c9973c327dd6e1b4fcc3db3ea39ec2f1..1451bf9d7c7bcedd84b306f518d5494af50286e0 100644 (file)
@@ -1770,7 +1770,7 @@ fn check(a: &[int],
     #[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([], [], []);
@@ -1786,7 +1786,7 @@ fn check_intersection(a: &[int], b: &[int], expected: &[int]) {
     #[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([], [], []);
@@ -1804,7 +1804,7 @@ fn check_difference(a: &[int], b: &[int], expected: &[int]) {
     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([], [], []);
@@ -1819,7 +1819,7 @@ fn check_symmetric_difference(a: &[int], b: &[int],
     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([], [], []);