use strict;
use warnings;
-use Test::More tests => 22;
+use Test::More tests => 2602;
-use Math::BigRat;
+my @classes = ('Math::BigRat');
-my $x = Math::BigRat->new('3/7');
+# We should test all the following operators:
+#
+# & | ^ << >> &= |= ^= <<= >>=
+#
+# as well as the corresponding methods
+#
+# band bior bxor blsft brsft
-for my $op (qw(& | ^ << >> &= |= ^= <<= >>=)) {
- my $test = "\$y = \$x $op 42";
- ok(!eval "my \$y = \$x $op 42; 1", $test);
- like($@, qr/^bitwise operation \Q$op\E not supported in Math::BigRat/,
- $test);
-}
+for my $class (@classes) {
+ use_ok($class);
+
+ for my $op (qw( & | ^ )) {
+ for (my $xscalar = 0 ; $xscalar <= 8 ; $xscalar += 0.5) {
+ for (my $yscalar = 0 ; $yscalar <= 8 ; $yscalar += 0.5) {
+
+ my $xint = int $xscalar;
+ my $yint = int $yscalar;
-my $test = "\$y = ~\$x";
-ok(!eval "my \$y = ~\$x; 1", $test);
-like($@, qr/^bitwise operation ~ not supported in Math::BigRat/, $test);
+ my $x = $class -> new("$xscalar");
+ my $y = $class -> new("$yscalar");
+
+ my $test = "$x $op $y";
+ my $expected = eval "$xscalar $op $yscalar";
+ my $got = eval "\$x $op \$y";
+
+ is($@, '', 'is $@ empty');
+ isa_ok($got, $class, $test);
+ is($got, $expected,
+ "$x $op $y = $xint $op $yint = $expected");
+ }
+ }
+ }
+}