[inseparable changes from match from perl-5.003_97a to perl-5.003_97b]
[p5sagit/p5-mst-13.2.git] / t / lib / complex.t
index 5dcac6c..310e6f5 100755 (executable)
@@ -2,19 +2,21 @@
 
 # $RCSfile$
 #
-# Regression tests for the new Math::Complex pacakge
-# -- Raphael Manfredi, Septemeber 1996
-# -- Jarkko Hietaniemi Manfredi, March 1997
+# Regression tests for the Math::Complex pacakge
+# -- Raphael Manfredi, September 1996
+# -- Jarkko Hietaniemi, March-April 1997
+
 BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
 }
+
 use Math::Complex;
 
 $test = 0;
 $| = 1;
-$script = '';
-my $eps = 1e-4; # for example root() is quite bad
+@script = ();
+my $eps = 1e-11;
 
 while (<DATA>) {
        s/^\s+//;
@@ -47,8 +49,40 @@ while (<DATA>) {
        }
 }
 
+# test the divbyzeros
+
+test_dbz(
+        'i/0',
+#       'tan(pi/2)',   # may succeed thanks to floating point inaccuracies
+#       'sec(pi/2)',   # may succeed thanks to floating point inaccuracies
+        'csc(0)',
+        'cot(0)',
+        'atan(i)',
+        'asec(0)',
+        'acsc(0)',
+        'acot(i)',
+#       'tanh(pi/2)',  # may succeed thanks to floating point inaccuracies
+#       'sech(pi/2)',  # may succeed thanks to floating point inaccuracies
+        'csch(0)',
+        'coth(0)',
+        'atanh(1)',
+        'asech(0)',
+        'acsch(0)',
+        'acoth(1)'
+       );
+
+sub test_dbz {
+    for my $op (@_) {
+       $test++;
+
+       push(@script, qq(eval '$op';));
+       push(@script, qq(print 'not ' unless (\$@ =~ /Division by zero/);));
+       push(@script, qq(print "ok $test\n";));
+    }
+}
+
 print "1..$test\n";
-eval $script;
+eval join '', @script;
 die $@ if $@;
 
 sub test {
@@ -57,13 +91,13 @@ sub test {
        my $i;
        for ($i = 0; $i < @args; $i++) {
                $val = value($args[$i]);
-               $script .= "\$z$i = $val;\n";
+               push @script, "\$z$i = $val;\n";
        }
        if (defined $z) {
                $args = "'$op'";                # Really the value
                $try = "abs(\$z0 - \$z1) <= $eps ? \$z1 : \$z0";
-               $script .= "\$res = $try; ";
-               $script .= "check($test, $args[0], \$res, \$z$#args, $args);\n";
+               push @script, "\$res = $try; ";
+               push @script, "check($test, $args[0], \$res, \$z$#args, $args);\n";
        } else {
                my ($try, $args);
                if (@args == 2) {
@@ -73,8 +107,8 @@ sub test {
                        $try = ($op =~ /^\w/) ? "$op(\$z0, \$z1)" : "\$z0 $op \$z1";
                        $args = "'$args[0]', '$args[1]'";
                }
-               $script .= "\$res = $try; ";
-               $script .= "check($test, '$try', \$res, \$z$#args, $args);\n";
+               push @script, "\$res = $try; ";
+               push @script, "check($test, '$try', \$res, \$z$#args, $args);\n";
        }
 }
 
@@ -88,8 +122,8 @@ sub set {
        for ($i = 0; $i < @set; $i++) {
                push(@{$valref}, $set[$i]);
                my $val = value($set[$i]);
-               $script .= "\$s$i = $val;\n";
-               push(@{$setref}, "\$s$i");
+               push @script, "\$s$i = $val;\n";
+               push @{$setref}, "\$s$i";
        }
 }