Skip to content

Commit ffe2623

Browse files
author
blake2-ppc
committed
iterator: Add test for .cycle()
1 parent 4623e81 commit ffe2623

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libstd/iterator.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,20 @@ mod tests {
14941494
assert_eq!(i, 10);
14951495
}
14961496

1497+
#[test]
1498+
fn test_cycle() {
1499+
let cycle_len = 3;
1500+
let it = Counter::new(0u,1).take_(cycle_len).cycle();
1501+
assert_eq!(it.size_hint(), (uint::max_value, None));
1502+
for it.take_(100).enumerate().advance |(i, x)| {
1503+
assert_eq!(i % cycle_len, x);
1504+
}
1505+
1506+
let mut it = Counter::new(0u,1).take_(0).cycle();
1507+
assert_eq!(it.size_hint(), (0, Some(0)));
1508+
assert_eq!(it.next(), None);
1509+
}
1510+
14971511
#[test]
14981512
fn test_iterator_nth() {
14991513
let v = &[0, 1, 2, 3, 4];

0 commit comments

Comments
 (0)