5 # Regression tests for the Math::Complex pacakge
6 # -- Raphael Manfredi, September 1996
7 # -- Jarkko Hietaniemi, March-April 1997
23 next if $_ eq '' || /^\#/;
25 $test_set = 0; # Assume not a test over a set of values
31 set($1, \@set, \@val);
35 $test_set = 1; # Requests we loop over the set...
37 my @args = split(/:/);
40 for ($i = 0; $i < @set; $i++) {
43 # textual value as found in set definition
45 test($zvalue, $target, @args);
48 test($op, undef, @args);
56 # 'tan(pi/2)', # may succeed thanks to floating point inaccuracies
57 # 'sec(pi/2)', # may succeed thanks to floating point inaccuracies
64 # 'tanh(pi/2)', # may succeed thanks to floating point inaccuracies
65 # 'sech(pi/2)', # may succeed thanks to floating point inaccuracies
78 push(@script, qq(eval '$op';));
79 push(@script, qq(print 'not ' unless (\$@ =~ /Division by zero/);));
80 push(@script, qq(print "ok $test\n";));
85 eval join '', @script;
89 my ($op, $z, @args) = @_;
92 for ($i = 0; $i < @args; $i++) {
93 $val = value($args[$i]);
94 push @script, "\$z$i = $val;\n";
97 $args = "'$op'"; # Really the value
98 $try = "abs(\$z0 - \$z1) <= $eps ? \$z1 : \$z0";
99 push @script, "\$res = $try; ";
100 push @script, "check($test, $args[0], \$res, \$z$#args, $args);\n";
105 $args = "'$args[0]'";
107 $try = ($op =~ /^\w/) ? "$op(\$z0, \$z1)" : "\$z0 $op \$z1";
108 $args = "'$args[0]', '$args[1]'";
110 push @script, "\$res = $try; ";
111 push @script, "check($test, '$try', \$res, \$z$#args, $args);\n";
116 my ($set, $setref, $valref) = @_;
119 my @set = split(/;\s*/, $set);
122 for ($i = 0; $i < @set; $i++) {
123 push(@{$valref}, $set[$i]);
124 my $val = value($set[$i]);
125 push @script, "\$s$i = $val;\n";
126 push @{$setref}, "\$s$i";
132 if (/^\s*\((.*),(.*)\)/) {
133 return "cplx($1,$2)";
135 elsif (/^\s*\[(.*),(.*)\]/) {
136 return "cplxe($1,$2)";
138 elsif (/^\s*'(.*)'/) {
140 $ex =~ s/\bz\b/$target/g;
141 $ex =~ s/\br\b/abs($target)/g;
142 $ex =~ s/\bt\b/arg($target)/g;
143 $ex =~ s/\ba\b/Re($target)/g;
144 $ex =~ s/\bb\b/Im($target)/g;
147 elsif (/^\s*"(.*)"/) {
154 my ($test, $try, $got, $expected, @z) = @_;
158 if ("$got" eq "$expected"
160 ($expected =~ /^-?\d/ && $got == $expected)
162 (abs($got - $expected) < $eps)
166 print "not ok $test\n";
167 my $args = (@z == 1) ? "z = $z[0]" : "z0 = $z[0], z1 = $z[1]";
168 print "# '$try' expected: '$expected' got: '$got' for $args\n";
197 [2,2*pi/3]:(1,0):[2,2*pi/3]
209 [4,pi]:[2,pi/2]:[2,pi/2]
210 [2,pi/2]:[4,pi]:[0.5,-(pi)/2]
264 [6, -2*pi/3]:"[6,-2pi/3]"
265 [0.5, -9*pi/11]:"[0.5,-9pi/11]"
267 { (4,3); [3,2]; (-3,4); (0,2); [2,1] }
270 |'z - ~z':'2*i*Im(z)'
271 |'z * ~z':'abs(z) * abs(z)'
273 { (2,3); [3,2]; (-3,2); (0,2); 3; 1.2; -3; (-3, 0); (-2, -1); [2,1] }
275 |'(root(z, 4))[1] ** 4':'z'
276 |'(root(z, 5))[3] ** 5':'z'
277 |'(root(z, 8))[7] ** 8':'z'
279 |'acot(z)':'acotan(z)'
280 |'acsc(z)':'acosec(z)'
281 |'acsc(z)':'asin(1 / z)'
282 |'asec(z)':'acos(1 / z)'
283 |'cbrt(z)':'cbrt(r) * exp(i * t/3)'
285 |'cos(z) ** 2 + sin(z) ** 2':1
286 |'cos(z)':'cosh(i*z)'
287 |'cosh(z) ** 2 - sinh(z) ** 2':1
289 |'cot(z)':'1 / tan(z)'
292 |'csc(z)':'1 / sin(z)'
295 |'exp(z)':'exp(a) * exp(i * b)'
298 |'log(z)':'log(r) + i*t'
299 |'log10(z)':'log(z) / log(10)'
300 |'logn(z, 2)':'log(z) / log(2)'
301 |'logn(z, 3)':'log(z) / log(3)'
303 |'sec(z)':'1 / cos(z)'
305 |'sin(i * z)':'i * sinh(z)'
306 |'sqrt(z) * sqrt(z)':'z'
307 |'sqrt(z)':'sqrt(r) * exp(i * t/2)'
309 |'z**z':'exp(z * log(z))'
311 { (1,1); [1,0.5]; (-2, -1); 2; -3; (-1,0.5); (0,0.5); 0.5; (2, 0); (-1, -2) }
313 |'cosh(acosh(z))':'z'
314 |'coth(acoth(z))':'z'
315 |'coth(z)':'1 / tanh(z)'
316 |'coth(z)':'cotanh(z)'
317 |'csch(acsch(z))':'z'
318 |'csch(z)':'1 / sinh(z)'
319 |'csch(z)':'cosech(z)'
320 |'sech(asech(z))':'z'
321 |'sech(z)':'1 / cosh(z)'
322 |'sinh(asinh(z))':'z'
323 |'tanh(atanh(z))':'z'
325 { (0.2,-0.4); [1,0.5]; -1.2; (-1,0.5); 0.5; (1.1, 0) }
327 |'acos(cos(z)) ** 2':'z * z'
328 |'acosh(cosh(z)) ** 2':'z * z'
329 |'acoth(z)':'acotanh(z)'
330 |'acoth(z)':'atanh(1 / z)'
331 |'acsch(z)':'acosech(z)'
332 |'acsch(z)':'asinh(1 / z)'
333 |'asech(z)':'acosh(1 / z)'
335 |'asinh(sinh(z))':'z'
337 |'atanh(tanh(z))':'z'
340 ( 2, 3):( 9.15449914691143, -4.16890695996656)
341 (-2, 3):( -9.15449914691143, -4.16890695996656)
342 (-2,-3):( -9.15449914691143, 4.16890695996656)
343 ( 2,-3):( 9.15449914691143, 4.16890695996656)
346 ( 2, 3):( -4.18962569096881, -9.10922789375534)
347 (-2, 3):( -4.18962569096881, 9.10922789375534)
348 (-2,-3):( -4.18962569096881, -9.10922789375534)
349 ( 2,-3):( -4.18962569096881, 9.10922789375534)
352 ( 2, 3):( -0.00376402564150, 1.00323862735361)
353 (-2, 3):( 0.00376402564150, 1.00323862735361)
354 (-2,-3):( 0.00376402564150, -1.00323862735361)
355 ( 2,-3):( -0.00376402564150, -1.00323862735361)
358 ( 2, 3):( -0.04167496441114, 0.09061113719624)
359 (-2, 3):( -0.04167496441114, -0.09061113719624)
360 (-2,-3):( -0.04167496441114, 0.09061113719624)
361 ( 2,-3):( -0.04167496441114, -0.09061113719624)
364 ( 2, 3):( 0.09047320975321, 0.04120098628857)
365 (-2, 3):( -0.09047320975321, 0.04120098628857)
366 (-2,-3):( -0.09047320975321, -0.04120098628857)
367 ( 2,-3):( 0.09047320975321, -0.04120098628857)
370 ( 2, 3):( -0.00373971037634, -0.99675779656936)
371 (-2, 3):( 0.00373971037634, -0.99675779656936)
372 (-2,-3):( 0.00373971037634, 0.99675779656936)
373 ( 2,-3):( -0.00373971037634, 0.99675779656936)
376 ( 2, 3):( 0.57065278432110, 1.98338702991654)
377 (-2, 3):( -0.57065278432110, 1.98338702991654)
378 (-2,-3):( -0.57065278432110, -1.98338702991654)
379 ( 2,-3):( 0.57065278432110, -1.98338702991654)
382 ( 2, 3):( 1.00014354247380, -1.98338702991654)
383 (-2, 3):( 2.14144911111600, -1.98338702991654)
384 (-2,-3):( 2.14144911111600, 1.98338702991654)
385 ( 2,-3):( 1.00014354247380, 1.98338702991654)
388 ( 2, 3):( 1.40992104959658, 0.22907268296854)
389 (-2, 3):( -1.40992104959658, 0.22907268296854)
390 (-2,-3):( -1.40992104959658, -0.22907268296854)
391 ( 2,-3):( 1.40992104959658, -0.22907268296854)
394 ( 2, 3):( 1.42041072246703, 0.23133469857397)
395 (-2, 3):( 1.72118193112276, 0.23133469857397)
396 (-2,-3):( 1.72118193112276, -0.23133469857397)
397 ( 2,-3):( 1.42041072246703, -0.23133469857397)
400 ( 2, 3):( 0.15038560432786, -0.23133469857397)
401 (-2, 3):( -0.15038560432786, -0.23133469857397)
402 (-2,-3):( -0.15038560432786, 0.23133469857397)
403 ( 2,-3):( 0.15038560432786, 0.23133469857397)
406 ( 2, 3):( 0.16087527719832, -0.22907268296854)
407 (-2, 3):( -0.16087527719832, -0.22907268296854)
408 (-2,-3):( -0.16087527719832, 0.22907268296854)
409 ( 2,-3):( 0.16087527719832, 0.22907268296854)
412 ( 2, 3):( -3.59056458998578, 0.53092108624852)
413 (-2, 3):( 3.59056458998578, 0.53092108624852)
414 (-2,-3):( 3.59056458998578, -0.53092108624852)
415 ( 2,-3):( -3.59056458998578, -0.53092108624852)
418 ( 2, 3):( -3.72454550491532, 0.51182256998738)
419 (-2, 3):( -3.72454550491532, -0.51182256998738)
420 (-2,-3):( -3.72454550491532, 0.51182256998738)
421 ( 2,-3):( -3.72454550491532, -0.51182256998738)
424 ( 2, 3):( 0.96538587902213, -0.00988437503832)
425 (-2, 3):( -0.96538587902213, -0.00988437503832)
426 (-2,-3):( -0.96538587902213, 0.00988437503832)
427 ( 2,-3):( 0.96538587902213, 0.00988437503832)
430 ( 2, 3):( -0.26351297515839, -0.03621163655877)
431 (-2, 3):( -0.26351297515839, 0.03621163655877)
432 (-2,-3):( -0.26351297515839, -0.03621163655877)
433 ( 2,-3):( -0.26351297515839, 0.03621163655877)
436 ( 2, 3):( -0.27254866146294, -0.04030057885689)
437 (-2, 3):( 0.27254866146294, -0.04030057885689)
438 (-2,-3):( 0.27254866146294, 0.04030057885689)
439 ( 2,-3):( -0.27254866146294, 0.04030057885689)
442 ( 2, 3):( 1.03574663776500, 0.01060478347034)
443 (-2, 3):( -1.03574663776500, 0.01060478347034)
444 (-2,-3):( -1.03574663776500, -0.01060478347034)
445 ( 2,-3):( 1.03574663776500, -0.01060478347034)
448 ( 2, 3):( 1.96863792579310, 0.96465850440760)
449 (-2, 3):( -1.96863792579310, 0.96465850440761)
450 (-2,-3):( -1.96863792579310, -0.96465850440761)
451 ( 2,-3):( 1.96863792579310, -0.96465850440760)
454 ( 2, 3):( 1.98338702991654, 1.00014354247380)
455 (-2, 3):( -1.98338702991653, -2.14144911111600)
456 (-2,-3):( -1.98338702991653, 2.14144911111600)
457 ( 2,-3):( 1.98338702991654, -1.00014354247380)
460 ( 2, 3):( 0.14694666622553, 1.33897252229449)
461 (-2, 3):( -0.14694666622553, 1.33897252229449)
462 (-2,-3):( -0.14694666622553, -1.33897252229449)
463 ( 2,-3):( 0.14694666622553, -1.33897252229449)
466 ( 2, 3):( 0.23133469857397, -1.42041072246703)
467 (-2, 3):( -0.23133469857397, 1.72118193112276)
468 (-2,-3):( -0.23133469857397, -1.72118193112276)
469 ( 2,-3):( 0.23133469857397, 1.42041072246703)
472 ( 2, 3):( 0.15735549884499, -0.22996290237721)
473 (-2, 3):( -0.15735549884499, -0.22996290237721)
474 (-2,-3):( -0.15735549884499, 0.22996290237721)
475 ( 2,-3):( 0.15735549884499, 0.22996290237721)
478 ( 2, 3):( 0.14694666622553, -0.23182380450040)
479 (-2, 3):( -0.14694666622553, -0.23182380450040)
480 (-2,-3):( -0.14694666622553, 0.23182380450040)
481 ( 2,-3):( 0.14694666622553, 0.23182380450040)