Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 246 lines (208 sloc) 8.018 kb
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
1 use v6;
2 use Test;
e1221121 »
2009-02-04 [t/spec] fix reduce-metaop.t, moritz--
3
c5240b2d »
2011-01-13 [reduce] Test for RT 82210: Misparse of metaop with immediate ()
4 plan 93;
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
5
6 =begin pod
7
8 =head1 DESCRIPTION
9
10 This test tests the C<[...]> reduce metaoperator.
11
12 Reference:
13 L<"http://groups.google.de/group/perl.perl6.language/msg/bd9eb275d5da2eda">
14
15 =end pod
16
17 # L<S03/"Reduction operators">
18
19 # [...] reduce metaoperator
20 {
21 my @array = <5 -3 7 0 1 -9>;
22 my $sum = 5 + -3 + 7 + 0 + 1 + -9; # laziness :)
23
24 is(([+] @array), $sum, "[+] works");
25 is(([*] 1,2,3), (1*2*3), "[*] works");
26 is(([-] 1,2,3), (1-2-3), "[-] works");
27 is(([/] 12,4,3), (12/4/3), "[/] works");
9b6c25af »
2010-06-08 [t/spec] Add simple tests for [div] and [mod].
28 is(([div] 12,4,3), (12 div 4 div 3), "[div] works");
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
29 is(([**] 2,2,3), (2**2**3), "[**] works");
5d1999ee »
2008-12-08 [t/spec] a test for [%] (meta reduce modulo)
30 is(([%] 13,7,4), (13%7%4), "[%] works");
9b6c25af »
2010-06-08 [t/spec] Add simple tests for [div] and [mod].
31 is(([mod] 13,7,4), (13 mod 7 mod 4), "[mod] works");
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
32
33 is((~ [\+] @array), "5 2 9 9 10 1", "[\\+] works");
34 is((~ [\-] 1, 2, 3), "1 -1 -4", "[\\-] works");
35 }
36
37 {
38 is ([~] <a b c d>), "abcd", "[~] works";
39 is (~ [\~] <a b c d>), "a ab abc abcd", "[\\~] works";
40 }
41
42 {
ea847c7f »
2010-09-22 remove more wrong uses of True and False as 0 and 1 (still more left)…
43 ok ([<] 1, 2, 3, 4), "[<] works (1)";
44 nok ([<] 1, 3, 2, 4), "[<] works (2)";
45 ok ([>] 4, 3, 2, 1), "[>] works (1)";
46 nok ([>] 4, 2, 3, 1), "[>] works (2)";
47 ok ([==] 4, 4, 4), "[==] works (1)";
48 nok ([==] 4, 5, 4), "[==] works (2)";
49 ok ([!=] 4, 5, 6), "[!=] works (1)";
50 nok ([!=] 4, 4, 4), "[!=] works (2)";
e7dbb23d »
2010-04-03 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
51 }
d1ccd8b2 »
2008-12-09 [t/spec] tests for === and =:= and their negated forms inside meta ops
52
e7dbb23d »
2010-04-03 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
53 {
e75736f9 »
2008-12-09 [t/spec] tests for [eq], [ne]
54 ok (! [eq] <a a b a>), '[eq] basic sanity (positive)';
55 ok ( [eq] <a a a a>), '[eq] basic sanity (negative)';
56 ok ( [ne] <a b c a>), '[ne] basic sanity (positive)';
57 ok (! [ne] <a a b c>), '[ne] basic sanity (negative)';
58 ok ( [lt] <a b c e>), '[lt] basic sanity (positive)';
59 ok (! [lt] <a a c e>), '[lt] basic sanity (negative)';
e7dbb23d »
2010-04-03 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
60 }
e75736f9 »
2008-12-09 [t/spec] tests for [eq], [ne]
61
e7dbb23d »
2010-04-03 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
62 #?rakudo skip "=:= NYI"
63 {
d1ccd8b2 »
2008-12-09 [t/spec] tests for === and =:= and their negated forms inside meta ops
64 my ($x, $y);
65 ok ( [=:=] $x, $x, $x), '[=:=] basic sanity 1';
66 ok (not [=:=] $x, $y, $x), '[=:=] basic sanity 2';
67 ok ( [!=:=] $x, $y, $x), '[!=:=] basic sanity (positive)';
68 ok (not [!=:=] $y, $y, $x), '[!=:=] basic sanity (negative)';
69 $y := $x;
70 ok ( [=:=] $y, $x, $y), '[=:=] after binding';
e7dbb23d »
2010-04-03 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
71 }
d1ccd8b2 »
2008-12-09 [t/spec] tests for === and =:= and their negated forms inside meta ops
72
e7dbb23d »
2010-04-03 [t/spec] Refudge S03-metaops/reduce.t a bit so that it works again.
73 {
d1ccd8b2 »
2008-12-09 [t/spec] tests for === and =:= and their negated forms inside meta ops
74 my $a = [1, 2];
75 my $b = [1, 2];
76
ea847c7f »
2010-09-22 remove more wrong uses of True and False as 0 and 1 (still more left)…
77 ok ([===] 1, 1, 1, 1), '[===] with literals';
78 ok ([===] $a, $a, $a), '[===] with vars (positive)';
79 nok ([===] $a, $a, [1, 2]), '[===] with vars (negative)';
80 ok ([!===] $a, $b, $a), '[!===] basic sanity (positive)';
81 nok ([!===] $a, $b, $b), '[!===] basic sanity (negative)';
434eb4ef »
2008-12-09 [t/spec] Unfudge tests for reduction meta-operator with chaining comp…
82 }
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
83
434eb4ef »
2008-12-09 [t/spec] Unfudge tests for reduction meta-operator with chaining comp…
84 {
29b04a98 »
2010-09-23 fix tests for Bool stringification
85 is ~ ([\<] 1, 2, 3, 4).map({+$_}), "1 1 1 1", "[\\<] works (1)";
86 is ~ ([\<] 1, 3, 2, 4).map({+$_}), "1 1 0 0", "[\\<] works (2)";
87 is ~ ([\>] 4, 3, 2, 1).map({+$_}), "1 1 1 1", "[\\>] works (1)";
88 is ~ ([\>] 4, 2, 3, 1).map({+$_}), "1 1 0 0", "[\\>] works (2)";
89 is ~ ([\==] 4, 4, 4).map({+$_}), "1 1 1", "[\\==] works (1)";
90 is ~ ([\==] 4, 5, 4).map({+$_}), "1 0 0", "[\\==] works (2)";
91 is ~ ([\!=] 4, 5, 6).map({+$_}), "1 1 1", "[\\!=] works (1)";
92 is ~ ([\!=] 4, 5, 5).map({+$_}), "1 1 0", "[\\!=] works (2)";
5cb1e9f9 »
2009-02-18 [t/spec] Fix triangle form of reduce metaop tests.
93 is (~ [\**] 1, 2, 3), "3 8 1", "[\\**] (right assoc) works (1)";
94 is (~ [\**] 3, 2, 0), "0 1 3", "[\\**] (right assoc) works (2)";
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
95 }
96
97 {
8f9a1198 »
2009-11-25 [t/] unify compartmentalized undef and Object concepts into Mu
98 my @array = (Mu, Mu, 3, Mu, 5);
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
99 is ([//] @array), 3, "[//] works";
4acefb9e »
2009-07-25 [t/spec] unfudge [//] and [||] tests for rakudo
100 #?rakudo skip '[orelse]'
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
101 is ([orelse] @array), 3, "[orelse] works";
102 }
103
104 {
8f9a1198 »
2009-11-25 [t/] unify compartmentalized undef and Object concepts into Mu
105 my @array = (Mu, Mu, 0, 3, Mu, 5);
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
106 is ([||] @array), 3, "[||] works";
107 is ([or] @array), 3, "[or] works";
108
8f9a1198 »
2009-11-25 [t/] unify compartmentalized undef and Object concepts into Mu
109 # Mu as well as [//] should work too, but testing it like
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
110 # this would presumably emit warnings when we have them.
111 is (~ [\||] 0, 0, 3, 4, 5), "0 0 3 3 3", "[\\||] works";
112 }
113
fc7413f7 »
2010-06-29 [t/spec] Tests for [&&] and [and]. Patch courtesy of (Alex Kapranoff)++.
114 {
115 my @array = (Mu, Mu, 0, 3, Mu, 5);
116 my @array1 = (2, 3, 4);
117 nok ([&&] @array), "[&&] works with 1 false";
118 is ([&&] @array1), 4, "[&&] works";
119 nok ([and] @array), "[and] works with 1 false";
120 is ([and] @array1), 4, "[and] works";
121 }
122
bc058f28 »
2008-07-24 [STD] improve parsing of reduceops
123 # not currently legal without an infix subscript operator
124 # {
125 # my $hash = {a => {b => {c => {d => 42, e => 23}}}};
126 # is try { [.{}] $hash, <a b c d> }, 42, '[.{}] works';
127 # }
128 #
129 # {
130 # my $hash = {a => {b => 42}};
131 # is ([.{}] $hash, <a b>), 42, '[.{}] works two levels deep';
132 # }
133 #
134 # {
135 # my $arr = [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]];
136 # is ([.[]] $arr, 1, 0, 2), 9, '[.[]] works';
137 # }
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
138
139 {
140 # 18:45 < autrijus> hm, I found a way to easily do linked list consing in Perl6
141 # 18:45 < autrijus> [=>] 1..10;
142 my $list = [=>] 1,2,3;
ed682732 »
2008-08-21 [t/spec] remove usage of try as a function
143 is $list.key, 1, "[=>] works (1)";
144 is (try {$list.value.key}), 2, "[=>] works (2)";
145 is (try {$list.value.value}), 3, "[=>] works (3)";
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
146 }
147
148 {
21768a77 »
2008-12-08 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
149 my @array = <5 -3 7 0 1 -9>;
150 # according to http://irclog.perlgeek.de/perl6/2008-09-10#i_560910
151 # [,] returns a scalar (holding an Array)
152 my $count = 0;
153 $count++ for [,] @array;
154 is $count, 1, '[,] returns a single Array';
a246cb9a »
2010-04-03 [t/spec] correct a test for [,], and unfudge a few for rakudo
155 ok ([,] @array) ~~ Positional, '[,] returns something Positional';
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
156 }
157
158 # Following two tests taken verbatim from former t/operators/reduce.t
159 lives_ok({my @foo = [1..3] >>+<< [1..3] >>+<< [1..3]},'Sanity Check');
160 lives_ok({my @foo = [>>+<<] ([1..3],[1..3],[1..3])},'Parse [>>+<<]');
161
162 # Check that user defined infix ops work with [...], too.
21768a77 »
2008-12-08 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
163 #?pugs todo 'bug'
8de8af6c »
2010-04-02 [t/spec] partially fudge reduce.t for rakudo
164 #?rakudo skip 'reduce of user defined op'
21768a77 »
2008-12-08 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
165 {
166 sub infix:<more_than_plus>(Int $a, Int $b) { $a + $b + 1 }
d1ccd8b2 »
2008-12-09 [t/spec] tests for === and =:= and their negated forms inside meta ops
167 is (try { [more_than_plus] 1, 2, 3 }), 8, "[...] reduce metaop works on user defined ops";
21768a77 »
2008-12-08 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
168 }
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
169
f1483360 »
2008-08-07 [STD vs t] user-defined prefix, infix, and postfix ops now derive new…
170 # {
171 # my $arr = [ 42, [ 23 ] ];
172 # $arr[1][1] = $arr;
173 #
174 # is try { [.[]] $arr, 1, 1, 1, 1, 1, 0 }, 23, '[.[]] works with infinite data structures';
175 # }
176 #
177 # {
178 # my $hash = {a => {b => 42}};
179 # $hash<a><c> = $hash;
180 #
181 # is try { [.{}] $hash, <a c a c a b> }, 42, '[.{}] works with infinite data structures';
182 # }
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
183
184 # L<S03/"Reduction operators"/"Among the builtin operators, [+]() returns 0 and [*]() returns 1">
185
21768a77 »
2008-12-08 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
186 is( ([*]()), 1, "[*]() returns 1");
187 is( ([+]()), 0, "[+]() returns 0");
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
188
2d7d862d »
2010-04-03 [t/spec] Add a few tests for the one-argument case.
189 is( ([*] 41), 41, "[*] 41 returns 41");
190 is( ([*] 42), 42, "[*] 42 returns 42");
0e61dff5 »
2010-04-03 [t/spec] Add a few more tests for the one-argument case.
191 is( ~([\*] 42), "42", "[\*] 42 returns (42)");
2d7d862d »
2010-04-03 [t/spec] Add a few tests for the one-argument case.
192 is( ([~] 'towel'), 'towel', "[~] 'towel' returns 'towel'");
193 is( ([~] 'washcloth'), 'washcloth', "[~] 'washcloth' returns 'washcloth'");
0e61dff5 »
2010-04-03 [t/spec] Add a few more tests for the one-argument case.
194 is( ([\~] 'towel'), 'towel', "[\~] 'towel' returns 'towel'");
f9ed5f42 »
2010-04-05 [reduce.t] fix parsefail
195 ok( ([\~] 'towel') ~~ Iterable, "[\~] 'towel' returns something Iterable");
2d7d862d »
2010-04-03 [t/spec] Add a few tests for the one-argument case.
196 is( ([<] 42), Bool::True, "[<] 42 returns true");
ea847c7f »
2010-09-22 remove more wrong uses of True and False as 0 and 1 (still more left)…
197 is( ~([\<] 42), ~True, "[\<] 42 returns '1'");
0e61dff5 »
2010-04-03 [t/spec] Add a few more tests for the one-argument case.
198 ok( ([\<] 42) ~~ Iterable, "[\<] 42 returns something Iterable");
2d7d862d »
2010-04-03 [t/spec] Add a few tests for the one-argument case.
199
9e9686f7 »
2010-06-15 [t/spec] replace .batch($x) with .[^$x]
200 is( ([\*] 1..*).[^10].join(', '), '1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800',
09a80e64 »
2010-04-03 [t/spec] Add two tests for lazy triangle reduce.
201 'triangle reduce is lazy');
9e9686f7 »
2010-06-15 [t/spec] replace .batch($x) with .[^$x]
202 is( ([\R~] 'a'..*).[^8].join(', '), 'a, ba, cba, dcba, edcba, fedcba, gfedcba, hgfedcba',
09a80e64 »
2010-04-03 [t/spec] Add two tests for lazy triangle reduce.
203 'triangle reduce is lazy');
204
f80ef638 »
2009-08-16 [t/spec] Tests for RT #65164
205 # RT #65164 (TODO: implement [^^])
206 #?rakudo skip 'implement [^^]'
207 {
208 is [^^](0, 42), 42, '[^^] works (one of two true)';
209 is [^^](42, 0), 42, '[^^] works (one of two true)';
210 ok ! [^^](1, 42), '[^^] works (two true)';
211 ok ! [^^](0, 0), '[^^] works (two false)';
212
213 ok ! [^^](0, 0, 0), '[^^] works (three false)';
214 ok ! [^^](5, 9, 17), '[^^] works (three true)';
215
216 is [^^](5, 9, 0), (5 ^^ 9 ^^ 0), '[^^] mix 1';
217 is [^^](5, 0, 17), (5 ^^ 0 ^^ 17), '[^^] mix 2';
218 is [^^](0, 9, 17), (0 ^^ 9 ^^ 17), '[^^] mix 3';
219 is [^^](5, 0, 0), (5 ^^ 0 ^^ 0), '[^^] mix 4';
220 is [^^](0, 9, 0), (0 ^^ 9 ^^ 0), '[^^] mix 5';
221 is [^^](0, 0, 17), (0 ^^ 0 ^^ 17), '[^^] mix 6';
222 }
223
65d1a8d8 »
2010-05-24 [t/spec] tests for RT #75234, using a metaop in one class hides it fr…
224 # RT #75234
225 # rakudo had a problem where once-used meta operators weren't installed
226 # in a sufficiently global location, so using a meta operator in class once
227 # makes it unusable further on
228 {
229 class A {
230 method m { return [~] gather for ^3 {take 'a'} }
231 }
232 class B {
233 method n { return [~] gather for ^4 {take 'b'}}
234 }
235 is A.new.m, 'aaa', '[~] works in first class';
236 is B.new.n, 'bbbb', '[~] works in second class';
237 is ([~] 1, 2, 5), '125', '[~] works outside class';
238 }
239
c5240b2d »
2011-01-13 [reduce] Test for RT 82210: Misparse of metaop with immediate ()
240 #?rakudo todo 'RT 82210'
241 ok [+](1..10) + 0 == ([+] 1..10) + 0,
242 'a listop with immediate () is a function call (RT 82210)';
243
e76dd4c7 »
2010-12-31 s/done_testing/done/ as per recent S24 changes
244 done;
4acefb9e »
2009-07-25 [t/spec] unfudge [//] and [||] tests for rakudo
245 # vim: ft=perl6
Something went wrong with that request. Please try again.