summaryrefslogtreecommitdiff
path: root/cpan/Math-BigRat/t/bitwise.t
blob: 6bd499fa51efbb57cff0f5a319a43ea8087f133d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!perl

use strict;
use warnings;

use Test::More tests => 2602;

my @classes = ('Math::BigRat');

# We should test all the following operators:
#
#     & | ^ << >> &= |= ^= <<= >>=
#
# as well as the corresponding methods
#
#     band bior bxor blsft brsft

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 $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");
            }
        }
    }
}