Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 65 lines (53 sloc) 2.844 kb
e5f7c9c [t/spec] Nine variants on the Fibonacci series.
colomon authored
1 use v6;
2 use Test;
3
ef86bef @moritz [sequence] is the new series
moritz authored
4 # L<S03/List infix precedence/"the sequence operator">
e5f7c9c [t/spec] Nine variants on the Fibonacci series.
colomon authored
5
79c35cc @usev6 Add test for RT #117825 (skipped for Parrot)
usev6 authored
6 plan 20;
e5f7c9c [t/spec] Nine variants on the Fibonacci series.
colomon authored
7
79c35cc @usev6 Add test for RT #117825 (skipped for Parrot)
usev6 authored
8 # some tests without regard to ending
e5f7c9c [t/spec] Nine variants on the Fibonacci series.
colomon authored
9
9e9686f [t/spec] replace .batch($x) with .[^$x]
moritz authored
10 is (1, 1, { $^a + $^b } ... *).[^6].join(', '), '1, 1, 2, 3, 5, 8', 'arity-2 Fibonacci';
53704ce [t/spec/S03-operators/series*.t] Deleted redundant tests, reorganized an...
Kodi authored
11 is (1, 1, &infix:<+> ... *).[^6].join(', '), '1, 1, 2, 3, 5, 8', 'arity-2 Fibonacci, using "&infix:<+>"';
5fd22f2 @colomon Fudge for niecza.
colomon authored
12 #?niecza skip "Undeclared names: '[+]'"
53704ce [t/spec/S03-operators/series*.t] Deleted redundant tests, reorganized an...
Kodi authored
13 is (1, 1, &[+] ... *).[^6].join(', '), '1, 1, 2, 3, 5, 8', 'arity-2 Fibonacci, using "&[+]"';
9e9686f [t/spec] replace .batch($x) with .[^$x]
moritz authored
14 is (0, 1, { $^a + $^b } ... *).[^7].join(', '), '0, 1, 1, 2, 3, 5, 8', 'arity-2 Fibonacci, 0 1 seeds';
15 is (1, 1, 2, -> $a, $b { $a + $b } ... *).[^6].join(', '), '1, 1, 2, 3, 5, 8', 'arity-2 Fibonacci, 3 seeds';
16 is (1, 1, 2, 3, { $^a + $^b } ... *).[^6].join(', '), '1, 1, 2, 3, 5, 8', 'arity-2 Fibonacci, 4 seeds';
17 is (0, 1, 1, 2, 3, { $^a + $^b } ... *).[^7].join(', '), '0, 1, 1, 2, 3, 5, 8', 'arity-2 Fibonacci, 5 seeds';
e5f7c9c [t/spec] Nine variants on the Fibonacci series.
colomon authored
18
19 # some tests which exactly hit a limit
20
c5fb7f2 [t/spec] Don't use .[^20] on tests which should have finite results.
colomon authored
21 is (1, 1, { $^a + $^b } ... 8).join(', '), '1, 1, 2, 3, 5, 8', 'arity-2 Fibonacci';
22 is (1, 1, 2, -> $a, $b { $a + $b } ... 8).join(', '), '1, 1, 2, 3, 5, 8', 'arity-2 Fibonacci, 3 seeds';
23 is (1, 1, 2, 3, { $^a + $^b } ... 8).join(', '), '1, 1, 2, 3, 5, 8', 'arity-2 Fibonacci, 4 seeds';
53704ce [t/spec/S03-operators/series*.t] Deleted redundant tests, reorganized an...
Kodi authored
24 # adapted from http://www.perlmonks.org/?node_id=772778
5fd22f2 @colomon Fudge for niecza.
colomon authored
25 #?niecza skip "Undeclared names: '[%]'"
53704ce [t/spec/S03-operators/series*.t] Deleted redundant tests, reorganized an...
Kodi authored
26 is (42, 24, &[%] ... 0)[*-2], 6, 'arity-2 GCD';
5fd22f2 @colomon Fudge for niecza.
colomon authored
27 #?niecza skip "Undeclared names: '[%]'"
53704ce [t/spec/S03-operators/series*.t] Deleted redundant tests, reorganized an...
Kodi authored
28 is (42, 24, &[%] ...^ 0)[*-1], 6, 'arity-2 GCD with excluded limit';
642e4da [t/spec] Refudge for Rakudo, and add a couple of tests which are variant...
colomon authored
29 is (42, 24, * % * ... 0)[*-2], 6, 'arity-2 GCD';
30 is (42, 24, * % * ...^ 0)[*-1], 6, 'arity-2 GCD with excluded limit';
e5f7c9c [t/spec] Nine variants on the Fibonacci series.
colomon authored
31
dbebcd8 @colomon [t/spec] Fix tests to match new series spec.
colomon authored
32 # some tests which miss a limit
e5f7c9c [t/spec] Nine variants on the Fibonacci series.
colomon authored
33
dbebcd8 @colomon [t/spec] Fix tests to match new series spec.
colomon authored
34 is (1, 1, { $^a + $^b } ... 9).[^7].join(', '), '1, 1, 2, 3, 5, 8, 13', 'arity-2 Fibonacci';
35 is (1, 1, 2, -> $a, $b { $a + $b } ... 9).[^7].join(', '), '1, 1, 2, 3, 5, 8, 13', 'arity-2 Fibonacci, 3 seeds';
36 is (1, 1, 2, 3, { $^a + $^b } ... 9).[^7].join(', '), '1, 1, 2, 3, 5, 8, 13', 'arity-2 Fibonacci, 4 seeds';
e5f7c9c [t/spec] Nine variants on the Fibonacci series.
colomon authored
37
ef86bef @moritz [sequence] is the new series
moritz authored
38 # sequence with slurpy functions
53704ce [t/spec/S03-operators/series*.t] Deleted redundant tests, reorganized an...
Kodi authored
39 {
40 sub nextprime( *@prev_primes ) {
79c35cc @usev6 Add test for RT #117825 (skipped for Parrot)
usev6 authored
41 my $current = @prev_primes[*-1];
53704ce [t/spec/S03-operators/series*.t] Deleted redundant tests, reorganized an...
Kodi authored
42 1 while ++$current % any(@prev_primes) == 0;
43 return $current;
44 }
45 is (2, &nextprime ... 13).join(' '), '2 3 5 7 11 13', 'slurpy prime generator';
46 }
dbebcd8 @colomon [t/spec] Fix tests to match new series spec.
colomon authored
47 is (1, 2, sub {[*] @_[*-1], @_ + 1} ... 720).join(' '), '1 2 6 24 120 720', 'slurpy factorial generator';
53704ce [t/spec/S03-operators/series*.t] Deleted redundant tests, reorganized an...
Kodi authored
48
79c35cc @usev6 Add test for RT #117825 (skipped for Parrot)
usev6 authored
49 # RT #117825
50 # TODO: better test (e.g. typed exception instead of testing for backend specific error messages
51 #?rakudo.parrot skip 'RT #117825'
52 {
53 throws_like { ( ^1, *+* ... * )[^20] }, Exception,
54 message => {
55 m/
56 'Too few positionals passed; expected 2 arguments but got 1'
57 |
58 'Not enough positional parameters passed; got 1 but expected 2'
59 /
60 },
61 'no internals leaking out with series operator used wrongly (arity 2)';
62 }
63
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
64 done;
Something went wrong with that request. Please try again.