Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 53 lines (42 sloc) 1.524 kB
d198f6b [t/spec] s/use v6-alpha;/use v6;/
moritz authored
1 use v6;
53330f8 Test suite refactoring.
cosimo authored
2 use Test;
3
ccace72 [t/spec] fix smartlinks in S32-list
moritz authored
4 # L<S32::Containers/"List"/"=item classify">
53330f8 Test suite refactoring.
cosimo authored
5
d6cc5f5 [t/spec] clean up classify.t, and extend it
moritz authored
6 plan 16;
7
8 {
9 my @list = 1, 2, 3, 4;
10 my @results = @list.classify: { $_ % 2 ?? 'odd' !! 'even' };
11 ok @results[0] ~~ Pair, 'got Pairs back from classify';
12 is +@results, 2, 'got two values back from classify';
13
f64c232 @colomon Fudge for niecza. (Also be more explicit about the sort call for nie…
colomon authored
14 @results = @results.sort({ .key });
d6cc5f5 [t/spec] clean up classify.t, and extend it
moritz authored
15 is @results[0].key, 'even', 'got correct "first" key';
16 is @results[1].key, 'odd', 'got correct "second" key';
17
18 is @results[0].value.join(','), '2,4', 'correct values from "even" key';
19 is @results[1].value.join(','), '1,3', 'correct values from "odd" key';
20 }
53330f8 Test suite refactoring.
cosimo authored
21
a20c69c [t/spec/*.t] :todo whackage
lwall authored
22 #?pugs todo 'feature'
d6cc5f5 [t/spec] clean up classify.t, and extend it
moritz authored
23 #?rakudo skip 'binding'
f64c232 @colomon Fudge for niecza. (Also be more explicit about the sort call for nie…
colomon authored
24 #?niecza skip 'Cannot use bind operator with this LHS'
a20c69c [t/spec/*.t] :todo whackage
lwall authored
25 {
26 my @list = (1, 2, 3, 4);
27 my (@even,@odd);
d6cc5f5 [t/spec] clean up classify.t, and extend it
moritz authored
28 lives_ok { (:@even, :@odd) := classify { $_ % 2 ?? 'odd' !! 'even' }, 1,2,3,4}, 'Can bind result list of classify';
a20c69c [t/spec/*.t] :todo whackage
lwall authored
29 is_deeply(@even, [2,4], "got expected evens");
3737fe2 [gsoc_spectest] Fixed typo in test. 1 modified test.
Auzon authored
30 is_deeply(@odd, [1,3], "got expected odds");
a20c69c [t/spec/*.t] :todo whackage
lwall authored
31 }
53330f8 Test suite refactoring.
cosimo authored
32
a20c69c [t/spec/*.t] :todo whackage
lwall authored
33 #?pugs todo 'feature'
34 {
35 my %by_five;
d6cc5f5 [t/spec] clean up classify.t, and extend it
moritz authored
36 lives_ok { %by_five = classify { $_ * 5 }, 1, 2, 3, 4},
37 'can classify by numbers';
53330f8 Test suite refactoring.
cosimo authored
38
a20c69c [t/spec/*.t] :todo whackage
lwall authored
39 is( %by_five{5}, 1);
40 is( %by_five{10}, 2);
41 is( %by_five{15}, 3);
42 is( %by_five{20}, 4);
43 }
53330f8 Test suite refactoring.
cosimo authored
44
1af085a [t/spec]
moritz authored
45 # .classify should work on non-arrays
f64c232 @colomon Fudge for niecza. (Also be more explicit about the sort call for nie…
colomon authored
46 #?niecza todo "Not sure what these should do"
53330f8 Test suite refactoring.
cosimo authored
47 {
1af085a [t/spec]
moritz authored
48 lives_ok { 42.classify: { $_ } }, "method form of classify should not work on numbers";
49 lives_ok { "str".classify: { $_ } }, "method form of classify should not work on strings";
53330f8 Test suite refactoring.
cosimo authored
50 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
51
52 # vim: ft=perl6
Something went wrong with that request. Please try again.