1N/A#!/usr/bin/perl -w
1N/A
1N/A# test calling conventions, and :constant overloading
1N/A
1N/Ause strict;
1N/Ause Test;
1N/A
1N/ABEGIN
1N/A {
1N/A $| = 1;
1N/A # to locate the testing files
1N/A my $location = $0; $location =~ s/calling.t//i;
1N/A if ($ENV{PERL_CORE})
1N/A {
1N/A # testing with the core distribution
1N/A @INC = qw(../lib);
1N/A }
1N/A else
1N/A {
1N/A unshift @INC, '../lib';
1N/A }
1N/A if (-d 't')
1N/A {
1N/A chdir 't';
1N/A require File::Spec;
1N/A unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
1N/A }
1N/A else
1N/A {
1N/A unshift @INC, $location;
1N/A }
1N/A print "# INC = @INC\n";
1N/A my $tests = 160;
1N/A plan tests => $tests;
1N/A if ($] < 5.006)
1N/A {
1N/A for (1..$tests) { skip (1,'Not supported on older Perls'); }
1N/A exit;
1N/A }
1N/A }
1N/A
1N/Apackage Math::BigInt::Test;
1N/A
1N/Ause Math::BigInt;
1N/Ause vars qw/@ISA/;
1N/A@ISA = qw/Math::BigInt/; # child of MBI
1N/Ause overload;
1N/A
1N/Apackage Math::BigFloat::Test;
1N/A
1N/Ause Math::BigFloat;
1N/Ause vars qw/@ISA/;
1N/A@ISA = qw/Math::BigFloat/; # child of MBI
1N/Ause overload;
1N/A
1N/Apackage main;
1N/A
1N/Ause Math::BigInt;
1N/Ause Math::BigFloat;
1N/A
1N/Amy ($x,$y,$z,$u);
1N/Amy $version = '1.61'; # adjust manually to match latest release
1N/A
1N/A###############################################################################
1N/A# check whether op's accept normal strings, even when inherited by subclasses
1N/A
1N/A# do one positive and one negative test to avoid false positives by "accident"
1N/A
1N/Amy ($func,@args,$ans,$rc,$class,$try);
1N/Awhile (<DATA>)
1N/A {
1N/A chomp;
1N/A next if /^#/; # skip comments
1N/A if (s/^&//)
1N/A {
1N/A $func = $_;
1N/A }
1N/A else
1N/A {
1N/A @args = split(/:/,$_,99);
1N/A $ans = pop @args;
1N/A foreach $class (qw/
1N/A Math::BigInt Math::BigFloat Math::BigInt::Test Math::BigFloat::Test/)
1N/A {
1N/A $try = "'$args[0]'"; # quote it
1N/A $try = $args[0] if $args[0] =~ /'/; # already quoted
1N/A $try = '' if $args[0] eq ''; # undef, no argument
1N/A $try = "$class\->$func($try);";
1N/A $rc = eval $try;
1N/A print "# Tried: '$try'\n" if !ok ($rc, $ans);
1N/A }
1N/A }
1N/A
1N/A }
1N/A
1N/A$class = 'Math::BigInt';
1N/A
1N/A# XXX TODO this test does not work/fail.
1N/A# test whether use Math::BigInt qw/version/ works
1N/A#$try = "use $class ($version.'1');";
1N/A#$try .= ' $x = $class->new(123); $x = "$x";';
1N/A#eval $try;
1N/A#ok_undef ( $x ); # should result in error!
1N/A
1N/A# test whether fallback to calc works
1N/A$try = "use $class ($version,'lib','foo, bar , ');";
1N/A$try .= "$class\->config()->{lib};";
1N/A$ans = eval $try;
1N/Aok ( $ans, "Math::BigInt::Calc");
1N/A
1N/A# test whether constant works or not, also test for qw($version)
1N/A# bgcd() is present in subclass, too
1N/A$try = "use Math::BigInt ($version,'bgcd',':constant');";
1N/A$try .= ' $x = 2**150; bgcd($x); $x = "$x";';
1N/A$ans = eval $try;
1N/Aok ( $ans, "1427247692705959881058285969449495136382746624");
1N/A
1N/A# test wether Math::BigInt::Scalar via use works (w/ dff. spellings of calc)
1N/A$try = "use $class ($version,'lib','Scalar');";
1N/A$try .= ' $x = 2**10; $x = "$x";';
1N/A$ans = eval $try; ok ( $ans, "1024");
1N/A$try = "use $class ($version,'LiB','$class\::Scalar');";
1N/A$try .= ' $x = 2**10; $x = "$x";';
1N/A$ans = eval $try; ok ( $ans, "1024");
1N/A
1N/A# all done
1N/A
1N/A###############################################################################
1N/A# Perl 5.005 does not like ok ($x,undef)
1N/A
1N/Asub ok_undef
1N/A {
1N/A my $x = shift;
1N/A
1N/A ok (1,1) and return if !defined $x;
1N/A ok ($x,'undef');
1N/A }
1N/A
1N/A__END__
1N/A&is_zero
1N/A1:0
1N/A0:1
1N/A&is_one
1N/A1:1
1N/A0:0
1N/A&is_positive
1N/A1:1
1N/A-1:0
1N/A&is_negative
1N/A1:0
1N/A-1:1
1N/A&is_nan
1N/Aabc:1
1N/A1:0
1N/A&is_inf
1N/Ainf:1
1N/A0:0
1N/A&bstr
1N/A5:5
1N/A10:10
1N/A-10:-10
1N/Aabc:NaN
1N/A'+inf':inf
1N/A'-inf':-inf
1N/A&bsstr
1N/A1:1e+0
1N/A0:0e+1
1N/A2:2e+0
1N/A200:2e+2
1N/A-5:-5e+0
1N/A-100:-1e+2
1N/Aabc:NaN
1N/A'+inf':inf
1N/A&babs
1N/A-1:1
1N/A1:1
1N/A&bnot
1N/A-2:1
1N/A1:-2
1N/A&bzero
1N/A:0
1N/A&bnan
1N/A:NaN
1N/Aabc:NaN
1N/A&bone
1N/A:1
1N/A'+':1
1N/A'-':-1
1N/A&binf
1N/A:inf
1N/A'+':inf
1N/A'-':-inf