Skip to content
Browse files

[t/spec] Add tests for RangeIter on infinite Ranges.

git-svn-id: http://svn.pugscode.org/pugs@30052 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 27c1486 commit ca5e8b02f562495add98de6b299b0921b2ed9dcf colomon committed
Showing with 98 additions and 14 deletions.
  1. +98 −14 S07-iterators/range-iterator.t
View
112 S07-iterators/range-iterator.t
@@ -1,7 +1,7 @@
use v6;
use Test;
-plan 23;
+plan *;
{
my $r = RangeIter.new(1..5);
@@ -27,19 +27,17 @@ plan 23;
is $r.get, EMPTY, '$r.get is still done';
}
-# Heh. skip doesn't work for ng1 yet?
-# #?rakudo skip 'cmp doesn't work for Rat yet'
-# {
-# my $r = RangeIter.new(-1.5..^3);
-# isa_ok $r, RangeIter, '$r is a RangeIter';
-# is $r.get, -1.5, '$r.get == -1.5';
-# is $r.get, -.5, '$r.get == -0.5';
-# is $r.get, .5, '$r.get == .5';
-# is $r.get, 1.5, '$r.get == 1.5';
-# is $r.get, 2.5, '$r.get == 2.5';
-# is $r.get, EMPTY, '$r.get is done';
-# is $r.get, EMPTY, '$r.get is still done';
-# }
+{
+ my $r = RangeIter.new(-1.5..^3);
+ isa_ok $r, RangeIter, '$r is a RangeIter';
+ is $r.get, -1.5, '$r.get == -1.5';
+ is $r.get, -.5, '$r.get == -0.5';
+ is $r.get, .5, '$r.get == .5';
+ is $r.get, 1.5, '$r.get == 1.5';
+ is $r.get, 2.5, '$r.get == 2.5';
+ is $r.get, EMPTY, '$r.get is done';
+ is $r.get, EMPTY, '$r.get is still done';
+}
{
my $r = RangeIter.new(-1.5.Num^..3);
@@ -52,4 +50,90 @@ plan 23;
is $r.get, EMPTY, '$r.get is still done';
}
+{
+ my $r = RangeIter.new(-1..*);
+ isa_ok $r, RangeIter, '$r is a RangeIter';
+ is $r.get, -1, '$r.get == -1';
+ is $r.get, 0, '$r.get == 0';
+ is $r.get, 1, '$r.get == 1';
+ is $r.get, 2, '$r.get == 2';
+ is $r.get, 3, '$r.get == 3';
+ is $r.get, 4, '$r.get == 4';
+ is $r.get, 5, '$r.get == 5';
+ loop (my $i = 0; $i < 100; $i++) {
+ $r.get; # 6 through 105
+ }
+ is $r.get, 106, '$r.get == 106';
+}
+
+{
+ my $r = RangeIter.new(-1.5.Num..*);
+ isa_ok $r, RangeIter, '$r is a RangeIter';
+ is $r.get, -1.5, '$r.get == -1.5';
+ is $r.get, -.5, '$r.get == -0.5';
+ is $r.get, .5, '$r.get == .5';
+ is $r.get, 1.5, '$r.get == 1.5';
+ is $r.get, 2.5, '$r.get == 2.5';
+ is $r.get, 3.5, '$r.get == 3.5';
+ is $r.get, 4.5, '$r.get == 4.5';
+}
+
+{
+ my $r = RangeIter.new(-1.5..*);
+ isa_ok $r, RangeIter, '$r is a RangeIter';
+ is $r.get, -1.5, '$r.get == -1.5';
+ is $r.get, -.5, '$r.get == -0.5';
+ is $r.get, .5, '$r.get == .5';
+ is $r.get, 1.5, '$r.get == 1.5';
+ is $r.get, 2.5, '$r.get == 2.5';
+ is $r.get, 3.5, '$r.get == 3.5';
+ is $r.get, 4.5, '$r.get == 4.5';
+}
+
+{
+ # Make sure we can read two different RangeIters at the same time.
+ # (May sound like an odd test, but as I type this, if Range iteration
+ # were implemented with gather/take, this test would fail.)
+ my $r1 = RangeIter.new(-1..*);
+ my $r2 = RangeIter.new(42..*);
+ isa_ok $r1, RangeIter, '$r1 is a RangeIter';
+ isa_ok $r2, RangeIter, '$r2 is a RangeIter';
+ is $r1.get, -1, '$r1.get == -1';
+ is $r2.get, 42, '$r2.get == 42';
+ is $r1.get, 0, '$r1.get == 0';
+ is $r2.get, 43, '$r2.get == 43';
+ is $r1.get, 1, '$r1.get == 1';
+ is $r2.get, 44, '$r2.get == 44';
+ is $r1.get, 2, '$r1.get == 2';
+ is $r2.get, 45, '$r2.get == 45';
+ is $r1.get, 3, '$r1.get == 3';
+ is $r2.get, 46, '$r2.get == 46';
+ is $r1.get, 4, '$r1.get == 4';
+ is $r2.get, 47, '$r2.get == 47';
+ is $r1.get, 5, '$r1.get == 5';
+ is $r2.get, 48, '$r2.get == 48';
+}
+
+{
+ my $r = RangeIter.new('d'..'g');
+ isa_ok $r, RangeIter, '$r is a RangeIter';
+ is $r.get, 'd', '$r.get == d';
+ is $r.get, 'e', '$r.get == e';
+ is $r.get, 'f', '$r.get == f';
+ is $r.get, 'g', '$r.get == g';
+ is $r.get, EMPTY, '$r.get is done';
+ is $r.get, EMPTY, '$r.get is still done';
+}
+
+{
+ my $r = RangeIter.new('d'..*);
+ isa_ok $r, RangeIter, '$r is a RangeIter';
+ is $r.get, 'd', '$r.get == d';
+ is $r.get, 'e', '$r.get == e';
+ is $r.get, 'f', '$r.get == f';
+ is $r.get, 'g', '$r.get == g';
+ is $r.get, 'h', '$r.get == h';
+ is $r.get, 'i', '$r.get == i';
+}
+
done_testing;

0 comments on commit ca5e8b0

Please sign in to comment.
Something went wrong with that request. Please try again.