Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 232 lines (196 sloc) 7.598 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
9b6c25af »
2010-06-08 [t/spec] Add simple tests for [div] and [mod].
4 plan 88;
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 {
43 ok ( [<] 1, 2, 3, 4), "[<] works (1)";
44 ok (not [<] 1, 3, 2, 4), "[<] works (2)";
45 ok ( [>] 4, 3, 2, 1), "[>] works (1)";
46 ok (not [>] 4, 2, 3, 1), "[>] works (2)";
47 ok ( [==] 4, 4, 4), "[==] works (1)";
48 ok (not [==] 4, 5, 4), "[==] works (2)";
49 ok ( [!=] 4, 5, 6), "[!=] works (1)";
50 ok (not [!=] 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
77 ok ( [===] 1, 1, 1, 1), '[===] with literals';
78 ok ( [===] $a, $a, $a), '[===] with vars (positive)';
79 ok (not [===] $a, $a, [1, 2]), '[===] with vars (negative)';
80 ok ( [!===] $a, $b, $a), '[!===] basic sanity (positive)';
81 ok (not [!===] $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 {
5cb1e9f9 »
2009-02-18 [t/spec] Fix triangle form of reduce metaop tests.
85 is (~ [\<] 1, 2, 3, 4), "1 1 1 1", "[\\<] works (1)";
2126a8db »
2009-02-21 [t/spec] Revert previous commit for reduce metaops.
86 is (~ [\<] 1, 3, 2, 4), "1 1 0 0", "[\\<] works (2)";
5cb1e9f9 »
2009-02-18 [t/spec] Fix triangle form of reduce metaop tests.
87 is (~ [\>] 4, 3, 2, 1), "1 1 1 1", "[\\>] works (1)";
6ac9615a »
2009-02-26 [t/spec] Update reduce-metaop to current spec.
88 is (~ [\>] 4, 2, 3, 1), "1 1 0 0", "[\\>] works (2)";
5cb1e9f9 »
2009-02-18 [t/spec] Fix triangle form of reduce metaop tests.
89 is (~ [\==] 4, 4, 4), "1 1 1", "[\\==] works (1)";
90 is (~ [\==] 4, 5, 4), "1 0 0", "[\\==] works (2)";
6ac9615a »
2009-02-26 [t/spec] Update reduce-metaop to current spec.
91 is (~ [\!=] 4, 5, 6), "1 1 1", "[\\!=] works (1)";
92 is (~ [\!=] 4, 5, 5), "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
bc058f28 »
2008-07-24 [STD] improve parsing of reduceops
114 # not currently legal without an infix subscript operator
115 # {
116 # my $hash = {a => {b => {c => {d => 42, e => 23}}}};
117 # is try { [.{}] $hash, <a b c d> }, 42, '[.{}] works';
118 # }
119 #
120 # {
121 # my $hash = {a => {b => 42}};
122 # is ([.{}] $hash, <a b>), 42, '[.{}] works two levels deep';
123 # }
124 #
125 # {
126 # my $arr = [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]];
127 # is ([.[]] $arr, 1, 0, 2), 9, '[.[]] works';
128 # }
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
129
130 {
131 # 18:45 < autrijus> hm, I found a way to easily do linked list consing in Perl6
132 # 18:45 < autrijus> [=>] 1..10;
133 my $list = [=>] 1,2,3;
ed682732 »
2008-08-21 [t/spec] remove usage of try as a function
134 is $list.key, 1, "[=>] works (1)";
135 is (try {$list.value.key}), 2, "[=>] works (2)";
136 is (try {$list.value.value}), 3, "[=>] works (3)";
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
137 }
138
139 {
21768a77 »
2008-12-08 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
140 my @array = <5 -3 7 0 1 -9>;
141 # according to http://irclog.perlgeek.de/perl6/2008-09-10#i_560910
142 # [,] returns a scalar (holding an Array)
143 my $count = 0;
144 $count++ for [,] @array;
145 is $count, 1, '[,] returns a single Array';
a246cb9a »
2010-04-03 [t/spec] correct a test for [,], and unfudge a few for rakudo
146 ok ([,] @array) ~~ Positional, '[,] returns something Positional';
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
147 }
148
149 # Following two tests taken verbatim from former t/operators/reduce.t
150 lives_ok({my @foo = [1..3] >>+<< [1..3] >>+<< [1..3]},'Sanity Check');
151 lives_ok({my @foo = [>>+<<] ([1..3],[1..3],[1..3])},'Parse [>>+<<]');
152
153 # Check that user defined infix ops work with [...], too.
21768a77 »
2008-12-08 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
154 #?pugs todo 'bug'
8de8af6c »
2010-04-02 [t/spec] partially fudge reduce.t for rakudo
155 #?rakudo skip 'reduce of user defined op'
21768a77 »
2008-12-08 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
156 {
157 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
158 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.
159 }
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
160
f1483360 »
2008-08-07 [STD vs t] user-defined prefix, infix, and postfix ops now derive new…
161 # {
162 # my $arr = [ 42, [ 23 ] ];
163 # $arr[1][1] = $arr;
164 #
165 # is try { [.[]] $arr, 1, 1, 1, 1, 1, 0 }, 23, '[.[]] works with infinite data structures';
166 # }
167 #
168 # {
169 # my $hash = {a => {b => 42}};
170 # $hash<a><c> = $hash;
171 #
172 # is try { [.{}] $hash, <a c a c a b> }, 42, '[.{}] works with infinite data structures';
173 # }
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
174
175 # L<S03/"Reduction operators"/"Among the builtin operators, [+]() returns 0 and [*]() returns 1">
176
21768a77 »
2008-12-08 [t/spec] clean up and fudge reduce-metaop.t for rakudo.
177 is( ([*]()), 1, "[*]() returns 1");
178 is( ([+]()), 0, "[+]() returns 0");
932a1bc6 »
2008-07-06 [gsoc_spectest] reorganization of reduce tests
179
2d7d862d »
2010-04-03 [t/spec] Add a few tests for the one-argument case.
180 is( ([*] 41), 41, "[*] 41 returns 41");
181 is( ([*] 42), 42, "[*] 42 returns 42");
0e61dff5 »
2010-04-03 [t/spec] Add a few more tests for the one-argument case.
182 is( ~([\*] 42), "42", "[\*] 42 returns (42)");
2d7d862d »
2010-04-03 [t/spec] Add a few tests for the one-argument case.
183 is( ([~] 'towel'), 'towel', "[~] 'towel' returns 'towel'");
184 is( ([~] 'washcloth'), 'washcloth', "[~] 'washcloth' returns 'washcloth'");
0e61dff5 »
2010-04-03 [t/spec] Add a few more tests for the one-argument case.
185 is( ([\~] 'towel'), 'towel', "[\~] 'towel' returns 'towel'");
f9ed5f42 »
2010-04-05 [reduce.t] fix parsefail
186 ok( ([\~] 'towel') ~~ Iterable, "[\~] 'towel' returns something Iterable");
2d7d862d »
2010-04-03 [t/spec] Add a few tests for the one-argument case.
187 is( ([<] 42), Bool::True, "[<] 42 returns true");
0e61dff5 »
2010-04-03 [t/spec] Add a few more tests for the one-argument case.
188 is( ~([\<] 42), "1", "[\<] 42 returns '1'");
189 ok( ([\<] 42) ~~ Iterable, "[\<] 42 returns something Iterable");
2d7d862d »
2010-04-03 [t/spec] Add a few tests for the one-argument case.
190
09a80e64 »
2010-04-03 [t/spec] Add two tests for lazy triangle reduce.
191 is( ([\*] 1..*).batch(10).join(', '), '1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800',
192 'triangle reduce is lazy');
193 is( ([\R~] 'a'..*).batch(8).join(', '), 'a, ba, cba, dcba, edcba, fedcba, gfedcba, hgfedcba',
194 'triangle reduce is lazy');
195
f80ef638 »
2009-08-16 [t/spec] Tests for RT #65164
196 # RT #65164 (TODO: implement [^^])
197 #?rakudo skip 'implement [^^]'
198 {
199 is [^^](0, 42), 42, '[^^] works (one of two true)';
200 is [^^](42, 0), 42, '[^^] works (one of two true)';
201 ok ! [^^](1, 42), '[^^] works (two true)';
202 ok ! [^^](0, 0), '[^^] works (two false)';
203
204 ok ! [^^](0, 0, 0), '[^^] works (three false)';
205 ok ! [^^](5, 9, 17), '[^^] works (three true)';
206
207 is [^^](5, 9, 0), (5 ^^ 9 ^^ 0), '[^^] mix 1';
208 is [^^](5, 0, 17), (5 ^^ 0 ^^ 17), '[^^] mix 2';
209 is [^^](0, 9, 17), (0 ^^ 9 ^^ 17), '[^^] mix 3';
210 is [^^](5, 0, 0), (5 ^^ 0 ^^ 0), '[^^] mix 4';
211 is [^^](0, 9, 0), (0 ^^ 9 ^^ 0), '[^^] mix 5';
212 is [^^](0, 0, 17), (0 ^^ 0 ^^ 17), '[^^] mix 6';
213 }
214
65d1a8d8 »
2010-05-24 [t/spec] tests for RT #75234, using a metaop in one class hides it fr…
215 # RT #75234
216 # rakudo had a problem where once-used meta operators weren't installed
217 # in a sufficiently global location, so using a meta operator in class once
218 # makes it unusable further on
219 {
220 class A {
221 method m { return [~] gather for ^3 {take 'a'} }
222 }
223 class B {
224 method n { return [~] gather for ^4 {take 'b'}}
225 }
226 is A.new.m, 'aaa', '[~] works in first class';
227 is B.new.n, 'bbbb', '[~] works in second class';
228 is ([~] 1, 2, 5), '125', '[~] works outside class';
229 }
230
4acefb9e »
2009-07-25 [t/spec] unfudge [//] and [||] tests for rakudo
231 # vim: ft=perl6
Something went wrong with that request. Please try again.