Skip to content

HTTPS clone URL

Subversion checkout URL

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