Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 46 lines (37 sloc) 1.463 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
use v6;
use Test;

# L<S03/List infix precedence/"can be 0-ary as well">

plan 13;

# Test with Whatever limit
{
    my @rolls = ({ (1..6).pick } ... *).[^20];
    is +@rolls, 20, 'Got the number of rolls we asked for';
    is @rolls.grep(Int).elems, 20, 'all the rolls are Ints';
    is @rolls.grep(1..6).elems, 20, 'all the rolls are in the Range 1..6';
}

# Test with exact limit
#?niecza skip 'Unable to resolve method munch in class List'
{
    my @rolls = ({ (1..2).pick } ... 2).munch(100);
    ok +@rolls > 0, 'the sequence had at least one element...';
    ok +@rolls < 100, '... and the sequence terminated';
    is @rolls.grep(Int).elems, +@rolls, 'all the rolls are Ints';
    is @rolls.grep(2).elems, 1, 'There was exactly one 2 rolled...';
    is @rolls[@rolls.elems - 1], 2, '...and it was the last roll';
}

# Test with limit between possible values
#?niecza skip 'Unable to resolve method munch in class List'
{
    my @rolls = ({ (1..2).pick } ... 1.5).munch(100);
    ok +@rolls == 100, 'the sequence is infinite...';
    is @rolls.grep(Int).elems, +@rolls, 'all the rolls are Ints';
}

# Test with limit that cannot be hit
#?niecza skip 'Unable to resolve method munch in class List'
{
    my @rolls = ({ (1..6).pick } ... 7).munch(40);
    is +@rolls, 40, 'Got the number of rolls we asked for';
    is @rolls.grep(Int).elems, 40, 'all the rolls are Ints';
    is @rolls.grep(1..6).elems, 40, 'all the rolls are in the Range 1..6';
}


done;
Something went wrong with that request. Please try again.