Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 148 lines (118 sloc) 5.342 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
57f0c48 @moritz != and complex numbers
moritz authored
5 plan 488;
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');
5693096 [t/spec] test for RT #76994, bare i is the complex unit
moritz authored
10 isa_ok(i, Complex, 'i creates a Complex number');
f0aa007 [t/spec] typo fix.
qiuhw authored
11 ok i == 1i, 'i == 1i';
57f0c48 @moritz != and complex numbers
moritz authored
12 ok 1 != 1i, '!= and complex numbers';
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
13
81b8c36 @lue Added tests for ()i and \i forms of Complex numbers.
lue 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
902702c @colomon Use eval_dies-ok because Niecza catches comparison errors at compile tim...
colomon authored
20 eval_dies_ok '(2 + 3i) > (2 + 2i)', '> comparison of complex numbers dies';
04c0281 @moritz comparison with < of complex numbers dies (RT #104660)
moritz authored
21
3c11479 [t/spec] Add tests for i as 1i.
colomon authored
22 is_approx(i, 1i, 'standalone i works to generate a Complex number');
23 is_approx(1 - i, 1 - 1i, 'standalone i works to generate a Complex number');
24 is_approx(2i * i, -2, 'standalone i works times a Complex number');
25
81160eb [t/spec] more tests for Complex arithmetics
moritz authored
26 # checked with the open CAS system "yacas":
27 # In> (3+4*I) / (2-I)
28 # Out> Complex(2/5,11/5)
29 # In> (3+4*I) * (2-I)
30 # Out> Complex(10,5)
31 # etc
32 is_approx (3+4i)/(2-1i), 2/5 + (11/5)i, 'Complex division';
c1ba1c5 @moritz start fudging complex.t for nom
moritz authored
33 is_approx (3+4i)*(2-1i), 10+5i, 'Complex multiplication';
81160eb [t/spec] more tests for Complex arithmetics
moritz authored
34 is_approx (6+4i)/2, 3+2i, 'dividing Complex by a Real';
0926aed [t/spec] Fixed typo.
rblasch authored
35 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
36 is_approx 2 * (3+7i), 6+14i, 'Real * Complex';
37 is_approx (3+7i) * 2, 6+14i, 'Complex * Real';
38
5bab36f @FROGGS eval => EVAL in S14 to S32
FROGGS authored
39 isa_ok( EVAL((1+3i).perl), Complex, 'EVAL (1+3i).perl is Complex' );
40 is_approx( (EVAL (1+3i).perl), 1+3i, 'EVAL (1+3i).perl is 1+3i' );
41 isa_ok( EVAL((1+0i).perl), Complex, 'EVAL (1+0i).perl is Complex' );
42 is_approx( (EVAL (1+0i).perl), 1, 'EVAL (1+0i).perl is 1' );
43 isa_ok( EVAL((3i).perl), Complex, 'EVAL (3i).perl is Complex' );
44 is_approx( (EVAL (3i).perl), 3i, 'EVAL (3i).perl is 3i' );
b2275f5 [t/spec] Add tests for Complex.perl.
colomon authored
45
6a5a339 @colomon Fudge for Niecza.
colomon authored
46 #?niecza skip "NYI"
47 {
48 ok (1+0i).Real ~~ Real, "(1+0i).Real is a Real";
49 is (1+0i).Real, 1, "(1+0i).Real is 1";
50 isa_ok (1.2+0i).Int, Int, "(1.2+0i).Int is an Int";
51 is (1.2+0i).Int, 1, "(1.2+0i).Int is 1";
52 isa_ok (1.2.sin+0i).Rat, Rat, "(1.2.sin+0i).Rat is an Rat";
53 is_approx (1.2.sin+0i).Rat, 1.2.sin, "(1.2.sin+0i).Rat is 1.2.sin";
54 isa_ok (1.2+0i).Num, Num, "(1.2+0i).Num is an Num";
55 is_approx (1.2+0i).Num, 1.2, "(1.2+0i).Num is 1.2";
56 isa_ok (1.2+1i).Complex, Complex, "(1.2+1i).Complex is an Complex";
57 is_approx (1.2+1i).Complex, 1.2+1i, "(1.2+1i).Complex is 1.2+1i";
58 }
4e37e94 [t/spec] Add tests for Complex conversions via .Real, .Int, .Rat, .Num, ...
colomon authored
59
b2275f5 [t/spec] Add tests for Complex.perl.
colomon authored
60 # MUST: test .Str
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
61
62 my @examples = (0i, 1 + 0i, -1 + 0i, 1i, -1i, 2 + 0i, -2 + 0i, 2i, -2i,
062d17a @coke (slightly complex) pugs fudge
coke authored
63 2 + 3i, 2 - 3i, -2 + 3i, -2 - 3i);
64
65 push @examples, (cis(1.1), cis(3.1), cis(5.1), 35.unpolar(0.8), 40.unpolar(3.7));
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
66
67 for @examples -> $z {
da387b9 [t/spec] Remove initial spaces in test description strings added yesterd...
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 they a...
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 yesterd...
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 yesterd...
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 they a...
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 yesterd...
colomon authored
79 is_approx($z - 0 / 1, $z, "$z - 0/1 = $z");
80 is_approx(0 / 1 - $z, -$z, "0/1 - $z = -$z");
062d17a @coke (slightly complex) pugs fudge
coke authored
81
da387b9 [t/spec] Remove initial spaces in test description strings added yesterd...
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 they a...
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 yesterd...
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 they a...
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 yesterd...
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
bae50d7 @colomon Add some Complex 0 ** tests.
colomon authored
105 {
106 is_approx 0i ** 2, 0, "Complex 0 ** Int works";
107 is_approx 0i ** 2.5, 0, "Complex 0 ** Rat works";
108 is_approx 0i ** (2 + 0i), 0, "Complex 0 ** Complex works";
be7da47 @colomon Add test for 0 ** (2 + 0i).
colomon authored
109 is_approx 0 ** (2 + 0i), 0, "Real 0 ** Complex works";
bae50d7 @colomon Add some Complex 0 ** tests.
colomon authored
110 }
111
8acee94 [t/spec] tests for RT #68848, complex powers wrapped in a subroutine
moritz authored
112 # used to be RT #68848
113 {
114 is_approx exp(3.0 * log(1i)), -1.83697e-16-1i,
115 'exp(3.0 * log(1i))';
116 sub iPower($a, $b) { exp($b * log($a)) };
117 is_approx iPower(1i, 3.0), -1.83697e-16-1i, 'same as wrapped as sub';
118 }
119
5ee0b4c [t/spec] Add a test for Num.log(Complex), which needs to be skipped now,...
colomon authored
120 is_approx e.log(1i), -2i / pi, "log e base i == -2i / pi";
121
0108741 [t/spec] New tests of basic arithmetic mixing Complex and numeric Strs.
colomon authored
122 # Complex math with strings, to make sure type coercion is working correctly
123 {
124 is 3i + "1", 1 + 3i, '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 is 3i * "1", 3i * 1, '3i * "1"';
129 is "1" * 3i, 1 * 3i, '"1" * 3i';
130 is 3i / "1", 3i / 1, '3i / "1"';
131 is "1" / 3i, 1 / 3i, '"1" / 3i';
132 is 3i ** "1", 3i ** 1, '3i ** "1"';
133 is "1" ** 3i, 1 ** 3i, '"1" ** 3i';
134
135 }
136
8acbb22 @dwhipp Add tests for conjugate method (for RT 76602)
dwhipp authored
137 # Conjugation
138 {
8992cb9 @moritz .conjugate is spelled .conj
moritz authored
139 is (2+3i).conj, 2-3i, 'conj 2+3i -> 2-3i';
140 is (5-4i).conj, 5+4i, 'conj 5-4i -> 5+4i';
8acbb22 @dwhipp Add tests for conjugate method (for RT 76602)
dwhipp authored
141 }
142
902702c @colomon Use eval_dies-ok because Niecza catches comparison errors at compile tim...
colomon authored
143 eval_dies_ok "(1 + 2i) < (2 + 4i)", 'Cannot arithmetically compare Complex numbers';
144
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
145 done;
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
146
147 # vim: ft=perl6
Something went wrong with that request. Please try again.