5 # Regression tests for the new Math::Complex pacakge
6 # -- Raphael Manfredi, Sept 1996
19 next if /^#/ || /^\s*$/;
21 $set_test = 0; # Assume not a test over a set of values
27 set($1, \@set, \@val);
31 $set_test = 1; # Requests we loop over the set...
33 my @args = split(/:/);
36 for ($i = 0; $i < @set; $i++) {
37 $target = $set[$i]; # complex number
38 $zvalue = $val[$i]; # textual value as found in set definition
39 test($zvalue, $target, @args);
42 test($op, undef, @args);
51 my ($op, $z, @args) = @_;
54 for ($i = 0; $i < @args; $i++) {
55 $val = value($args[$i]);
56 $script .= "\$z$i = $val;\n";
59 $args = "'$op'"; # Really the value
60 $try = "abs(\$z0 - \$z1) <= 1e-10 ? \$z1 : \$z0";
61 $script .= "\$res = $try; ";
62 $script .= "check($test, $args[0], \$res, \$z$#args, $args);\n";
69 $try = ($op =~ /^\w/) ? "$op(\$z0, \$z1)" : "\$z0 $op \$z1";
70 $args = "'$args[0]', '$args[1]'";
72 $script .= "\$res = $try; ";
73 $script .= "check($test, '$try', \$res, \$z$#args, $args);\n";
78 my ($set, $setref, $valref) = @_;
81 my @set = split(/;\s*/, $set);
84 for ($i = 0; $i < @set; $i++) {
85 push(@{$valref}, $set[$i]);
86 my $val = value($set[$i]);
87 $script .= "\$s$i = $val;\n";
88 push(@{$setref}, "\$s$i");
94 if (/^\s*\((.*),(.*)\)/) {
97 elsif (/^\s*\[(.*),(.*)\]/) {
98 return "cplxe($1,$2)";
100 elsif (/^\s*'(.*)'/) {
102 $ex =~ s/\bz\b/$target/g;
103 $ex =~ s/\br\b/abs($target)/g;
104 $ex =~ s/\bt\b/arg($target)/g;
105 $ex =~ s/\ba\b/Re($target)/g;
106 $ex =~ s/\bb\b/Im($target)/g;
109 elsif (/^\s*"(.*)"/) {
116 my ($test, $try, $got, $expected, @z) = @_;
117 if ("$got" eq "$expected" || ($expected =~ /^-?\d/ && $got == $expected)) {
120 print "not ok $test\n";
121 my $args = (@z == 1) ? "z = $z[0]" : "z0 = $z[0], z1 = $z[1]";
122 print "# '$try' expected: '$expected' got: '$got' for $args\n";
151 [2,2*pi/3]:(1,0):[2,2*pi/3]
163 [4,pi]:[2,pi/2]:[2,pi/2]
164 [2,pi/2]:[4,pi]:[0.5,-(pi)/2]
203 [6, -2*pi/3]:"[6,-2pi/3]"
204 [0.5, -9*pi/11]:"[0.5,-9pi/11]"
206 { (4,3); [3,2]; (-3,4); (0,2); [2,1] }
209 |'z - ~z':'2*i*Im(z)'
210 |'z * ~z':'abs(z) * abs(z)'
212 { (4,3); [3,2]; (-3,4); (0,2); 3; 1; (-5, 0); [2,1] }
214 |'exp(z)':'exp(a) * exp(i * b)'
216 |'sqrt(z) * sqrt(z)':'z'
217 |'sqrt(z)':'sqrt(r) * exp(i * t/2)'
218 |'cbrt(z)':'cbrt(r) * exp(i * t/3)'
219 |'log(z)':'log(r) + i*t'
223 |'cotan(acotan(z))':'z'
224 |'cos(z) ** 2 + sin(z) ** 2':1
225 |'cosh(z) ** 2 - sinh(z) ** 2':1
226 |'cos(z)':'cosh(i*z)'
227 |'cotan(z)':'1 / tan(z)'
228 |'cotanh(z)':'1 / tanh(z)'
229 |'i*sin(z)':'sinh(i*z)'
230 |'z**z':'exp(z * log(z))'
233 |'log10(z)':'log(z) / log(10)'
234 |'logn(z, 3)':'log(z) / log(3)'
235 |'logn(z, 2)':'log(z) / log(2)'
236 |'(root(z, 4))[1] ** 4':'z'
237 |'(root(z, 8))[7] ** 8':'z'
239 { (1,1); [1,0.5]; (-2, -1); 2; (-1,0.5); (0,0.5); 0.5; (2, 0) }
241 |'sinh(asinh(z))':'z'
242 |'cosh(acosh(z))':'z'
243 |'tanh(atanh(z))':'z'
244 |'cotanh(acotanh(z))':'z'
246 { (0.2,-0.4); [1,0.5]; -1.2; (-1,0.5); (0,-0.5); 0.5; (1.1, 0) }
249 |'acos(cos(z)) ** 2':'z * z'
251 |'asinh(sinh(z))':'z'
252 |'acosh(cosh(z)) ** 2':'z * z'
253 |'atanh(tanh(z))':'z'