Commit | Line | Data |
ee15d750 |
1 | #!/usr/bin/perl -w |
2 | |
3 | # test calling conventions |
4 | |
5 | use strict; |
6 | use Test; |
7 | |
8 | BEGIN |
9 | { |
10 | $| = 1; |
11 | # chdir 't' if -d 't'; |
12 | unshift @INC, '../lib'; # for running manually |
13 | plan tests => 100; |
14 | } |
15 | |
16 | package Math::BigInt::Test; |
17 | |
18 | use Math::BigInt; |
19 | use vars qw/@ISA/; |
20 | @ISA = qw/Math::BigInt/; # child of MBI |
21 | use overload; |
22 | |
23 | package Math::BigFloat::Test; |
24 | |
25 | use Math::BigFloat; |
26 | use vars qw/@ISA/; |
27 | @ISA = qw/Math::BigFloat/; # child of MBI |
28 | use overload; |
29 | |
30 | package main; |
31 | |
32 | use Math::BigInt; |
33 | use Math::BigFloat; |
34 | |
35 | my ($x,$y,$z,$u); |
36 | |
37 | ############################################################################### |
38 | # check whether op's accept normal strings, even when inherited by subclasses |
39 | |
40 | # do one positive and one negative test to avoid false positives by "accident" |
41 | |
42 | my ($func,@args,$ans,$rc,$class,$try); |
43 | while (<DATA>) |
44 | { |
45 | chop; |
46 | next if /^#/; # skip comments |
47 | if (s/^&//) |
48 | { |
49 | $func = $_; |
50 | } |
51 | else |
52 | { |
53 | @args = split(/:/,$_,99); |
54 | $ans = pop @args; |
55 | foreach $class (qw/ |
56 | Math::BigInt Math::BigFloat Math::BigInt::Test Math::BigFloat::Test/) |
57 | { |
58 | $try = "$class\->$func('$args[0]');"; |
59 | $rc = eval $try; |
60 | print "# Tried: '$try'\n" if !ok ($rc, $ans); |
61 | } |
62 | } |
63 | |
64 | } |
65 | |
66 | # all done |
67 | |
68 | ############################################################################### |
69 | # Perl 5.005 does not like ok ($x,undef) |
70 | |
71 | sub ok_undef |
72 | { |
73 | my $x = shift; |
74 | |
75 | ok (1,1) and return if !defined $x; |
76 | ok ($x,'undef'); |
77 | } |
78 | |
79 | __END__ |
80 | &is_zero |
81 | 1:0 |
82 | 0:1 |
83 | &is_one |
84 | 1:1 |
85 | 0:0 |
86 | &is_positive |
87 | 1:1 |
88 | -1:0 |
89 | &is_negative |
90 | 1:0 |
91 | -1:1 |
92 | &is_nan |
93 | abc:1 |
94 | 1:0 |
95 | &is_inf |
96 | inf:1 |
97 | 0:0 |
98 | &bstr |
99 | 5:5 |
100 | 10:10 |
101 | abc:NaN |
102 | +inf:inf |
103 | -inf:-inf |
104 | &bsstr |
105 | 1:1e+0 |
106 | 0:0e+1 |
107 | 2:2e+0 |
108 | 200:2e+2 |
109 | &babs |
110 | -1:1 |
111 | 1:1 |
112 | &bnot |
113 | -2:1 |
114 | 1:-2 |