Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 166 lines (133 sloc) 5.742 kb
58135b30 »
2008-05-08 [t/spec] changed 'use v6-alpha;' to 'use v6;'
1 use v6;
ad1b86bb »
2008-01-24 [t] Test suite refactoring.
2
3 use Test;
4
06c877b8 »
2009-09-30 [t/spec] Add some basic tests for complex addition and subtraction.
5 plan *;
ad1b86bb »
2008-01-24 [t] Test suite refactoring.
6
65127307 »
2009-03-09 [t/spec] test for Complex.re and .im
7 # Basic tests functions specific to complex numbers.
ad1b86bb »
2008-01-24 [t] Test suite refactoring.
8
06c877b8 »
2009-09-30 [t/spec] Add some basic tests for complex addition and subtraction.
9 isa_ok(1 + 2i, Complex, 'postfix:<i> creates a Complex number');
10
81160ebb »
2009-09-30 [t/spec] more tests for Complex arithmetics
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
3c114793 »
2009-10-24 [t/spec] Add tests for i as 1i.
14 #?rakudo 3 skip 'standalone i NYI'
15 is_approx(i, 1i, 'standalone i works to generate a Complex number');
16 is_approx(1 - i, 1 - 1i, 'standalone i works to generate a Complex number');
17 is_approx(2i * i, -2, 'standalone i works times a Complex number');
18
81160ebb »
2009-09-30 [t/spec] more tests for Complex arithmetics
19 # checked with the open CAS system "yacas":
20 # In> (3+4*I) / (2-I)
21 # Out> Complex(2/5,11/5)
22 # In> (3+4*I) * (2-I)
23 # Out> Complex(10,5)
24 # etc
25 is_approx (3+4i)/(2-1i), 2/5 + (11/5)i, 'Complex division';
26 is_approx (3+4i)*(2-1i), 10+5i, 'Complex division';
27 is_approx (6+4i)/2, 3+2i, 'dividing Complex by a Real';
0926aed2 »
2009-10-07 [t/spec] Fixed typo.
28 is_approx 2/(3+1i), 3/5 -(1/5)i, 'dividing a Real by a Complex';
81160ebb »
2009-09-30 [t/spec] more tests for Complex arithmetics
29 is_approx 2 * (3+7i), 6+14i, 'Real * Complex';
30 is_approx (3+7i) * 2, 6+14i, 'Complex * Real';
31
b2275f5e »
2009-10-18 [t/spec] Add tests for Complex.perl.
32 isa_ok( eval((1+3i).perl), Complex, 'eval (1+3i).perl is Complex' );
33 is_approx( (eval (1+3i).perl), 1+3i, 'eval (1+3i).perl is 1+3i' );
34 isa_ok( eval((1+0i).perl), Complex, 'eval (1+0i).perl is Complex' );
35 is_approx( (eval (1+0i).perl), 1, 'eval (1+0i).perl is 1' );
36 isa_ok( eval((3i).perl), Complex, 'eval (3i).perl is Complex' );
37 is_approx( (eval (3i).perl), 3i, 'eval (3i).perl is 3i' );
38
39 # MUST: test .Str
06c877b8 »
2009-09-30 [t/spec] Add some basic tests for complex addition and subtraction.
40
41 my @examples = (0i, 1 + 0i, -1 + 0i, 1i, -1i, 2 + 0i, -2 + 0i, 2i, -2i,
42 2 + 3i, 2 - 3i, -2 + 3i, -2 - 3i,
43 cis(1.1), cis(3.1), cis(5.1), 35.unpolar(0.8), 40.unpolar(3.7));
44
45 for @examples -> $z {
46 is_approx($z + 0, $z, "$z + 0 = $z");
47 is_approx(0 + $z, $z, "0 + $z = $z");
48 is_approx($z + 0.0, $z, "$z + 0.0 = $z");
49 is_approx(0.0 + $z, $z, "0.0 + $z = $z");
50 is_approx($z + 0 / 1, $z, "$z + 0/1 = $z");
51 is_approx(0 / 1 + $z, $z, "0/1 + $z = $z");
52
53 is_approx($z - 0, $z, "$z - 0 = $z");
54 is_approx(0 - $z, -$z, "0 - $z = -$z");
55 is_approx($z - 0.0, $z, "$z - 0.0 = $z");
56 is_approx(0.0 - $z, -$z, "0.0 - $z = -$z");
57 is_approx($z - 0 / 1, $z, "$z - 0/1 = $z");
58 is_approx(0 / 1 - $z, -$z, "0/1 - $z = -$z");
59
60 is_approx($z + 2, $z.re + 2 + ($z.im)i, "$z + 2");
61 is_approx(2 + $z, $z.re + 2 + ($z.im)i, "2 + $z");
62 is_approx($z + 2.5, $z.re + 2.5 + ($z.im)i, "$z + 2.5 = $z");
63 is_approx(2.5 + $z, $z.re + 2.5 + ($z.im)i, "2.5 + $z = $z");
64 is_approx($z + 3 / 2, $z.re + 3/2 + ($z.im)i, "$z + 3/2");
65 is_approx(3 / 2 + $z, $z.re + 3/2 + ($z.im)i, "3/2 + $z");
66
67 is_approx($z - 2, $z.re - 2 + ($z.im)i, "$z - 2");
68 is_approx(2 - $z, -$z.re + 2 - ($z.im)i, "2 - $z");
69 is_approx($z - 2.5, $z.re - 2.5 + ($z.im)i, "$z - 2.5 = $z");
70 is_approx(2.5 - $z, -$z.re + 2.5 - ($z.im)i, "2.5 - $z = $z");
71 is_approx($z - 3 / 2, $z.re - 3/2 + ($z.im)i, "$z - 3/2");
72 is_approx(3 / 2 - $z, -$z.re + 3/2 - ($z.im)i, "3/2 - $z");
73 }
74
4e820b43 »
2009-04-26 [t/spec] more smartlink fixes
75 # L<S32::Numeric/Complex/=item re>
76 # L<S32::Numeric/Complex/=item im>
ad1b86bb »
2008-01-24 [t] Test suite refactoring.
77
65127307 »
2009-03-09 [t/spec] test for Complex.re and .im
78 {
79 is (1 + 2i).re, 1, 'Complex.re works';
80 is (1 + 2i).im, 2, 'Complex.im works';
81 }
626a59c1 »
2008-01-27 [rakudo] add directives to S29-num/ and convert pod to pod6
82
d1548163 »
2009-04-26 [t/spec] more smartlink fixing
83 # L<S32::Numeric/Num/=item cis>
5fe1b881 »
2008-06-07 S29-num/complex.t: Update #?rakudo fudging.
84 my $pi = 3.141592653589793238;
ad1b86bb »
2008-01-24 [t] Test suite refactoring.
85
5fe1b881 »
2008-06-07 S29-num/complex.t: Update #?rakudo fudging.
86 {
4bb1f868 »
2008-06-05 [spec] complex.t: invalid uses of is_approx()
87 is_approx(cis(0), 1 + 0i, "cis(0) == 1");
88 is_approx(cis($pi), -1 + 0i, "cis(pi) == -1");
89 is_approx(cis($pi / 2), 1i, "cis(pi/2) == i");
26eada7e »
2008-06-30 [spec] S29-num/complex.t: fixed two tests
90 is_approx(cis(3*$pi / 2),-1i, "cis(3pi/2) == -i");
5fe1b881 »
2008-06-07 S29-num/complex.t: Update #?rakudo fudging.
91 }
ad1b86bb »
2008-01-24 [t] Test suite refactoring.
92
576906b4 »
2009-01-31 [t] added named arg tests to trig and num functions
93 #?rakudo skip 'named args'
94 {
95 is_approx(cis(:angle(0)), 1 + 0i, "cis(:angle(0)) == 1");
96 is_approx(cis(:angle($pi)), -1 + 0i, "cis(:angle(pi)) == -1");
97 is_approx(cis(:angle($pi / 2)), 1i, "cis(:angle(pi/2)) == i");
98 is_approx(cis(:angle(3*$pi / 2)),-1i, "cis(:angle(3pi/2)) == -i");
99 }
100
d1548163 »
2009-04-26 [t/spec] more smartlink fixing
101 # Test that 1.unpolar == cis
102 # L<S32::Numeric/Num/=item cis>
103 # L<S32::Numeric/Num/=item unpolar>
5fe1b881 »
2008-06-07 S29-num/complex.t: Update #?rakudo fudging.
104
105 {
626a59c1 »
2008-01-27 [rakudo] add directives to S29-num/ and convert pod to pod6
106 for 1..20 -> $i {
107 my $angle = 2 * $pi * $i / 20;
4bb1f868 »
2008-06-05 [spec] complex.t: invalid uses of is_approx()
108 is_approx(cis($i), 1.unpolar($i), "cis(x) == 1.unpolar(x) No $i");
626a59c1 »
2008-01-27 [rakudo] add directives to S29-num/ and convert pod to pod6
109 }
448375ea »
2008-06-23 [spec] finer graded fudging of complex.t
110 }
ad1b86bb »
2008-01-24 [t] Test suite refactoring.
111
d1548163 »
2009-04-26 [t/spec] more smartlink fixing
112 # L<S32::Numeric/Num/=item abs>
113 # L<S32::Numeric/Num/=item unpolar>
448375ea »
2008-06-23 [spec] finer graded fudging of complex.t
114 #
115 # Test that unpolar() doesn't change the absolute value
626a59c1 »
2008-01-27 [rakudo] add directives to S29-num/ and convert pod to pod6
116
448375ea »
2008-06-23 [spec] finer graded fudging of complex.t
117 {
626a59c1 »
2008-01-27 [rakudo] add directives to S29-num/ and convert pod to pod6
118 my $counter = 1;
119 for 1..10 -> $abs {
120 for 1..10 -> $a {
72b072b6 »
2008-06-26 S29-num/complex.t: update #?rakudo skip markers for new passing tests
121 my $angle = 2 * $pi * $a / 10;
122 is_approx(abs($abs.unpolar($angle)), $abs,
626a59c1 »
2008-01-27 [rakudo] add directives to S29-num/ and convert pod to pod6
123 "unpolar doesn't change the absolute value (No $counter)");
124 $counter++;
125 }
ad1b86bb »
2008-01-24 [t] Test suite refactoring.
126 }
5fe1b881 »
2008-06-07 S29-num/complex.t: Update #?rakudo fudging.
127 }
ad1b86bb »
2008-01-24 [t] Test suite refactoring.
128
d1548163 »
2009-04-26 [t/spec] more smartlink fixing
129 # L<S32::Numeric/Num/=item unpolar>
576906b4 »
2009-01-31 [t] added named arg tests to trig and num functions
130 #?rakudo skip 'named args'
131 {
132 # Basic tests for unpolar()
133 my $s = 2 * sqrt(2);
134
135 is_approx(unpolar(:mag(4), 0), 4, "unpolar(:mag(4), 0) == 4");
136 is_approx(unpolar(:mag(4), $pi/4), $s + ($s)i ,"unpolar(:mag(4), pi/4) == 2+2i");
137 is_approx(unpolar(:mag(4), $pi/2), 4i, "unpolar(:mag(4), pi/2) == 4i");
138 is_approx(unpolar(:mag(4), 3*$pi/4), -$s + ($s)i,"unpolar(:mag(4), pi/4) == -2+2i");
139 is_approx(unpolar(:mag(4), $pi), -4, "unpolar(:mag(4), pi) == -4");
140 }
141
5fe1b881 »
2008-06-07 S29-num/complex.t: Update #?rakudo fudging.
142 {
626a59c1 »
2008-01-27 [rakudo] add directives to S29-num/ and convert pod to pod6
143 # Basic tests for unpolar()
26eada7e »
2008-06-30 [spec] S29-num/complex.t: fixed two tests
144 my $s = 2 * sqrt(2);
ad1b86bb »
2008-01-24 [t] Test suite refactoring.
145
4bb1f868 »
2008-06-05 [spec] complex.t: invalid uses of is_approx()
146 is_approx(4.unpolar(0), 4, "4.unpolar(0) == 4");
26eada7e »
2008-06-30 [spec] S29-num/complex.t: fixed two tests
147 is_approx(4.unpolar($pi/4), $s + ($s)i ,"4.unpolar(pi/4) == 2+2i");
4bb1f868 »
2008-06-05 [spec] complex.t: invalid uses of is_approx()
148 is_approx(4.unpolar($pi/2), 4i, "4.unpolar(pi/2) == 4i");
26eada7e »
2008-06-30 [spec] S29-num/complex.t: fixed two tests
149 is_approx(4.unpolar(3*$pi/4), -$s + ($s)i,"4.unpolar(pi/4) == -2+2i");
4bb1f868 »
2008-06-05 [spec] complex.t: invalid uses of is_approx()
150 is_approx(4.unpolar($pi), -4, "4.unpolar(pi) == -4");
626a59c1 »
2008-01-27 [rakudo] add directives to S29-num/ and convert pod to pod6
151 }
65127307 »
2009-03-09 [t/spec] test for Complex.re and .im
152
8acee941 »
2009-10-28 [t/spec] tests for RT #68848, complex powers wrapped in a subroutine
153
154 # used to be RT #68848
155 {
156 is_approx exp(3.0 * log(1i)), -1.83697e-16-1i,
157 'exp(3.0 * log(1i))';
158 sub iPower($a, $b) { exp($b * log($a)) };
159 is_approx iPower(1i, 3.0), -1.83697e-16-1i, 'same as wrapped as sub';
160
161 }
162
06c877b8 »
2009-09-30 [t/spec] Add some basic tests for complex addition and subtraction.
163 done_testing;
7f29bc53 »
2009-08-08 [t/spec] Add vim: lines everywhere.
164
165 # vim: ft=perl6
Something went wrong with that request. Please try again.