Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 280 lines (218 sloc) 6.474 kB
d198f6b [t/spec] s/use v6-alpha;/use v6;/
moritz authored
1 use v6;
53330f8 Test suite refactoring.
cosimo authored
2 use Test;
0d5bc79 @masak [S32-list/sort.t] removed test
masak authored
3 plan 32;
53330f8 Test suite refactoring.
cosimo authored
4
ccace72 [t/spec] fix smartlinks in S32-list
moritz authored
5 # L<S32::Containers/"List"/"=item sort">
53330f8 Test suite refactoring.
cosimo authored
6
7 {
8 my @a = (4, 5, 3, 2, 5, 1);
9 my @e = (1 .. 5, 5);
10
11 my @s = sort(@a);
12 is(@s, @e, 'array of numbers was sorted');
13 }
14
15 {
16 my @a = (4, 5, 3, 2, 5, 1);
17 my @e = (1 .. 5, 5);
18
19 my @s = sort @a;
ca4a12a [t/spec] Add test for sorting floats with Inf/NaN in S32-list/sort.t
leto authored
20 is(@s, @e, 'array of numbers was sorted (w/out parens)');
21 }
22
23 {
801c909 @colomon Trying to make less pathological, plus light fudging for niecza.
colomon authored
24 # This test used to have NaN in it, but that is nonsensical.
25 # --colomon
26
27 my @a = (1.1,2,-3.05,0.1,Inf,42,-1e-07,-Inf).sort;
28 my @e = (-Inf,-3.05,-1e-07,0.1,1.1,2,42,Inf);
ca4a12a [t/spec] Add test for sorting floats with Inf/NaN in S32-list/sort.t
leto authored
29 my @s = sort @a;
801c909 @colomon Trying to make less pathological, plus light fudging for niecza.
colomon authored
30 is(@s, @e, 'array of mixed numbers including Inf');
53330f8 Test suite refactoring.
cosimo authored
31 }
32
33 {
34 my @a = (4, 5, 3, 2, 5, 1);
35 my @e = (1 .. 5, 5);
36
37 my @s = @a.sort;
38 is(@s, @e, 'array of numbers was sorted (using invocant form)');
39 }
40
e4b089d @coke pugs fudges
coke authored
41 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
42 {
43 my @a = (2, 45, 6, 1, 3);
44 my @e = (1, 2, 3, 6, 45);
45
46 my @s = sort { $^a <=> $^b }, @a;
3ad9371 [t] added named arg tests for Lists, exists, and abs
frew authored
47 is(@s, @e, '... with explicit spaceship');
53330f8 Test suite refactoring.
cosimo authored
48 }
49
0960758 Some updates to S29-list.
pmichaud authored
50 #?rakudo skip "closure as non-final argument"
801c909 @colomon Trying to make less pathological, plus light fudging for niecza.
colomon authored
51 #?niecza skip 'Invocant handling is NYI'
e4b089d @coke pugs fudges
coke authored
52 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
53 {
54 my @a = (2, 45, 6, 1, 3);
55 my @e = (1, 2, 3, 6, 45);
56
57 my @s = sort { $^a <=> $^b }: @a;
0960758 Some updates to S29-list.
pmichaud authored
58 is(@s, @e, '... with closure as indirect invocant');
53330f8 Test suite refactoring.
cosimo authored
59 }
60
83474c3 [t/spec]: Clean up a few tests.
pmichaud authored
61 #?rakudo skip "method fallback to sub unimpl"
801c909 @colomon Trying to make less pathological, plus light fudging for niecza.
colomon authored
62 #?niecza skip 'err, what?'
e4b089d @coke pugs fudges
coke authored
63 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
64 {
65 my @a = (2, 45, 6, 1, 3);
66 my @e = (1, 2, 3, 6, 45);
67
68 my @s = { $^a <=> $^b }.sort: @a;
3ad9371 [t] added named arg tests for Lists, exists, and abs
frew authored
69 is(@s, @e, '... with closure as direct invocant');
53330f8 Test suite refactoring.
cosimo authored
70 }
71
e4b089d @coke pugs fudges
coke authored
72 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
73 {
74 my @a = (2, 45, 6, 1, 3);
75 my @e = (1, 2, 3, 6, 45);
76
690570b [t/spec] more whitespaces for disambiguation
moritz authored
77 my @s = @a.sort: { $^a <=> $^b };
3ad9371 [t] added named arg tests for Lists, exists, and abs
frew authored
78 is(@s, @e, '... with explicit spaceship (using invocant form)');
53330f8 Test suite refactoring.
cosimo authored
79 }
80
e4b089d @coke pugs fudges
coke authored
81 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
82 {
83 my @a = (2, 45, 6, 1, 3);
84 my @e = (45, 6, 3, 2, 1);
85
86 my @s = sort { $^b <=> $^a }, @a;
3ad9371 [t] added named arg tests for Lists, exists, and abs
frew authored
87 is(@s, @e, '... reverse sort with explicit spaceship');
53330f8 Test suite refactoring.
cosimo authored
88 }
89
e4b089d @coke pugs fudges
coke authored
90 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
91 {
92 my @a = (2, 45, 6, 1, 3);
93 my @e = (45, 6, 3, 2, 1);
94
690570b [t/spec] more whitespaces for disambiguation
moritz authored
95 my @s = @a.sort: { $^b <=> $^a };
3ad9371 [t] added named arg tests for Lists, exists, and abs
frew authored
96 is(@s, @e, '... reverse sort with explicit spaceship (using invocant form)');
53330f8 Test suite refactoring.
cosimo authored
97 }
98
99 {
100 my @a = <foo bar gorch baz>;
101 my @e = <bar baz foo gorch>;
102
103 my @s = sort(@a);
104 is(@s, @e, 'array of strings was sorted');
105 }
106
107 {
108 my @a = <foo bar gorch baz>;
109 my @e = <bar baz foo gorch>;
110
111 my @s = sort @a;
ca4a12a [t/spec] Add test for sorting floats with Inf/NaN in S32-list/sort.t
leto authored
112 is(@s, @e, 'array of strings was sorted (w/out parens)');
53330f8 Test suite refactoring.
cosimo authored
113 }
114
115 {
116 my @a = <foo bar gorch baz>;
117 my @e = <bar baz foo gorch>;
118
119 my @s = @a.sort;
120 is(@s, @e, 'array of strings was sorted (using invocant form)');
121 }
122
e4b089d @coke pugs fudges
coke authored
123 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
124 {
125 my @a = <daa boo gaa aaa>;
126 my @e = <aaa boo daa gaa>;
127
128 my @s = sort { $^a cmp $^b }, @a;
3ad9371 [t] added named arg tests for Lists, exists, and abs
frew authored
129 is(@s, @e, '... with explicit cmp');
53330f8 Test suite refactoring.
cosimo authored
130 }
131
e4b089d @coke pugs fudges
coke authored
132 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
133 {
134 my @a = <daa boo gaa aaa>;
135 my @e = <aaa boo daa gaa>;
136
690570b [t/spec] more whitespaces for disambiguation
moritz authored
137 my @s = @a.sort: { $^a cmp $^b };
3ad9371 [t] added named arg tests for Lists, exists, and abs
frew authored
138 is(@s, @e, '... with explicit cmp (using invocant form)');
53330f8 Test suite refactoring.
cosimo authored
139 }
140
61b6d30 [spec] fudged S29-list/{grep,sort}.t, patch curtesy of bacek++
moritz authored
141
e4b089d @coke pugs fudges
coke authored
142 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
143 {
144 my %a = (4 => 'a', 1 => 'b', 2 => 'c', 5 => 'd', 3 => 'e');
145 my @e = (4, 1, 2, 5, 3);
146
147 my @s = sort { %a{$^a} cmp %a{$^b} }, %a.keys;
3ad9371 [t] added named arg tests for Lists, exists, and abs
frew authored
148 is(@s, @e, '... sort keys by string value');
53330f8 Test suite refactoring.
cosimo authored
149 }
150
e4b089d @coke pugs fudges
coke authored
151 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
152 {
153 my %a = (4 => 'a', 1 => 'b', 2 => 'c', 5 => 'd', 3 => 'e');
154 my @e = (4, 1, 2, 5, 3);
155
690570b [t/spec] more whitespaces for disambiguation
moritz authored
156 my @s = %a.keys.sort: { %a{$^a} cmp %a{$^b} };
53330f8 Test suite refactoring.
cosimo authored
157 is(@s, @e, '... sort keys by string value (using invocant form)');
158 }
159
e4b089d @coke pugs fudges
coke authored
160 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
161 {
162 my %a = ('a' => 4, 'b' => 1, 'c' => 2, 'd' => 5, 'e' => 3);
163 my @e = <b c e a d>;
164
165 my @s = sort { %a{$^a} <=> %a{$^b} }, %a.keys;
166 is(@s, @e, '... sort keys by numeric value');
167 }
168
e4b089d @coke pugs fudges
coke authored
169 #?pugs todo
53330f8 Test suite refactoring.
cosimo authored
170 {
171 my %a = ('a' => 4, 'b' => 1, 'c' => 2, 'd' => 5, 'e' => 3);
172 my @e = <b c e a d>;
173
690570b [t/spec] more whitespaces for disambiguation
moritz authored
174 my @s = %a.keys.sort: { %a{$^a} <=> %a{$^b} };
53330f8 Test suite refactoring.
cosimo authored
175 is(@s, @e, '... sort keys by numeric value (using invocant form)');
176 }
177
1781a85 [t/spec] add tests for sort, both with unary closure and to ensure th…
moritz authored
178
e4b089d @coke pugs fudges
coke authored
179 #?pugs skip '.key'
1781a85 [t/spec] add tests for sort, both with unary closure and to ensure th…
moritz authored
180 {
181 my %map = (p => 1, e => 2, r => 3, l => 4);
182
49d046f .join now defaults to ''
lwall authored
183 is <r e p l>.sort({ %map{$_} }).join, 'perl',
1781a85 [t/spec] add tests for sort, both with unary closure and to ensure th…
moritz authored
184 'can sort with automated Schwartzian Transform';
185
186 my @s = %map.sort: { .value };
187 isa_ok(@s[0], Pair, '%hash.sort returns a List of Pairs');
49d046f .join now defaults to ''
lwall authored
188 is (@s.map: { .key }).join, 'perl', 'sort with unary sub'
1781a85 [t/spec] add tests for sort, both with unary closure and to ensure th…
moritz authored
189 }
190
e4b089d @coke pugs fudges
coke authored
191
48814de @colomon Fix tests to match pmichaud's comment, not to mention the behavior of…
colomon authored
192 #?niecza todo "Niecza's sort is not stable"
e4b089d @coke pugs fudges
coke authored
193 #?pugs skip 'Cannot cast into Array: VRef'
1781a85 [t/spec] add tests for sort, both with unary closure and to ensure th…
moritz authored
194 {
49d046f .join now defaults to ''
lwall authored
195 is (<P e r l 6>.sort: { 0; }).join, 'Perl6',
1781a85 [t/spec] add tests for sort, both with unary closure and to ensure th…
moritz authored
196 'sort with arity 0 closure is stable';
197
198 my @a = ([5, 4], [5, 5], [5, 6], [0, 0], [1, 2], [1, 3], [0, 1], [5, 7]);
199
200 {
201 my @s = @a.sort: { .[0] };
202
203 ok ([<] @s.map({.[1]})), 'sort with arity 1 closure is stable';
204 }
205
206 {
207 my @s = @a.sort: { $^a.[0] <=> $^b.[0] };
208
209 ok ([<] @s.map({.[1]})), 'sort with arity 2 closure is stable';
210 }
211 }
212
0960758 Some updates to S29-list.
pmichaud authored
213 ## XXX pmichaud, 2008-07-01: .sort should work on non-list values
53330f8 Test suite refactoring.
cosimo authored
214 {
48814de @colomon Fix tests to match pmichaud's comment, not to mention the behavior of…
colomon authored
215 is ~42.sort, "42", "method form of sort should work on numbers";
216 is ~"str".sort, "str", "method form of sort should work on strings";
801c909 @colomon Trying to make less pathological, plus light fudging for niecza.
colomon authored
217 is ~(42,).sort, "42", "method form of sort should work on parcels";
53330f8 Test suite refactoring.
cosimo authored
218 }
c2f8fec [t] and [t/spec] (two train travels worth of changes):
moritz authored
219
6f8418d [t/spec] tests for RT #67010 Error with glibc backtrace dump when cmp…
bbkr authored
220 # RT #67010
e4b089d @coke pugs fudges
coke authored
221 #?pugs todo
6f8418d [t/spec] tests for RT #67010 Error with glibc backtrace dump when cmp…
bbkr authored
222 {
223 my @list = 1, 2, Code;
224 lives_ok { @list.sort: { $^a cmp $^b } },
225 'sort by class name';
226 }
227
46a0f39 [t/spec] tests for RT #68112 sort doesnt accept &rand (or zero-arg su…
bbkr authored
228 # RT #68112
9c33dc2 [t/spec] tests for RT #68112 sort doesnt accept &rand (or zero-arg su…
bbkr authored
229 #?rakudo skip "determine behavior of 0-arity methods passed to sort"
801c909 @colomon Trying to make less pathological, plus light fudging for niecza.
colomon authored
230 #?niecza skip "determine behavior of 0-arity methods passed to sort"
46a0f39 [t/spec] tests for RT #68112 sort doesnt accept &rand (or zero-arg su…
bbkr authored
231 {
6e0c51d [sort.t] fix parsefail; reduce op requires whitespace
lwall authored
232 sub foo () { 0 } #OK not used
46a0f39 [t/spec] tests for RT #68112 sort doesnt accept &rand (or zero-arg su…
bbkr authored
233 lives_ok { (1..10).sort(&foo) },
234 'sort accepts 0-arity method';
801c909 @colomon Trying to make less pathological, plus light fudging for niecza.
colomon authored
235 # errr... is there even supposed to be a rand sub?
46a0f39 [t/spec] tests for RT #68112 sort doesnt accept &rand (or zero-arg su…
bbkr authored
236 lives_ok { (1..10).sort(&rand) },
237 'sort accepts rand method';
238 }
239
6f2dd51 [t/spec] tests for RT #71258 Cant sort objects of a custom class, can…
bbkr authored
240 # RT #71258
241 {
242 class RT71258_1 { };
243
244 my @sorted;
245
48814de @colomon Fix tests to match pmichaud's comment, not to mention the behavior of…
colomon authored
246 #?niecza todo 'Is this test actually testing for correct behavior?'
6f2dd51 [t/spec] tests for RT #71258 Cant sort objects of a custom class, can…
bbkr authored
247 lives_ok { @sorted = (RT71258_1.new, RT71258_1.new).sort },
248 'sorting by stringified class instance (name and memory address)';
249
250 class RT71258_2 {
251 has $.x;
252 method Str { $.x }
253 };
254
801c909 @colomon Trying to make less pathological, plus light fudging for niecza.
colomon authored
255 # Following tests removed because you cannot
256 # affect the behavior of sort by defining
257 # sub cmp. As far as I understand things, you
258 # couldn't even affect it by defined
259 # a new sub infix:<cmp>. --colomon
260
261 # multi sub cmp(RT71258_2 $a, RT71258_2 $b) {
262 # $a.x <=> $b.x;
263 # }
264 #
265 # #?rakudo todo 'nom regression'
266 # lives_ok {
267 # @sorted = (
268 # RT71258_2.new(x => 2),
269 # RT71258_2.new(x => 3),
270 # RT71258_2.new(x => 1)
271 # ).sort
272 # }, 'sorting stringified class instance with custom cmp';
273 #
274 # #?rakudo todo 'nom regression'
275 # is ~@sorted, '1 2 3',
276 # 'checking sort order with custom cmp';
6f2dd51 [t/spec] tests for RT #71258 Cant sort objects of a custom class, can…
bbkr authored
277 }
278
c2f8fec [t] and [t/spec] (two train travels worth of changes):
moritz authored
279 # vim: ft=perl6
Something went wrong with that request. Please try again.