Skip to content

Commit ae3ad50

Browse files
committed
Handle more paranoid infix:<eqv> of 463e758
1 parent 2199588 commit ae3ad50

File tree

2 files changed

+62
-59
lines changed

2 files changed

+62
-59
lines changed

S32-list/categorize.t

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ plan 28;
77

88
{ # basic categorize with all possible mappers
99
my @list = 29, 7, 12, 9, 18, 23, 3, 7;
10-
my %expected1 =
11-
('0'=>[7,9,3,7], '10'=>[12,18], '20'=>[29,23]);
12-
my %expected2 =
13-
('0'=>[7,9,3,7,7,9,3,7], '10'=>[12,18,12,18], '20'=>[29,23,29,23]);
10+
my %expected1{Any} =
11+
(0=>[7,9,3,7], 10=>[12,18], 20=>[29,23]);
12+
my %expected2{Any} =
13+
(0=>[7,9,3,7,7,9,3,7], 10=>[12,18,12,18], 20=>[29,23,29,23]);
1414
my sub subber ($a) { $a - ($a % 10) };
1515
my $blocker = { $_ - ($_ % 10) };
1616
my $hasher = { 3=>0, 7=>0, 9=>0, 12=>10, 18=>10, 23=>20, 29=>20 };
@@ -22,14 +22,14 @@ plan 28;
2222
is-deeply @list.categorize( $mapper ), %expected1,
2323
"method call on list with {$mapper.^name}";
2424

25-
categorize( $mapper, @list, :into(my %h) );
25+
categorize( $mapper, @list, :into(my %h{Any}) );
2626
is-deeply %h, %expected1,
2727
"basic categorize as sub with {$mapper.^name} and new into";
2828
categorize( $mapper, @list, :into(%h) );
2929
is-deeply %h, %expected2,
3030
"basic categorize as sub with {$mapper.^name} and existing into";
3131

32-
@list.categorize( $mapper, :into(my %i) );
32+
@list.categorize( $mapper, :into(my %i{Any}) );
3333
is-deeply %i, %expected1,
3434
"basic categorize from list with {$mapper.^name} and new into";
3535
@list.categorize( $mapper, :into(%i) );
@@ -91,12 +91,13 @@ plan 28;
9191
#?niecza todo 'feature'
9292
{
9393
is-deeply( categorize( { map { [$_+0, $_+10] }, .comb }, 100,104,112,119 ),
94-
:{1 => :{ 11 => [100, 104, 112, 112, 119, 119] },
95-
0 => :{ 10 => [100, 100, 104] },
96-
4 => :{ 14 => [104] },
97-
2 => :{ 12 => [112] },
98-
9 => :{ 19 => [119] },
99-
}, 'multi-level categorize' );
94+
(my %{Any} =
95+
1 => ( my %{Any} = 11 => [100, 104, 112, 112, 119, 119] ),
96+
0 => ( my %{Any} = 10 => [100, 100, 104] ),
97+
4 => ( my %{Any} = 14 => [104] ),
98+
2 => ( my %{Any} = 12 => [112] ),
99+
9 => ( my %{Any} = 19 => [119] ),
100+
), 'multi-level categorize' );
100101
}
101102

102103
# vim: ft=perl6

S32-list/classify.t

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@ plan 40;
77

88
{
99
my @list = 1, 2, 3, 4;
10-
my $classified1 = { even => [2,4], odd => [1,3] };
11-
my $classified2 = { even => [2,4,2,4], odd => [1,3,1,3] };
10+
my %classified1{Any} = even => [2,4], odd => [1,3];
11+
my %classified2{Any} = even => [2,4,2,4], odd => [1,3,1,3];
1212
my sub subber ($a) { $a % 2 ?? 'odd' !! 'even' };
1313
my $blocker = { $_ % 2 ?? 'odd' !! 'even' };
1414
my $hasher = { 1 => 'odd', 2 => 'even', 3 => 'odd', 4 => 'even' };
1515
my $arrayer = <huh odd even odd even>.list;
1616

1717
for &subber, $blocker, $hasher, $arrayer -> $classifier {
18-
is-deeply @list.classify( $classifier ), $classified1,
18+
is-deeply @list.classify( $classifier ), %classified1,
1919
"basic classify from list with {$classifier.^name}";
20-
is-deeply classify( $classifier, @list ), $classified1,
20+
is-deeply classify( $classifier, @list ), %classified1,
2121
"basic classify as subroutine with {$classifier.^name}";
2222

23-
classify( $classifier, @list, :into(my %h) );
24-
is-deeply %h, $classified1,
23+
classify( $classifier, @list, :into(my %h{Any}) );
24+
is-deeply %h, %classified1,
2525
"basic classify as sub with {$classifier.^name} and new into";
2626
classify( $classifier, @list, :into(%h) );
27-
is-deeply %h, $classified2,
27+
is-deeply %h, %classified2,
2828
"basic classify as sub with {$classifier.^name} and existing into";
2929

30-
@list.classify( $classifier, :into(my %i) );
31-
is-deeply %i, $classified1,
30+
@list.classify( $classifier, :into(my %i{Any}) );
31+
is-deeply %i, %classified1,
3232
"basic classify from list with {$classifier.^name} and new into";
3333
@list.classify( $classifier, :into(%i) );
34-
is-deeply %i, $classified2,
34+
is-deeply %i, %classified2,
3535
"basic classify from list with {$classifier.^name} and existing into";
3636
}
3737

@@ -54,57 +54,59 @@ plan 40;
5454
} #3
5555

