### ----------------------------------------------------
### -- Iter::Able
### -- Licenses: Artistic-2.0
### -- Authors: 
### -- File: t/07-cycle.rakutest
### ----------------------------------------------------
use Test;
use Iter::Able::Cycle;

my &id = -> \g, \e, Str $desc? { g | e ~~ Seq:D ?? cmp-ok(g, "eqv", e, $desc) !! is-deeply(g, e, $desc) };

plan 10;

my $s;
$s := [2, 3];
id cycle($s).head(5), [2, 3, 2, 3, 2].Seq, "Random list with 2.5 repeats";

$s := [];
id cycle($s), [].Seq,  "Empty-list";

$s := [3, 4, 5].Seq;
id cycle($s).head(2), [3, 4].Seq, "Seq with 0.66 repeats";

$s := [5];
id cycle($s).head(7), (|$s xx 7).Seq, "One element list with 7 repeats";

$s := "yes";
id cycle($s).head(10), "yesyesyesy".comb, "String ~3.33 repeats";

$s := (-2, -1, 0, 1, 2, 3);
my \it = $s.iterator;
it.pull-one for ^2;
my \newit = cycle(it);
it.pull-one;  # should affect `newit`s behaviour
does-ok newit, Iterator, "Iterator (returned an Iterator, not a Seq)";
id Seq.new(newit).head(4), [1, 2, 3, 1].Seq, "Iterator (values)";
ok it.pull-one =:= IterationEnd, "Iterator (original, exhausted)";
nok newit.pull-one =:= IterationEnd, "Iterator (new, *not* exhausted)";
is newit.pull-one, 3, "(... and yields the right value)";

done-testing;


