Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests for Supply.uniq( :expires )
  • Loading branch information
lizmat committed Apr 23, 2014
1 parent 4d38b1f commit 6f8a5d1
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion S17-concurrency/supply.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 248;
plan 272;

sub tap_ok ( $s, $expected, $text, :$sort, :&after_tap, :$timeout is copy = 5 ) {
ok $s ~~ Supply, "{$s.^name} appears to be doing Supply";
Expand Down Expand Up @@ -124,6 +124,79 @@ for (ThreadPoolScheduler, CurrentThreadScheduler) {
[<a B cc>],
"uniq with as and with tap works";

{
my $s = Supply.new;
tap_ok $s.uniq( :expires(2) ),
[1,2,3,1,2],
'uniq with expiry works',
:after_tap( {
$s.more(1);
sleep 1;
$s.more(2);
sleep 1;
$s.more(3);
sleep 1;
$s.more(1);
$s.more(2);
$s.more(3); # twice within expiration time
} );
}

{
my $s = Supply.new;
tap_ok $s.uniq( :as( * div 2 ), :expires(2) ),
[1,2,1,2],
'uniq with as and expiry works',
:after_tap( {
$s.more(1);
sleep 1;
$s.more(2);
sleep 1;
$s.more(3); # same as 2
sleep 1;
$s.more(1);
$s.more(2);
$s.more(3); # twice within expiration time
} );
}

{
my $s = Supply.new;
tap_ok $s.uniq( :with( {$^a.lc eq $^b.lc} ), :expires(2) ),
[<a b c B>],
'uniq with as and expiry works',
:after_tap( {
$s.more("a");
sleep 1;
$s.more("b");
sleep 1;
$s.more("B"); # same as "b"
sleep 1;
$s.more("c");
$s.more("B");
$s.more("b"); # same as "B"
} );
}

{
my $s = Supply.new;
tap_ok $s.uniq(
:as( *.substr(0,1) ), :with( {$^a.lc eq $^b.lc} ), :expires(2) ),
[<a bb c B>],
'uniq with as and expiry works',
:after_tap( {
$s.more("a");
sleep 1;
$s.more("bb");
sleep 1;
$s.more("B"); # same as "bb"
sleep 1;
$s.more("c");
$s.more("B");
$s.more("bb"); # same as "B"
} );
}

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],
"squish tap with 2 ranges works";
Expand Down

0 comments on commit 6f8a5d1

Please sign in to comment.