Skip to content
Newer
Older
100644 140 lines (113 sloc) 4.94 KB
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
ad1b86b [t] Test suite refactoring.
cosimo authored
2
3 use Test;
4
04c0281 @moritz comparison with < of complex numbers dies (RT #104660)
moritz authored
5 plan 482;
ad1b86b [t] Test suite refactoring.
cosimo authored
6
6512730 [t/spec] test for Complex.re and .im
moritz authored
7 # Basic tests functions specific to complex numbers.
ad1b86b [t] Test suite refactoring.
cosimo authored
8
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
9 isa_ok(1 + 2i, Complex, 'postfix:<i> creates a Complex number');
c1ba1c5 @moritz start fudging complex.t for nom
moritz authored
10 #?rakudo 2 skip 'i'
5693096 [t/spec] test for RT #76994, bare i is the complex unit
moritz authored
11 isa_ok(i, Complex, 'i creates a Complex number');
f0aa007 [t/spec] typo fix.
qiuhw authored
12 ok i == 1i, 'i == 1i';
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
13
81b8c36 @ShimmerFairy Added tests for ()i and \i forms of Complex numbers.
ShimmerFairy authored
14 isa_ok((3)i, Complex, '($n)i form creates a Complex number');
15 isa_ok(3\i, Complex, '$n\i form creates a Complex number');
16
81160eb [t/spec] more tests for Complex arithmetics
moritz authored
17 is_approx((2i)i, -2, 'postfix:<i> works on an imaginary number');
18 is_approx((2i + 3)i, -2 + 3i, 'postfix:<i> works on a Complex number');
19
04c0281 @moritz comparison with < of complex numbers dies (RT #104660)
moritz authored
20 dies_ok { (2 + 3i) > (2 + 2i) }, '> comparison of complex numbers dies';
21
c1ba1c5 @moritz start fudging complex.t for nom
moritz authored
22 #?rakudo 3 skip 'i'
3c11479 [t/spec] Add tests for i as 1i.
colomon authored
23 is_approx(i, 1i, 'standalone i works to generate a Complex number');
24 is_approx(1 - i, 1 - 1i, 'standalone i works to generate a Complex number');
25 is_approx(2i * i, -2, 'standalone i works times a Complex number');
26
81160eb [t/spec] more tests for Complex arithmetics
moritz authored
27 # checked with the open CAS system "yacas":
28 # In> (3+4*I) / (2-I)
29 # Out> Complex(2/5,11/5)
30 # In> (3+4*I) * (2-I)
31 # Out> Complex(10,5)
32 # etc
33 is_approx (3+4i)/(2-1i), 2/5 + (11/5)i, 'Complex division';
c1ba1c5 @moritz start fudging complex.t for nom
moritz authored
34 is_approx (3+4i)*(2-1i), 10+5i, 'Complex multiplication';
81160eb [t/spec] more tests for Complex arithmetics
moritz authored
35 is_approx (6+4i)/2, 3+2i, 'dividing Complex by a Real';
0926aed [t/spec] Fixed typo.
rblasch authored
36 is_approx 2/(3+1i), 3/5 -(1/5)i, 'dividing a Real by a Complex';
81160eb [t/spec] more tests for Complex arithmetics
moritz authored
37 is_approx 2 * (3+7i), 6+14i, 'Real * Complex';
38 is_approx (3+7i) * 2, 6+14i, 'Complex * Real';
39
b2275f5 [t/spec] Add tests for Complex.perl.
colomon authored
40 isa_ok( eval((1+3i).perl), Complex, 'eval (1+3i).perl is Complex' );
41 is_approx( (eval (1+3i).perl), 1+3i, 'eval (1+3i).perl is 1+3i' );
42 isa_ok( eval((1+0i).perl), Complex, 'eval (1+0i).perl is Complex' );
43 is_approx( (eval (1+0i).perl), 1, 'eval (1+0i).perl is 1' );
44 isa_ok( eval((3i).perl), Complex, 'eval (3i).perl is Complex' );
45 is_approx( (eval (3i).perl), 3i, 'eval (3i).perl is 3i' );
46
6a5a339 @colomon Fudge for Niecza.
colomon authored
47 #?niecza skip "NYI"
48 {
49 ok (1+0i).Real ~~ Real, "(1+0i).Real is a Real";
50 is (1+0i).Real, 1, "(1+0i).Real is 1";
51 isa_ok (1.2+0i).Int, Int, "(1.2+0i).Int is an Int";
52 is (1.2+0i).Int, 1, "(1.2+0i).Int is 1";
53 isa_ok (1.2.sin+0i).Rat, Rat, "(1.2.sin+0i).Rat is an Rat";
54 is_approx (1.2.sin+0i).Rat, 1.2.sin, "(1.2.sin+0i).Rat is 1.2.sin";
55 isa_ok (1.2+0i).Num, Num, "(1.2+0i).Num is an Num";
56 is_approx (1.2+0i).Num, 1.2, "(1.2+0i).Num is 1.2";
57 isa_ok (1.2+1i).Complex, Complex, "(1.2+1i).Complex is an Complex";
58 is_approx (1.2+1i).Complex, 1.2+1i, "(1.2+1i).Complex is 1.2+1i";
59 }
4e37e94 [t/spec] Add tests for Complex conversions via .Real, .Int, .Rat, .Nu…
colomon authored
60
b2275f5 [t/spec] Add tests for Complex.perl.
colomon authored
61 # MUST: test .Str
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
62
63 my @examples = (0i, 1 + 0i, -1 + 0i, 1i, -1i, 2 + 0i, -2 + 0i, 2i, -2i,
64 2 + 3i, 2 - 3i, -2 + 3i, -2 - 3i,
65 cis(1.1), cis(3.1), cis(5.1), 35.unpolar(0.8), 40.unpolar(3.7));
66
67 for @examples -> $z {
da387b9 [t/spec] Remove initial spaces in test description strings added yest…
colomon authored
68 is_approx($z + 0, $z, "$z + 0 = $z");
69 is_approx(0 + $z, $z, "0 + $z = $z");
3dc8e04 [t/spec] All those 0.0s and 2.5s were meant to be Nums -- and now the…
colomon authored
70 is_approx($z + 0.0.Num, $z, "$z + 0.0.Num = $z");
71 is_approx(0.0.Num + $z, $z, "0.0.Num + $z = $z");
da387b9 [t/spec] Remove initial spaces in test description strings added yest…
colomon authored
72 is_approx($z + 0 / 1, $z, "$z + 0/1 = $z");
73 is_approx(0 / 1 + $z, $z, "0/1 + $z = $z");
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
74
da387b9 [t/spec] Remove initial spaces in test description strings added yest…
colomon authored
75 is_approx($z - 0, $z, "$z - 0 = $z");
76 is_approx(0 - $z, -$z, "0 - $z = -$z");
3dc8e04 [t/spec] All those 0.0s and 2.5s were meant to be Nums -- and now the…
colomon authored
77 is_approx($z - 0.0.Num, $z, "$z - 0.0.Num = $z");
78 is_approx(0.0.Num - $z, -$z, "0.0.Num - $z = -$z");
da387b9 [t/spec] Remove initial spaces in test description strings added yest…
colomon authored
79 is_approx($z - 0 / 1, $z, "$z - 0/1 = $z");
80 is_approx(0 / 1 - $z, -$z, "0/1 - $z = -$z");
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
81
da387b9 [t/spec] Remove initial spaces in test description strings added yest…
colomon authored
82 is_approx($z + 2, $z.re + 2 + ($z.im)i, "$z + 2");
83 is_approx(2 + $z, $z.re + 2 + ($z.im)i, "2 + $z");
3dc8e04 [t/spec] All those 0.0s and 2.5s were meant to be Nums -- and now the…
colomon authored
84 is_approx($z + 2.5.Num, $z.re + 2.5.Num + ($z.im)i, "$z + 2.5.Num = $z");
85 is_approx(2.5.Num + $z, $z.re + 2.5.Num + ($z.im)i, "2.5.Num + $z = $z");
da387b9 [t/spec] Remove initial spaces in test description strings added yest…
colomon authored
86 is_approx($z + 3 / 2, $z.re + 3/2 + ($z.im)i, "$z + 3/2");
87 is_approx(3 / 2 + $z, $z.re + 3/2 + ($z.im)i, "3/2 + $z");
88
89 is_approx($z - 2, $z.re - 2 + ($z.im)i, "$z - 2");
90 is_approx(2 - $z, -$z.re + 2 - ($z.im)i, "2 - $z");
3dc8e04 [t/spec] All those 0.0s and 2.5s were meant to be Nums -- and now the…
colomon authored
91 is_approx($z - 2.5.Num, $z.re - 2.5.Num + ($z.im)i, "$z - 2.5.Num = $z");
92 is_approx(2.5.Num - $z, -$z.re + 2.5.Num - ($z.im)i, "2.5.Num - $z = $z");
da387b9 [t/spec] Remove initial spaces in test description strings added yest…
colomon authored
93 is_approx($z - 3 / 2, $z.re - 3/2 + ($z.im)i, "$z - 3/2");
94 is_approx(3 / 2 - $z, -$z.re + 3/2 - ($z.im)i, "3/2 - $z");
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
95 }
96
4e820b4 [t/spec] more smartlink fixes
moritz authored
97 # L<S32::Numeric/Complex/=item re>
98 # L<S32::Numeric/Complex/=item im>
ad1b86b [t] Test suite refactoring.
cosimo authored
99
6512730 [t/spec] test for Complex.re and .im
moritz authored
100 {
101 is (1 + 2i).re, 1, 'Complex.re works';
102 is (1 + 2i).im, 2, 'Complex.im works';
103 }
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
104
8acee94 [t/spec] tests for RT #68848, complex powers wrapped in a subroutine
moritz authored
105 # used to be RT #68848
106 {
107 is_approx exp(3.0 * log(1i)), -1.83697e-16-1i,
108 'exp(3.0 * log(1i))';
109 sub iPower($a, $b) { exp($b * log($a)) };
110 is_approx iPower(1i, 3.0), -1.83697e-16-1i, 'same as wrapped as sub';
111 }
112
f59ce96 @moritz fudge complex.t for rakudo
moritz authored
113 #?rakudo skip 'e'
5ee0b4c [t/spec] Add a test for Num.log(Complex), which needs to be skipped n…
colomon authored
114 is_approx e.log(1i), -2i / pi, "log e base i == -2i / pi";
115
0108741 [t/spec] New tests of basic arithmetic mixing Complex and numeric Strs.
colomon authored
116 # Complex math with strings, to make sure type coercion is working correctly
117 {
118 is 3i + "1", 1 + 3i, '3i + "1"';
119 is "1" + 3i, 1 + 3i, '"1" + 3i';
120 is 3i - "1", 3i - 1, '3i - "1"';
121 is "1" - 3i, 1 - 3i, '"1" - 3i';
122 is 3i * "1", 3i * 1, '3i * "1"';
123 is "1" * 3i, 1 * 3i, '"1" * 3i';
124 is 3i / "1", 3i / 1, '3i / "1"';
125 is "1" / 3i, 1 / 3i, '"1" / 3i';
126 is 3i ** "1", 3i ** 1, '3i ** "1"';
127 is "1" ** 3i, 1 ** 3i, '"1" ** 3i';
128
129 }
130
8acbb22 @dwhipp Add tests for conjugate method (for RT 76602)
dwhipp authored
131 # Conjugation
132 {
133 is (2+3i).conjugate, 2-3i, 'conjugate 2+3i -> 2-3i';
134 is (5-4i).conjugate, 5+4i, 'conjugate 5-4i -> 5+4i';
135 }
136
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
137 done;
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
138
139 # vim: ft=perl6
Something went wrong with that request. Please try again.