5656
{
57-
my $result = { 5 => [1], 10 => [2], 15 => [3], 20 => [4] };
58-
is-deeply classify( { $_ * 5 }, 1, 2, 3, 4 ), $result,
57+
my %result{Any} = 5 => [1], 10 => [2], 15 => [3], 20 => [4];
58+
is-deeply classify( { $_ * 5 }, 1, 2, 3, 4 ), %result,
5959
'can classify by numbers';
60-
classify( { $_ * 5 }, 1, 2, 3, 4, :into(my %by_five) );
61-
is-deeply %by_five, $result,
60+
classify( { $_ * 5 }, 1, 2, 3, 4, :into(my %by_five{Any}) );
61+
is-deeply %by_five, %result,
6262
'can classify by numbers into an existing empty hash';
6363
classify( { $_ * 5 }, 1, 2, 3, 4, :into(%by_five) );
64-
$_[1] = $_[0] for $result.values;
65-
is-deeply %by_five, $result,
64+
$_[1] = $_[0] for %result.values;
65+
is-deeply %by_five, %result,
6666
'can classify by numbers into an existing filled hash';
6767
classify( { $_ * 5 }, 1, 2, 3, 4, :into(%by_five), :as(* * 2) );
68-
$_[2] = 2 * $_[1] for $result.values;
69-
is-deeply %by_five, $result,
68+
$_[2] = 2 * $_[1] for %result.values;
69+
is-deeply %by_five, %result,
7070
'can classify by numbers into an existing filled hash with an :as';
7171
} #4
7272

7373
# .classify should work on non-arrays
7474
{
75-
is-deeply 42.classify( {$_} ), { 42 => [42] }, "classify single num";
76-
is-deeply "A".classify( {$_} ), { A => ["A"] }, "classify single string";
75+
is-deeply 42.classify( {$_} ), (my %{Any} = 42 => [42]), "classify single num";
76+
is-deeply "A".classify( {$_} ), (my %{Any} = A => ["A"]), "classify single string";
7777
} #2
7878

7979
#?niecza todo 'feature'
8080
{
8181
is-deeply( classify( {.comb}, flat 100 .. 119, 104, 119 ),
82-
("1" => {
83-
"0" => {
84-
"0" => [100],
85-
"1" => [101],
86-
"2" => [102],
87-
"3" => [103],
88-
"4" => [104,104],
89-
"5" => [105],
90-
"6" => [106],
91-
"7" => [107],
92-
"8" => [108],
93-
"9" => [109],
94-
},
95-
"1" => {
96-
"0" => [110],
97-
"1" => [111],
98-
"2" => [112],
99-
"3" => [113],
100-
"4" => [114],
101-
"5" => [115],
102-
"6" => [116],
103-
"7" => [117],
104-
"8" => [118],
105-
"9" => [119,119],
106-
}
107-
}).hash, 'multi-level classify' );
82+
(my %{Any} =
83+
"1" => (my %{Any} =
84+
"0" => (my %{Any} =
85+
"0" => [100],
86+
"1" => [101],
87+
"2" => [102],
88+
"3" => [103],
89+
"4" => [104,104],
90+
"5" => [105],
91+
"6" => [106],
92+
"7" => [107],
93+
"8" => [108],
94+
"9" => [109],
95+
),
96+
"1" => (my %{Any} =
97+
"0" => [110],
98+
"1" => [111],
99+
"2" => [112],
100+
"3" => [113],
101+
"4" => [114],
102+
"5" => [115],
103+
"6" => [116],
104+
"7" => [117],
105+
"8" => [118],
106+
"9" => [119,119],
107+
)
108+
)
109+
), 'multi-level classify' );
108110
}
109111

110112
is classify( { "foo" }, () ).elems, 0, 'classify an empty list';
@@ -113,7 +115,7 @@ is classify( { "foo" }, () ).elems, 0, 'classify an empty list';
113115
{
114116
is-deeply
115117
<a b c>.classify({ ~($ ~= $_); }),
116-
{'a' => ['a'], 'ab' => ['b'], 'abc' => ['c']},
118+
(my %{Any} = 'a' => ['a'], 'ab' => ['b'], 'abc' => ['c']),
117119
'&test only run once for each item';
118120
}
119121

0 commit comments

Comments
 (0)