xref: /openbsd-src/gnu/usr.bin/perl/cpan/Math-BigInt/t/bitwise-mbr.t (revision 5486feefcc8cb79b19e014ab332cc5dfd05b3b33)
1*5486feefSafresh1# -*- mode: perl; -*-
2*5486feefSafresh1
3*5486feefSafresh1use strict;
4*5486feefSafresh1use warnings;
5*5486feefSafresh1
6*5486feefSafresh1use Test::More tests => 2602;
7*5486feefSafresh1
8*5486feefSafresh1my @classes = ('Math::BigRat');
9*5486feefSafresh1
10*5486feefSafresh1# We should test all the following operators:
11*5486feefSafresh1#
12*5486feefSafresh1#     & | ^ << >> &= |= ^= <<= >>=
13*5486feefSafresh1#
14*5486feefSafresh1# as well as the corresponding methods
15*5486feefSafresh1#
16*5486feefSafresh1#     band bior bxor blsft brsft
17*5486feefSafresh1
18*5486feefSafresh1for my $class (@classes) {
19*5486feefSafresh1    use_ok($class);
20*5486feefSafresh1
21*5486feefSafresh1    for my $op (qw( & | ^ )) {
22*5486feefSafresh1        for (my $xscalar = 0 ; $xscalar <= 8 ; $xscalar += 0.5) {
23*5486feefSafresh1            for (my $yscalar = 0 ; $yscalar <= 8 ; $yscalar += 0.5) {
24*5486feefSafresh1
25*5486feefSafresh1                my $xint = int $xscalar;
26*5486feefSafresh1                my $yint = int $yscalar;
27*5486feefSafresh1
28*5486feefSafresh1                my $x = $class -> new("$xscalar");
29*5486feefSafresh1                my $y = $class -> new("$yscalar");
30*5486feefSafresh1
31*5486feefSafresh1                my $test     = "$x $op $y";
32*5486feefSafresh1                my $expected = eval "$xscalar $op $yscalar";
33*5486feefSafresh1                my $got      = eval "\$x $op \$y";
34*5486feefSafresh1
35*5486feefSafresh1                is($@, '', 'is $@ empty');
36*5486feefSafresh1                isa_ok($got, $class, $test);
37*5486feefSafresh1                is($got, $expected,
38*5486feefSafresh1                   "$x $op $y = $xint $op $yint = $expected");
39*5486feefSafresh1            }
40*5486feefSafresh1        }
41*5486feefSafresh1    }
42*5486feefSafresh1}
43