Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 174 lines (136 sloc) 5.302 kb
d198f6b [t/spec] s/use v6-alpha;/use v6;/
moritz authored
1 use v6;
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
2
3 use Test;
4
2d6c012 @colomon Add tests for roll and pick given a huge integer range.
colomon authored
5 plan 46;
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
6
8313f3f [t/spec] Converted pod markers to pod6
cosimo authored
7 =begin description
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
8
ccace72 [t/spec] fix smartlinks in S32-list
moritz authored
9 This test tests the C<pick> builtin. See S32::Containers#pick.
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
10
11 Previous discussions about pick.
12
3ad9371 [t] added named arg tests for Lists, exists, and abs
frew authored
13 L<"http://groups.google.com/group/perl.perl6.language/tree/browse_frm/thread/24e369fba3ed626e/4e893cad1016ed94?rnum=1&_done=%2Fgroup%2Fperl.perl6.language%2Fbrowse_frm%2Fthread%2F24e369fba3ed626e%2F6e6a2aad1dcc879d%3F#doc_2ed48e2376511fe3">
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
14
8313f3f [t/spec] Converted pod markers to pod6
cosimo authored
15 =end description
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
16
ccace72 [t/spec] fix smartlinks in S32-list
moritz authored
17 # L<S32::Containers/List/=item pick>
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
18
19 my @array = <a b c d>;
30d3be9 @coke pugs fudge
coke authored
20 #?pugs skip "autothread"
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
21 ok ?(@array.pick eq any <a b c d>), "pick works on arrays";
9b1c972 @colomon Refudge for niecza.
colomon authored
22 #?niecza skip '().pick === Nil'
30d3be9 @coke pugs fudge
coke authored
23 #?pugs skip 'Nil'
b13a406 @moritz ().pick and .roll return Nil
moritz authored
24 ok ().pick === Nil, '.pick on the empty list is Nil';
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
25
26 my @arr = <z z z>;
27
ec0d2fe [t/spec] fixed pick.t, and fudged for rakudo
moritz authored
28 ok ~(@arr.pick(2)) eq 'z z', 'method pick with $num < +@values';
29 ok ~(@arr.pick(4)) eq 'z z z', 'method pick with $num > +@values';
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
30
30d3be9 @coke pugs fudge
coke authored
31 #?pugs 2 skip 'NYI'
e66c8a2 [t/spec] Additional fudging for pick.t.
colomon authored
32 is pick(2, @arr), <z z>, 'sub pick with $num < +@values, implicit no-replace';
ec0d2fe [t/spec] fixed pick.t, and fudged for rakudo
moritz authored
33 is pick(4, @arr), <z z z>, 'sub pick with $num > +@values';
714b57d Refactored `pick' tests under /t/spec/S29-list/
cosimo authored
34
30d3be9 @coke pugs fudge
coke authored
35 #?pugs skip '.Str'
e66c8a2 [t/spec] Additional fudging for pick.t.
colomon authored
36 is (<a b c d>.pick(*).sort).Str, 'a b c d', 'pick(*) returns all the items in the array (but maybe not in order)';
f70bb14 [gsoc_spectest] added tests for pick(*). (Added 2 tests)
Auzon authored
37
38 {
027c62a [t/spec/S29-list/pick.t] answered challenge by Auzon++:
masak authored
39 my @items = <1 2 3 4>;
40 my @shuffled_items_10;
41 push @shuffled_items_10, @items.pick(*) for ^10;
42 isnt(@shuffled_items_10, @items xx 10,
43 'pick(*) returned the items of the array in a random order');
f70bb14 [gsoc_spectest] added tests for pick(*). (Added 2 tests)
Auzon authored
44 }
45
30d3be9 @coke pugs fudge
coke authored
46 #?pugs skip "autothreading"
ec0d2fe [t/spec] fixed pick.t, and fudged for rakudo
moritz authored
47 {
48 # Test that List.pick doesn't flatten array refs
dab2551 [t/spec] extended and corrected pick.t
moritz authored
49 ok ?([[1, 2], [3, 4]].pick.join('|') eq any('1|2', '3|4')), '[[1,2],[3,4]].pick does not flatten';
ec0d2fe [t/spec] fixed pick.t, and fudged for rakudo
moritz authored
50 ok ?(~([[1, 2], [3, 4]].pick(*)) eq '1 2 3 4' | '3 4 1 2'), '[[1,2],[3,4]].pick(*) does not flatten';
dab2551 [t/spec] extended and corrected pick.t
moritz authored
51 }
ec0d2fe [t/spec] fixed pick.t, and fudged for rakudo
moritz authored
52
dab2551 [t/spec] extended and corrected pick.t
moritz authored
53 {
54 ok <5 5>.pick() == 5,
55 '.pick() returns something can be used as single scalar';
ec0d2fe [t/spec] fixed pick.t, and fudged for rakudo
moritz authored
56 }
dab2551 [t/spec] extended and corrected pick.t
moritz authored
57
30d3be9 @coke pugs fudge
coke authored
58 #?pugs skip 'pick not defined: VNum Infinity'
a25207b @colomon [t/spec] Add about eighty pick and roll tests, including a new S32-li…
colomon authored
59 {
60 my @a = 1..100;
61 my @b = pick(*, @a);
62 is @b.elems, 100, "pick(*, @a) returns the correct number of elements";
63 is ~@b.sort, ~(1..100), "pick(*, @a) returns the correct elements";
64 is ~@b.grep(Int).elems, 100, "pick(*, @a) returns Ints (if @a is Ints)";
a57398b @colomon Rearrange slightly and fudge for Niecza.
colomon authored
65 }
66
67 {
68 my @a = 1..100;
a25207b @colomon [t/spec] Add about eighty pick and roll tests, including a new S32-li…
colomon authored
69
70 isa_ok @a.pick, Int, "picking a single element from an array of Ints produces an Int";
30d3be9 @coke pugs fudge
coke authored
71 #?pugs todo
a25207b @colomon [t/spec] Add about eighty pick and roll tests, including a new S32-li…
colomon authored
72 ok @a.pick ~~ 1..100, "picking a single element from an array of Ints produces one of them";
73
30d3be9 @coke pugs fudge
coke authored
74 #?pugs todo
a25207b @colomon [t/spec] Add about eighty pick and roll tests, including a new S32-li…
colomon authored
75 isa_ok @a.pick(1), Int, "picking 1 from an array of Ints produces an Int";
30d3be9 @coke pugs fudge
coke authored
76 #?pugs todo
a25207b @colomon [t/spec] Add about eighty pick and roll tests, including a new S32-li…
colomon authored
77 ok @a.pick(1) ~~ 1..100, "picking 1 from an array of Ints produces one of them";
78
79 my @c = @a.pick(2);
80 isa_ok @c[0], Int, "picking 2 from an array of Ints produces an Int...";
81 isa_ok @c[1], Int, "... and an Int";
30d3be9 @coke pugs fudge
coke authored
82 #?pugs todo
a25207b @colomon [t/spec] Add about eighty pick and roll tests, including a new S32-li…
colomon authored
83 ok (@c[0] ~~ 1..100) && (@c[1] ~~ 1..100), "picking 2 from an array of Ints produces two of them";
84 ok @c[0] != @c[1], "picking 2 from an array of Ints produces two distinct results";
85
30d3be9 @coke pugs fudge
coke authored
86 #?pugs 2 skip "NYI"
a25207b @colomon [t/spec] Add about eighty pick and roll tests, including a new S32-li…
colomon authored
87 is @a.pick("25").elems, 25, ".pick works Str arguments";
88 is pick("25", @a).elems, 25, "pick works Str arguments";
89 }
90
30d3be9 @coke pugs fudge
coke authored
91 #?pugs skip "NYI"
4f15296 @masak [S32-list/pick.t] test for deprecated :replace
masak authored
92 {
a9de2f6 @moritz various rakudo fudges and unfudges
moritz authored
93 #?rakudo todo 'error on pick :replace'
4f15296 @masak [S32-list/pick.t] test for deprecated :replace
masak authored
94 dies_ok({ [1,2,3].pick(4, :replace) }, 'error on deprecated :replace');
95 }
96
d5e42b6 @moritz tests for RT #76238, Bool.pick (and SomeEnum.pick)
moritz authored
97 # enums + pick
30d3be9 @coke pugs fudge
coke authored
98 #?pugs skip "NYI"
d5e42b6 @moritz tests for RT #76238, Bool.pick (and SomeEnum.pick)
moritz authored
99 {
0ced986 @colomon Add a couple of tests, unfudge for niecza.
colomon authored
100 is Bool.pick(*).grep(Bool).elems, 2, 'Bool.pick works';
d5e42b6 @moritz tests for RT #76238, Bool.pick (and SomeEnum.pick)
moritz authored
101
102 enum A <b c d>;
0ced986 @colomon Add a couple of tests, unfudge for niecza.
colomon authored
103 is A.pick(*).grep(A).elems, 3, 'RandomEnum.pick works';
d5e42b6 @moritz tests for RT #76238, Bool.pick (and SomeEnum.pick)
moritz authored
104 }
105
b896f6d @moritz tests for Range.roll and .pick
moritz authored
106 # ranges + pick
92c0f96 @colomon Add more sanity tests for Range.pick and Range.roll. Unfudge tests w…
colomon authored
107 {
108 my %seen;
109 %seen{$_} = 1 for (1..100).pick(50);
110 is %seen.keys.elems, 50, 'Range.pick produces uniq elems';
111 ok (so 1 <= all(%seen.keys) <= 100), '... and all the elements are in range';
112 }
113
114 {
115 my %seen;
116 %seen{$_} = 1 for (1..300).pick(50);
117 is %seen.keys.elems, 50, 'Range.pick produces uniq elems';
118 ok (so 1 <= all(%seen.keys) <= 300), '... and all the elements are in range';
119 }
120
121 {
122 my %seen;
123 %seen{$_} = 1 for (1..50).pick(*);
124 is %seen.keys.elems, 50, 'Range.pick produces uniq elems';
125 ok (so 1 <= all(%seen.keys) <= 50), '... and all the elements are in range';
126 }
127
128 {
129 ok 1 <= (1..50).pick <= 50, 'Range.pick() works';
130 }
131
b896f6d @moritz tests for Range.roll and .pick
moritz authored
132 {
133 my %seen;
134 %seen{$_} = 1 for (1..1_000_000).pick(50);
135 is %seen.keys.elems, 50, 'Range.pick produces uniq elems';
136 ok (so 1 <= all(%seen.keys) <= 1_000_000), '... and all the elements are in range';
137 }
92c0f96 @colomon Add more sanity tests for Range.pick and Range.roll. Unfudge tests w…
colomon authored
138
b896f6d @moritz tests for Range.roll and .pick
moritz authored
139 {
140 my %seen;
141 %seen{$_} = 1 for (1^..1_000_000).pick(50);
142 is %seen.keys.elems, 50, 'Range.pick produces uniq elems (lower exclusive)';
143 ok (so 1 < all(%seen.keys) <= 1_000_000), '... and all the elements are in range';
144 }
92c0f96 @colomon Add more sanity tests for Range.pick and Range.roll. Unfudge tests w…
colomon authored
145
b896f6d @moritz tests for Range.roll and .pick
moritz authored
146 {
147 my %seen;
148 %seen{$_} = 1 for (1..^1_000_000).pick(50);
149 is %seen.keys.elems, 50, 'Range.pick produces uniq elems (upper exclusive)';
150 ok (so 1 <= all(%seen.keys) < 1_000_000), '... and all the elements are in range';
151 }
92c0f96 @colomon Add more sanity tests for Range.pick and Range.roll. Unfudge tests w…
colomon authored
152
b896f6d @moritz tests for Range.roll and .pick
moritz authored
153 {
154 my %seen;
155 %seen{$_} = 1 for (1^..^1_000_000).pick(50);
156 is %seen.keys.elems, 50, 'Range.pick produces uniq elems (both exclusive)';
157 ok (so 1 < all(%seen.keys) < 1_000_000), '... and all the elements are in range';
158 }
159
3ec12fb @moritz rakudofudge new tests
moritz authored
160 #?rakudo skip '.pick on huge integer ranges'
2d6c012 @colomon Add tests for roll and pick given a huge integer range.
colomon authored
161 {
162 my %seen;
163 %seen{$_} = 1 for (1 .. (10**1000) ).pick(50);
164 is %seen.keys.elems, 50, 'Range.pick produces uniq elems in huge range';
165 ok (so 1 <= all(%seen.keys) <= 10**1000), '... and all the elements are in range';
166 }
167
2fae5d6 @moritz more Range.{roll,pick} tests
moritz authored
168 is (1..^2).pick, 1, 'pick on 1-elem range';
169
30d3be9 @coke pugs fudge
coke authored
170 #?pugs todo
2fae5d6 @moritz more Range.{roll,pick} tests
moritz authored
171 ok ('a'..'z').pick ~~ /\w/, 'Range.pick on non-Int range';
172
dab2551 [t/spec] extended and corrected pick.t
moritz authored
173 # vim: ft=perl6
Something went wrong with that request. Please try again.