Skip to content
Newer
Older
100644 326 lines (271 sloc) 6.99 KB
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
1 use v6;
2 use Test;
7383aad @colomon Unfudge tests now working in niecza, add four more tests.
colomon authored
3 plan 140;
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
4
5 my $five = abs(-5);
6
7 unless ($five == 5) {
8 say "Bail out!";
9 say "Unreliable abs()";
10 exit();
11 }
12
13 # 2008-May-01 .nextwith tailcalls removed to help rakudo.
14 # Probably degrades error messages, so restore once rakudo does .nextwith.
15
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
16 #?DOES 1
998332a [spec] arith.t more fudging, not quite there yet
moritz authored
17 sub tryeq ($lhs, $rhs) {
3b0cda1 [gsoc_spectest] fudged arith.t for Rakudo
Auzon authored
18 ok($lhs == $rhs, "$lhs == $rhs");
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
19 }
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
20
21 #?DOES 1
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
22 sub tryeq_sloppy ($lhs, $rhs, $todo1 = '') {
23 my $todo = $todo1; # TODO is rw
24 $todo = ' # TODO ' ~ $todo if $todo;
25 if ($lhs == $rhs) {
26 if ($todo) {
27 #&ok.nextwith($lhs==$rhs,$todo, :todo);
28 ok($lhs==$rhs,$todo, :todo);
29 } else {
30 #&ok.nextwith($lhs==$rhs,$todo);
31 ok($lhs==$rhs,$todo);
32 }
33 } else {
3b0cda1 [gsoc_spectest] fudged arith.t for Rakudo
Auzon authored
34 my $error = abs($lhs - $rhs);
35 $error /= $lhs; # Syntax highlighting fix
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
36 if ($todo) {
37 #&ok.nextwith($error <1e-9,$todo ~ " # " ~ $lhs ~ " is close to " ~ $rhs, :todo);
207f13f [t] and [t/spec]
moritz authored
38 ok($error < 1e-9, $todo ~ " # " ~ $lhs ~ " is close to " ~ $rhs, :todo);
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
39 } else {
40 #&ok.nextwith($error <1e-9);
207f13f [t] and [t/spec]
moritz authored
41 ok($error < 1e-9);
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
42 }
43 }
44 }
45
46 # L<S03/Operator precedence>
47 tryeq 13 % 4, 1;
48 tryeq -13 % 4, 3;
49 tryeq 13 % -4, -3;
50 tryeq -13 % -4, -1;
51
7383aad @colomon Unfudge tests now working in niecza, add four more tests.
colomon authored
52 tryeq 13.0 % 4.0, 1;
53 tryeq -13.0 % 4.0, 3;
54 tryeq 13.0 % -4.0, -3;
55 tryeq -13.0 % -4.0, -1;
56
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
57 {
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
58 tryeq 5 % 2.5, 0;
59 tryeq 2.5 % 1, .5;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
60 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
61
62
63 my $limit = 1e6;
64
998332a [spec] arith.t more fudging, not quite there yet
moritz authored
65 ok abs( 13e21 % 4e21 - 1e21) < $limit;
66 ok abs(-13e21 % 4e21 - 3e21) < $limit;
67 ok abs( 13e21 % -4e21 - -3e21) < $limit;
68 ok abs(-13e21 % -4e21 - -1e21) < $limit;
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
69
70 # Hmm. Don t forget the simple stuff
71 tryeq 1 + 1, 2;
72 tryeq 4 + -2, 2;
73 tryeq -10 + 100, 90;
74 tryeq -7 + -9, -16;
75 tryeq -63 + +2, -61;
76 tryeq 4 + -1, 3;
77 tryeq -1 + 1, 0;
78 tryeq +29 + -29, 0;
79 tryeq -1 + 4, 3;
80 tryeq +4 + -17, -13;
81
82 # subtraction
83 tryeq 3 - 1, 2;
84 tryeq 3 - 15, -12;
85 tryeq 3 - -7, 10;
86 tryeq -156 - 5, -161;
87 tryeq -156 - -5, -151;
88 tryeq -5 - -12, 7;
89 tryeq -3 - -3, 0;
90 tryeq 15 - 15, 0;
91
92 tryeq 2147483647 - 0, 2147483647;
93 tryeq 0 - -2147483647, 2147483647;
3b0cda1 [gsoc_spectest] fudged arith.t for Rakudo
Auzon authored
94
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
95 # No warnings should appear;
2e97e92 @colomon Patch for niecza.
colomon authored
96 #?niecza skip "undefine NYI"
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
97 {
98 my $a;
99 $a += 1;
100 tryeq $a, 1;
101 undefine $a;
102 $a += -1;
103 tryeq $a, -1;
104 undefine $a;
105 $a += 4294967290;
106 tryeq $a, 4294967290;
107 undefine $a;
108 $a += -4294967290;
109 tryeq $a, -4294967290;
110 undefine $a;
111 $a += 4294967297;
112 tryeq $a, 4294967297;
113 undefine $a;
114 $a += -4294967297;
115 tryeq $a, -4294967297;
116 }
117
2e97e92 @colomon Patch for niecza.
colomon authored
118 #?niecza skip "undefine NYI"
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
119 {
120 my $s;
121 $s -= 1;
122 tryeq $s, -1;
123 undefine $s;
124 $s -= -1;
125 tryeq $s, +1;
126 undefine $s;
127 $s -= -4294967290;
128 tryeq $s, +4294967290;
129 undefine $s;
130 $s -= 4294967290;
131 tryeq $s, -4294967290;
132 undefine $s;
133 $s -= 4294967297;
134 tryeq $s, -4294967297;
135 undefine $s;
136 $s -= -4294967297;
137 tryeq $s, +4294967297;
138 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
139
140 # Multiplication
141
142 tryeq 1 * 3, 3;
143 tryeq -2 * 3, -6;
144 tryeq 3 * -3, -9;
145 tryeq -4 * -3, 12;
146
62c1178 [t/spec] Move tests that have 32-bit overflow issues from arith.t to …
colomon authored
147 {
3b0cda1 [gsoc_spectest] fudged arith.t for Rakudo
Auzon authored
148 # 2147483647 is prime. bah.
149
150 tryeq 46339 * 46341, 0x7ffea80f;
151 tryeq 46339 * -46341, -0x7ffea80f;
152 tryeq -46339 * 46341, -0x7ffea80f;
153 tryeq -46339 * -46341, 0x7ffea80f;
154 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
155
156 # leading space should be ignored
157
158 tryeq 1 + " 1", 2;
159 tryeq 3 + " -1", 2;
160 tryeq 1.2, " 1.2";
161 tryeq -1.2, " -1.2";
162
163 # divide
164
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…
moritz authored
165 tryeq 28 div 14, 2;
166 tryeq 28 div -7, -4;
167 tryeq -28 div 4, -7;
168 tryeq -28 div -2, 14;
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
169
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…
moritz authored
170 is(9 div 4, 2, "9 div 4 == 2");
674bf37 @moritz fudge arith.t for rakudo
moritz authored
171 #?rakudo 2 todo 'negative div'
1642bdd [t/spec] Additional tests for div, first tests for mod.
colomon authored
172 is(-9 div 4, -3, "-9 div 4 == -3");
173 is(9 div -4, -3, "9 div -4 == -3");
174 is(-9 div -4, 2, "-9 div -4 == 2");
175
176 # modulo
177
674bf37 @moritz fudge arith.t for rakudo
moritz authored
178 is 13 mod 4, 1, '13 mod 4';
179 #?rakudo 2 todo 'negative mod'
180 is -13 mod 4, 3, '-13 mod 4';
181 is 13 mod -4, -3, '13 mod -4';
182 is -13 mod -4, -1, '-13 mod -4';
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
183
184 tryeq 2.5 / 2, 1.25;
185 tryeq 3.5 / -2, -1.75;
186 tryeq -4.5 / 2, -2.25;
187 tryeq -5.5 / -2, 2.75;
188
189 # exponentiation
190
191 is 2**2, 4;
192 is 2.2**2, 4.84;
5ecd8f8 [t/spec] simplify and unfudge two arithmetic tests
moritz authored
193 is_approx 2**2.2, 4.59479341;
194 is_approx 2.2**2.2, 5.66669577;
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
195 is 1**0, 1;
196 is 1**1, 1;
0f670c5 [t/spec] Add test for ** right associative
bacek authored
197 isnt 2**3**4, 4096, "** is right associative";
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
198
612a8a8 [t/spec] a few small improvements
moritz authored
199 # test associativity
200 is 2 ** 2 ** 3, 256, 'infix:<**> is right associative';
201
207f13f [t] and [t/spec]
moritz authored
202 {
203 is_approx(-1, (0 + 1i)**2, "i^2 == -1");
7201d4d [t/spec] re-fudge arith.t for rakudo
moritz authored
204
207f13f [t] and [t/spec]
moritz authored
205 is_approx(-1, (0.7071067811865476 + -0.7071067811865475i)**4, "sqrt(-i)**4 ==-1" );
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…
moritz authored
206 is_approx(1i, (-1+0i)**0.5, '(-1+0i)**0.5 == i ');
207f13f [t] and [t/spec]
moritz authored
207 }
208
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
209 {
3a37e8f [t/spec] some corrections and fudges
moritz authored
210 # Inf
211 is Inf, Inf;
212 is -Inf, -Inf;
213 isnt Inf, -Inf;
214 is (-Inf).abs, Inf;
215 is Inf+100, Inf;
216 is Inf-100, Inf;
217 is Inf*100, Inf;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…
moritz authored
218 is Inf / 100, Inf;
3a37e8f [t/spec] some corrections and fudges
moritz authored
219 is Inf*-100, -Inf;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…
moritz authored
220 is Inf / -100, -Inf;
221 is 100 / Inf, 0;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
222 is Inf**100, Inf;
223 is Inf*0, NaN;
0b3dad3 [t/spec] some disambiguationg whitespaces
moritz authored
224 is Inf - Inf, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
225 is Inf*Inf, Inf;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…
moritz authored
226 is Inf / Inf, NaN;
227 is Inf*Inf / Inf, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
228 is Inf**0, 1;
229 is 0**0, 1;
230 is 0**Inf, 0;
231
232 my $inf1 = 100**Inf;
233 is $inf1, Inf, "100**Inf";
234 my $inf2 = Inf**Inf;
235 is $inf2, Inf, "Inf**Inf";
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
236
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
237 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
238 # See L<"http://mathworld.wolfram.com/Indeterminate.html">
239 # for why these three values are defined like they are.
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
240 {
241 is 0.9**Inf, 0, "0.9**Inf converges towards 0";
242 is 1.1**Inf, Inf, "1.1**Inf diverges towards Inf";
2e97e92 @colomon Patch for niecza.
colomon authored
243 #?niecza todo "No agreement over correct behavior here -- above web page not helpful!"
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
244 is 1**Inf, 1;
245 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
246
b6e5936 [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
247 ##?pugs todo
248 #flunk("1**Inf is platform-specific -- it's 1 on OSX and NaN elsewhere");
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
249
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
250 {
251 # NaN
252 is NaN, NaN;
253 is -NaN, NaN;
254 is NaN+100, NaN;
255 is NaN-100, NaN;
256 is NaN*100, NaN;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…
moritz authored
257 is NaN / 100, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
258 is NaN**100, NaN;
259 is NaN+NaN, NaN;
0b3dad3 [t/spec] some disambiguationg whitespaces
moritz authored
260 is NaN - NaN, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
261 is NaN*NaN, NaN;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…
moritz authored
262 is NaN / NaN, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
263
264 is NaN+Inf, NaN;
0b3dad3 [t/spec] some disambiguationg whitespaces
moritz authored
265 is NaN - Inf, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
266 is NaN*Inf, NaN;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…
moritz authored
267 is NaN / Inf, NaN;
268 is Inf / NaN, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run …
moritz authored
269
270 my $nan1 = NaN**NaN;
271 is $nan1, NaN, "NaN**NaN";
272 my $nan2 = NaN**Inf;
273 is $nan2, NaN, "NaN**Inf";
274 my $nan3 = Inf**NaN;
275 is $nan3, NaN, "Inf**NaN";
276 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
277
278 =begin pod
279
280 =head2 BEHAVIOUR OF DIVISION AND MODULUS WITH ZERO
281
282 This test tests the behaviour of '%' and '/' when used with
283 a zero modulus resp. divisor.
284
285 All uses of a zero modulus or divisor should 'die', and the
286 'die' should be non-fatal.
287
288 =end pod
289
290 my $x;
291
a09e6cc [t/spec] Refudge a tad for ng.
colomon authored
292 #?rakudo 2 todo 'modulo by zero'
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
293 dies_ok( { say 3 % 0 }, 'Modulo zero dies and is catchable');
294 dies_ok( { $x = 0; say 3 % $x; }, 'Modulo zero dies and is catchable with VInt/VRat variables');
0c16733 [t/spec] some rakudo unfudges
moritz authored
295 #?rakudo todo 'die or fail?'
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
296 dies_ok( { $x := 0; say 3 % $x; }, 'Modulo zero dies and is catchable with VRef variables');
297
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy…
moritz authored
298 dies_ok( { say 3 div 0 }, 'Division by zero dies and is catchable');
299 dies_ok( { $x = 0; say 3 div $x; }, 'Division by zero dies and is catchable with VInt div VRat variables');
300 dies_ok( { $x := 0; say 3 div $x; }, 'Division by zero dies and is catchable with VRef variables');
78c96ad [t/spec] added two bigint tests, slavik++
moritz authored
301
302 # This is a rakudo regression wrt bignum:
303 {
987ade2 @jnthn Unfudge some bigint tests; remove a stray say.
jnthn authored
304 my $f = 1; $f *= $_ for 2..25;
78c96ad [t/spec] added two bigint tests, slavik++
moritz authored
305 ok $f == 15511210043330985984000000,
306 'Can calcualte 25! without loss of precision';
307 ok 2**65 == 36893488147419103232,
308 'Can calcualte 2**65 without loss of precision';
309 }
310
8aaa346 [t/spec] test that Rat literals are gone, RT #73264
moritz authored
311 # RT #73264
312 # Rat literals are gone
313 {
314 ok 1/7 / 1/7 == 1/49, 'no more Rat literals, infix:</> has normal left assoc';
315 }
316
3e93462 added tests for RT #73386
Jimmy Zhuo authored
317 # RT #73386
318 eval_dies_ok '3 !+ 4', 'infix:<+> is not iffy enough';
319
fc78e0f @masak added test for #100768
masak authored
320 # RT #100768
321 eval_lives_ok '-Inf', '-Inf warns (and yields 0) but does not give an error';
322
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
323 done;
72c5e19 [t/spec] Test for RT 69172
kyle authored
324
78c96ad [t/spec] added two bigint tests, slavik++
moritz authored
325 # vim: ft=perl6
Something went wrong with that request. Please try again.