Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some more and more precise Supply tests
  • Loading branch information
lizmat committed Apr 19, 2014
1 parent 2964de5 commit 9bf4cfb
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions S17-concurrency/supply.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 108;
plan 126;

sub tap_ok ( $s, $expected, $text ) {
ok $s ~~ Supply, "{$s.^name} appears to be doing Supply";
Expand All @@ -12,7 +12,7 @@ sub tap_ok ( $s, $expected, $text ) {

for ^50 { sleep .1; last if $done }
ok $done, "$text was really done";
is ~@res, $expected, $text;
is_deeply @res, $expected, $text;
}

for (ThreadPoolScheduler, CurrentThreadScheduler) {
Expand Down Expand Up @@ -61,8 +61,18 @@ for (ThreadPoolScheduler, CurrentThreadScheduler) {

{
my $s = Supply.for(1..10);
tap_ok $s, "1 2 3 4 5 6 7 8 9 10", "On demand publish worked";
tap_ok $s, "1 2 3 4 5 6 7 8 9 10", "Second tap gets all the values";
tap_ok $s, [1..10], "On demand publish worked";
tap_ok $s, [1..10], "Second tap gets all the values";
}

{
my $s = Supply.for( (1..5).map( {[$_]} ) );
tap_ok $s, [[1],[2],[3],[4],[5]], "On demand publish with arrays";
}

{
my $s = Supply.for( [1,2],[3,4,5] ).map( {.flat} );
tap_ok $s, [1..5], "On demand publish with flattened arrays";
}

#?rakudo.jvm skip "hangs"
Expand All @@ -76,51 +86,55 @@ for (ThreadPoolScheduler, CurrentThreadScheduler) {
}

tap_ok Supply.for(1..10).map( * * 5 ),
'5 10 15 20 25 30 35 40 45 50',
"mapping taps works";
[5,10,15,20,25,30,35,40,45,50],
"mapping tap with single values works";

tap_ok Supply.for(1..10).map( { $_ xx 2 } ),
[1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10],
"mapping tap with multiple values works";

tap_ok Supply.for(1..10).grep( * > 5 ),
'6 7 8 9 10',
[6,7,8,9,10],
"grepping taps works";

tap_ok Supply.for(1..10,1..10).uniq,
'1 2 3 4 5 6 7 8 9 10',
[1,2,3,4,5,6,7,8,9,10],
"uniq tap works";

tap_ok Supply.for(1..10).uniq(:as(* div 2)),
'1 2 4 6 8 10',
[1,2,4,6,8,10],
"uniq with as tap works";

tap_ok Supply.for(<a A B b c C>).uniq( :with( {$^a.lc eq $^b.lc} ) ),
'a B c',
[<a B c>],
"uniq with with tap works";

tap_ok Supply.for(<a AA B bb cc C>).uniq(
:as( *.substr(0,1) ), :with( {$^a.lc eq $^b.lc} )
),
'a B cc',
[<a B cc>],
"uniq with as and with tap works";

tap_ok Supply.for(1..10,1..10).squish,
'1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10',
[1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10],
"squish tap with 2 ranges works";

tap_ok Supply.for(1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10).squish,
'1 2 3 4 5 6 7 8 9 10',
[1,2,3,4,5,6,7,8,9,10],
"squish tap with doubling range works";

tap_ok Supply.for(1..10).squish(:as(* div 2)),
'1 2 4 6 8 10',
[1,2,4,6,8,10],
"squish with as tap works";

tap_ok Supply.for(<a A B b c C A>).squish( :with( {$^a.lc eq $^b.lc} ) ),
'a B c A',
[<a B c A>],
"squish with with tap works";

tap_ok Supply.for(<a AA B bb cc C AA>).squish(
:as( *.substr(0,1) ), :with( {$^a.lc eq $^b.lc} )
),
'a B cc AA',
[<a B cc AA>],
"squish with as and with tap works";

{
Expand Down

0 comments on commit 9bf4cfb

Please sign in to comment.