Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 144 lines (116 sloc) 4.871 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
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
5 plan *;
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');
10
81160eb [t/spec] more tests for Complex arithmetics
moritz authored
11 is_approx((2i)i, -2, 'postfix:<i> works on an imaginary number');
12 is_approx((2i + 3)i, -2 + 3i, 'postfix:<i> works on a Complex number');
13
14 # checked with the open CAS system "yacas":
15 # In> (3+4*I) / (2-I)
16 # Out> Complex(2/5,11/5)
17 # In> (3+4*I) * (2-I)
18 # Out> Complex(10,5)
19 # etc
20 is_approx (3+4i)/(2-1i), 2/5 + (11/5)i, 'Complex division';
21 is_approx (3+4i)*(2-1i), 10+5i, 'Complex division';
22 is_approx (6+4i)/2, 3+2i, 'dividing Complex by a Real';
0926aed [t/spec] Fixed typo.
rblasch authored
23 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
24 is_approx 2 * (3+7i), 6+14i, 'Real * Complex';
25 is_approx (3+7i) * 2, 6+14i, 'Complex * Real';
26
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
27 # MUST: test .perl, .Str
28
29 my @examples = (0i, 1 + 0i, -1 + 0i, 1i, -1i, 2 + 0i, -2 + 0i, 2i, -2i,
30 2 + 3i, 2 - 3i, -2 + 3i, -2 - 3i,
31 cis(1.1), cis(3.1), cis(5.1), 35.unpolar(0.8), 40.unpolar(3.7));
32
33 for @examples -> $z {
34 is_approx($z + 0, $z, "$z + 0 = $z");
35 is_approx(0 + $z, $z, "0 + $z = $z");
36 is_approx($z + 0.0, $z, "$z + 0.0 = $z");
37 is_approx(0.0 + $z, $z, "0.0 + $z = $z");
38 is_approx($z + 0 / 1, $z, "$z + 0/1 = $z");
39 is_approx(0 / 1 + $z, $z, "0/1 + $z = $z");
40
41 is_approx($z - 0, $z, "$z - 0 = $z");
42 is_approx(0 - $z, -$z, "0 - $z = -$z");
43 is_approx($z - 0.0, $z, "$z - 0.0 = $z");
44 is_approx(0.0 - $z, -$z, "0.0 - $z = -$z");
45 is_approx($z - 0 / 1, $z, "$z - 0/1 = $z");
46 is_approx(0 / 1 - $z, -$z, "0/1 - $z = -$z");
47
48 is_approx($z + 2, $z.re + 2 + ($z.im)i, "$z + 2");
49 is_approx(2 + $z, $z.re + 2 + ($z.im)i, "2 + $z");
50 is_approx($z + 2.5, $z.re + 2.5 + ($z.im)i, "$z + 2.5 = $z");
51 is_approx(2.5 + $z, $z.re + 2.5 + ($z.im)i, "2.5 + $z = $z");
52 is_approx($z + 3 / 2, $z.re + 3/2 + ($z.im)i, "$z + 3/2");
53 is_approx(3 / 2 + $z, $z.re + 3/2 + ($z.im)i, "3/2 + $z");
54
55 is_approx($z - 2, $z.re - 2 + ($z.im)i, "$z - 2");
56 is_approx(2 - $z, -$z.re + 2 - ($z.im)i, "2 - $z");
57 is_approx($z - 2.5, $z.re - 2.5 + ($z.im)i, "$z - 2.5 = $z");
58 is_approx(2.5 - $z, -$z.re + 2.5 - ($z.im)i, "2.5 - $z = $z");
59 is_approx($z - 3 / 2, $z.re - 3/2 + ($z.im)i, "$z - 3/2");
60 is_approx(3 / 2 - $z, -$z.re + 3/2 - ($z.im)i, "3/2 - $z");
61 }
62
4e820b4 [t/spec] more smartlink fixes
moritz authored
63 # L<S32::Numeric/Complex/=item re>
64 # L<S32::Numeric/Complex/=item im>
ad1b86b [t] Test suite refactoring.
cosimo authored
65
6512730 [t/spec] test for Complex.re and .im
moritz authored
66 {
67 is (1 + 2i).re, 1, 'Complex.re works';
68 is (1 + 2i).im, 2, 'Complex.im works';
69 }
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
70
d154816 [t/spec] more smartlink fixing
moritz authored
71 # L<S32::Numeric/Num/=item cis>
5fe1b88 S29-num/complex.t: Update #?rakudo fudging.
pmichaud authored
72 my $pi = 3.141592653589793238;
ad1b86b [t] Test suite refactoring.
cosimo authored
73
5fe1b88 S29-num/complex.t: Update #?rakudo fudging.
pmichaud authored
74 {
4bb1f86 [spec] complex.t: invalid uses of is_approx()
moritz authored
75 is_approx(cis(0), 1 + 0i, "cis(0) == 1");
76 is_approx(cis($pi), -1 + 0i, "cis(pi) == -1");
77 is_approx(cis($pi / 2), 1i, "cis(pi/2) == i");
26eada7 [spec] S29-num/complex.t: fixed two tests
moritz authored
78 is_approx(cis(3*$pi / 2),-1i, "cis(3pi/2) == -i");
5fe1b88 S29-num/complex.t: Update #?rakudo fudging.
pmichaud authored
79 }
ad1b86b [t] Test suite refactoring.
cosimo authored
80
576906b [t] added named arg tests to trig and num functions
frew authored
81 #?rakudo skip 'named args'
82 {
83 is_approx(cis(:angle(0)), 1 + 0i, "cis(:angle(0)) == 1");
84 is_approx(cis(:angle($pi)), -1 + 0i, "cis(:angle(pi)) == -1");
85 is_approx(cis(:angle($pi / 2)), 1i, "cis(:angle(pi/2)) == i");
86 is_approx(cis(:angle(3*$pi / 2)),-1i, "cis(:angle(3pi/2)) == -i");
87 }
88
d154816 [t/spec] more smartlink fixing
moritz authored
89 # Test that 1.unpolar == cis
90 # L<S32::Numeric/Num/=item cis>
91 # L<S32::Numeric/Num/=item unpolar>
5fe1b88 S29-num/complex.t: Update #?rakudo fudging.
pmichaud authored
92
93 {
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
94 for 1..20 -> $i {
95 my $angle = 2 * $pi * $i / 20;
4bb1f86 [spec] complex.t: invalid uses of is_approx()
moritz authored
96 is_approx(cis($i), 1.unpolar($i), "cis(x) == 1.unpolar(x) No $i");
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
97 }
448375e [spec] finer graded fudging of complex.t
moritz authored
98 }
ad1b86b [t] Test suite refactoring.
cosimo authored
99
d154816 [t/spec] more smartlink fixing
moritz authored
100 # L<S32::Numeric/Num/=item abs>
101 # L<S32::Numeric/Num/=item unpolar>
448375e [spec] finer graded fudging of complex.t
moritz authored
102 #
103 # Test that unpolar() doesn't change the absolute value
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
104
448375e [spec] finer graded fudging of complex.t
moritz authored
105 {
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
106 my $counter = 1;
107 for 1..10 -> $abs {
108 for 1..10 -> $a {
72b072b S29-num/complex.t: update #?rakudo skip markers for new passing tests
pmichaud authored
109 my $angle = 2 * $pi * $a / 10;
110 is_approx(abs($abs.unpolar($angle)), $abs,
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
111 "unpolar doesn't change the absolute value (No $counter)");
112 $counter++;
113 }
ad1b86b [t] Test suite refactoring.
cosimo authored
114 }
5fe1b88 S29-num/complex.t: Update #?rakudo fudging.
pmichaud authored
115 }
ad1b86b [t] Test suite refactoring.
cosimo authored
116
d154816 [t/spec] more smartlink fixing
moritz authored
117 # L<S32::Numeric/Num/=item unpolar>
576906b [t] added named arg tests to trig and num functions
frew authored
118 #?rakudo skip 'named args'
119 {
120 # Basic tests for unpolar()
121 my $s = 2 * sqrt(2);
122
123 is_approx(unpolar(:mag(4), 0), 4, "unpolar(:mag(4), 0) == 4");
124 is_approx(unpolar(:mag(4), $pi/4), $s + ($s)i ,"unpolar(:mag(4), pi/4) == 2+2i");
125 is_approx(unpolar(:mag(4), $pi/2), 4i, "unpolar(:mag(4), pi/2) == 4i");
126 is_approx(unpolar(:mag(4), 3*$pi/4), -$s + ($s)i,"unpolar(:mag(4), pi/4) == -2+2i");
127 is_approx(unpolar(:mag(4), $pi), -4, "unpolar(:mag(4), pi) == -4");
128 }
129
5fe1b88 S29-num/complex.t: Update #?rakudo fudging.
pmichaud authored
130 {
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
131 # Basic tests for unpolar()
26eada7 [spec] S29-num/complex.t: fixed two tests
moritz authored
132 my $s = 2 * sqrt(2);
ad1b86b [t] Test suite refactoring.
cosimo authored
133
4bb1f86 [spec] complex.t: invalid uses of is_approx()
moritz authored
134 is_approx(4.unpolar(0), 4, "4.unpolar(0) == 4");
26eada7 [spec] S29-num/complex.t: fixed two tests
moritz authored
135 is_approx(4.unpolar($pi/4), $s + ($s)i ,"4.unpolar(pi/4) == 2+2i");
4bb1f86 [spec] complex.t: invalid uses of is_approx()
moritz authored
136 is_approx(4.unpolar($pi/2), 4i, "4.unpolar(pi/2) == 4i");
26eada7 [spec] S29-num/complex.t: fixed two tests
moritz authored
137 is_approx(4.unpolar(3*$pi/4), -$s + ($s)i,"4.unpolar(pi/4) == -2+2i");
4bb1f86 [spec] complex.t: invalid uses of is_approx()
moritz authored
138 is_approx(4.unpolar($pi), -4, "4.unpolar(pi) == -4");
626a59c [rakudo] add directives to S29-num/ and convert pod to pod6
particle authored
139 }
6512730 [t/spec] test for Complex.re and .im
moritz authored
140
06c877b [t/spec] Add some basic tests for complex addition and subtraction.
colomon authored
141 done_testing;
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
142
143 # vim: ft=perl6
Something went wrong with that request. Please try again.