Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 314 lines (261 sloc) 6.783 kb
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
1 use v6;
2 use Test;
643bc98 replace plan *; with number of tests S03
mberends authored
3 plan 135;
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 tim...
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 tim...
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
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
52 {
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
53 tryeq 5 % 2.5, 0;
54 tryeq 2.5 % 1, .5;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
55 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
56
57
58 my $limit = 1e6;
59
998332a [spec] arith.t more fudging, not quite there yet
moritz authored
60 ok abs( 13e21 % 4e21 - 1e21) < $limit;
61 ok abs(-13e21 % 4e21 - 3e21) < $limit;
62 ok abs( 13e21 % -4e21 - -3e21) < $limit;
63 ok abs(-13e21 % -4e21 - -1e21) < $limit;
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
64
65 # Hmm. Don t forget the simple stuff
66 tryeq 1 + 1, 2;
67 tryeq 4 + -2, 2;
68 tryeq -10 + 100, 90;
69 tryeq -7 + -9, -16;
70 tryeq -63 + +2, -61;
71 tryeq 4 + -1, 3;
72 tryeq -1 + 1, 0;
73 tryeq +29 + -29, 0;
74 tryeq -1 + 4, 3;
75 tryeq +4 + -17, -13;
76
77 # subtraction
78 tryeq 3 - 1, 2;
79 tryeq 3 - 15, -12;
80 tryeq 3 - -7, 10;
81 tryeq -156 - 5, -161;
82 tryeq -156 - -5, -151;
83 tryeq -5 - -12, 7;
84 tryeq -3 - -3, 0;
85 tryeq 15 - 15, 0;
86
87 tryeq 2147483647 - 0, 2147483647;
88 tryeq 0 - -2147483647, 2147483647;
3b0cda1 [gsoc_spectest] fudged arith.t for Rakudo
Auzon authored
89
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
90 # No warnings should appear;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
91 {
92 my $a;
93 $a += 1;
94 tryeq $a, 1;
95 undefine $a;
96 $a += -1;
97 tryeq $a, -1;
98 undefine $a;
99 $a += 4294967290;
100 tryeq $a, 4294967290;
101 undefine $a;
102 $a += -4294967290;
103 tryeq $a, -4294967290;
104 undefine $a;
105 $a += 4294967297;
106 tryeq $a, 4294967297;
107 undefine $a;
108 $a += -4294967297;
109 tryeq $a, -4294967297;
110 }
111
112 {
113 my $s;
114 $s -= 1;
115 tryeq $s, -1;
116 undefine $s;
117 $s -= -1;
118 tryeq $s, +1;
119 undefine $s;
120 $s -= -4294967290;
121 tryeq $s, +4294967290;
122 undefine $s;
123 $s -= 4294967290;
124 tryeq $s, -4294967290;
125 undefine $s;
126 $s -= 4294967297;
127 tryeq $s, -4294967297;
128 undefine $s;
129 $s -= -4294967297;
130 tryeq $s, +4294967297;
131 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
132
133 # Multiplication
134
135 tryeq 1 * 3, 3;
136 tryeq -2 * 3, -6;
137 tryeq 3 * -3, -9;
138 tryeq -4 * -3, 12;
139
62c1178 [t/spec] Move tests that have 32-bit overflow issues from arith.t to ove...
colomon authored
140 {
3b0cda1 [gsoc_spectest] fudged arith.t for Rakudo
Auzon authored
141 # 2147483647 is prime. bah.
142
143 tryeq 46339 * 46341, 0x7ffea80f;
144 tryeq 46339 * -46341, -0x7ffea80f;
145 tryeq -46339 * 46341, -0x7ffea80f;
146 tryeq -46339 * -46341, 0x7ffea80f;
147 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
148
149 # leading space should be ignored
150
151 tryeq 1 + " 1", 2;
152 tryeq 3 + " -1", 2;
153 tryeq 1.2, " 1.2";
154 tryeq -1.2, " -1.2";
155
156 # divide
157
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy (m...
moritz authored
158 tryeq 28 div 14, 2;
159 tryeq 28 div -7, -4;
160 tryeq -28 div 4, -7;
161 tryeq -28 div -2, 14;
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
162
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy (m...
moritz authored
163 is(9 div 4, 2, "9 div 4 == 2");
1642bdd [t/spec] Additional tests for div, first tests for mod.
colomon authored
164 is(-9 div 4, -3, "-9 div 4 == -3");
165 is(9 div -4, -3, "9 div -4 == -3");
166 is(-9 div -4, 2, "-9 div -4 == 2");
167
168 # modulo
169
170 tryeq 13 mod 4, 1;
171 tryeq -13 mod 4, 3;
172 tryeq 13 mod -4, -3;
173 tryeq -13 mod -4, -1;
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
174
175 # The example for sloppy divide, rigged to avoid the peephole optimiser.
a35a460 [spec] un-TODO two more tests in arith.t
moritz authored
176 is_approx "20." / "5.", 4;
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
177
178 tryeq 2.5 / 2, 1.25;
179 tryeq 3.5 / -2, -1.75;
180 tryeq -4.5 / 2, -2.25;
181 tryeq -5.5 / -2, 2.75;
182
183 # exponentiation
184
185 is 2**2, 4;
186 is 2.2**2, 4.84;
5ecd8f8 [t/spec] simplify and unfudge two arithmetic tests
moritz authored
187 is_approx 2**2.2, 4.59479341;
188 is_approx 2.2**2.2, 5.66669577;
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
189 is 1**0, 1;
190 is 1**1, 1;
0f670c5 [t/spec] Add test for ** right associative
bacek authored
191 isnt 2**3**4, 4096, "** is right associative";
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
192
612a8a8 [t/spec] a few small improvements
moritz authored
193 # test associativity
194 is 2 ** 2 ** 3, 256, 'infix:<**> is right associative';
195
207f13f [t] and [t/spec]
moritz authored
196 {
197 is_approx(-1, (0 + 1i)**2, "i^2 == -1");
7201d4d [t/spec] re-fudge arith.t for rakudo
moritz authored
198
207f13f [t] and [t/spec]
moritz authored
199 is_approx(-1, (0.7071067811865476 + -0.7071067811865475i)**4, "sqrt(-i)**4 ==-1" );
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy (m...
moritz authored
200 is_approx(1i, (-1+0i)**0.5, '(-1+0i)**0.5 == i ');
207f13f [t] and [t/spec]
moritz authored
201 }
202
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
203 {
3a37e8f [t/spec] some corrections and fudges
moritz authored
204 # Inf
205 is Inf, Inf;
206 is -Inf, -Inf;
207 isnt Inf, -Inf;
208 is (-Inf).abs, Inf;
209 is Inf+100, Inf;
210 is Inf-100, Inf;
211 is Inf*100, Inf;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy (m...
moritz authored
212 is Inf / 100, Inf;
3a37e8f [t/spec] some corrections and fudges
moritz authored
213 is Inf*-100, -Inf;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy (m...
moritz authored
214 is Inf / -100, -Inf;
215 is 100 / Inf, 0;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
216 is Inf**100, Inf;
217 is Inf*0, NaN;
0b3dad3 [t/spec] some disambiguationg whitespaces
moritz authored
218 is Inf - Inf, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
219 is Inf*Inf, Inf;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy (m...
moritz authored
220 is Inf / Inf, NaN;
221 is Inf*Inf / Inf, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
222 is Inf**0, 1;
223 is 0**0, 1;
224 is 0**Inf, 0;
225
226 my $inf1 = 100**Inf;
227 is $inf1, Inf, "100**Inf";
228 my $inf2 = Inf**Inf;
229 is $inf2, Inf, "Inf**Inf";
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
230
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
231 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
232 # See L<"http://mathworld.wolfram.com/Indeterminate.html">
233 # for why these three values are defined like they are.
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
234 {
235 is 0.9**Inf, 0, "0.9**Inf converges towards 0";
236 is 1.1**Inf, Inf, "1.1**Inf diverges towards Inf";
237 is 1**Inf, 1;
238 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
239
b6e5936 [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
240 ##?pugs todo
241 #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
242
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
243 {
244 # NaN
245 is NaN, NaN;
246 is -NaN, NaN;
247 is NaN+100, NaN;
248 is NaN-100, NaN;
249 is NaN*100, NaN;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy (m...
moritz authored
250 is NaN / 100, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
251 is NaN**100, NaN;
252 is NaN+NaN, NaN;
0b3dad3 [t/spec] some disambiguationg whitespaces
moritz authored
253 is NaN - NaN, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
254 is NaN*NaN, NaN;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy (m...
moritz authored
255 is NaN / NaN, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
256
257 is NaN+Inf, NaN;
0b3dad3 [t/spec] some disambiguationg whitespaces
moritz authored
258 is NaN - Inf, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
259 is NaN*Inf, NaN;
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy (m...
moritz authored
260 is NaN / Inf, NaN;
261 is Inf / NaN, NaN;
03ac5b7 [spec] started to fudge artih.t - got rid of all compilation and run tim...
moritz authored
262
263 my $nan1 = NaN**NaN;
264 is $nan1, NaN, "NaN**NaN";
265 my $nan2 = NaN**Inf;
266 is $nan2, NaN, "NaN**Inf";
267 my $nan3 = Inf**NaN;
268 is $nan3, NaN, "Inf**NaN";
269 }
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
270
271 =begin pod
272
273 =head2 BEHAVIOUR OF DIVISION AND MODULUS WITH ZERO
274
275 This test tests the behaviour of '%' and '/' when used with
276 a zero modulus resp. divisor.
277
278 All uses of a zero modulus or divisor should 'die', and the
279 'die' should be non-fatal.
280
281 =end pod
282
283 my $x;
284
a09e6cc [t/spec] Refudge a tad for ng.
colomon authored
285 #?rakudo 2 todo 'modulo by zero'
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
286 dies_ok( { say 3 % 0 }, 'Modulo zero dies and is catchable');
287 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
288 #?rakudo todo 'die or fail?'
1269f88 [gsoc_spectest] staging commit for fudging arith.t
Auzon authored
289 dies_ok( { $x := 0; say 3 % $x; }, 'Modulo zero dies and is catchable with VRef variables');
290
a4ba5fd [t/spec] correct meaning of infix:<div> and infix:</>. Patch courtesy (m...
moritz authored
291 dies_ok( { say 3 div 0 }, 'Division by zero dies and is catchable');
292 dies_ok( { $x = 0; say 3 div $x; }, 'Division by zero dies and is catchable with VInt div VRat variables');
293 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
294
295 # This is a rakudo regression wrt bignum:
cafc38e [spec]: Convert rakudo's bignum 'todo' to 'skip'.
pmichaud authored
296 #?rakudo skip 'bigint'
78c96ad [t/spec] added two bigint tests, slavik++
moritz authored
297 {
298 my $f = 1; $f *= $_ for 2..25; say $f;
299 ok $f == 15511210043330985984000000,
300 'Can calcualte 25! without loss of precision';
301 ok 2**65 == 36893488147419103232,
302 'Can calcualte 2**65 without loss of precision';
303 }
304
8aaa346 [t/spec] test that Rat literals are gone, RT #73264
moritz authored
305 # RT #73264
306 # Rat literals are gone
307 {
308 ok 1/7 / 1/7 == 1/49, 'no more Rat literals, infix:</> has normal left assoc';
309 }
310
e76dd4c Moritz Lenz s/done_testing/done/ as per recent S24 changes
moritz authored
311 done;
72c5e19 [t/spec] Test for RT 69172
kyle authored
312
78c96ad [t/spec] added two bigint tests, slavik++
moritz authored
313 # vim: ft=perl6
Something went wrong with that request. Please try again.