This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update bignum, Math::BigInt, Math::BigInt::FastCalc, and Math::BigRat
[perl5.git] / cpan / Math-BigRat / t / bitwise.t
CommitLineData
6853e8af 1# -*- mode: perl; -*-
11c955be 2
9aa0b648
FR
3use strict;
4use warnings;
11c955be 5
6320cdc0 6use Test::More tests => 2602;
9aa0b648 7
6320cdc0 8my @classes = ('Math::BigRat');
9aa0b648 9
6320cdc0
SH
10# We should test all the following operators:
11#
12# & | ^ << >> &= |= ^= <<= >>=
13#
14# as well as the corresponding methods
15#
16# band bior bxor blsft brsft
9aa0b648 17
6320cdc0
SH
18for my $class (@classes) {
19 use_ok($class);
20
21 for my $op (qw( & | ^ )) {
22 for (my $xscalar = 0 ; $xscalar <= 8 ; $xscalar += 0.5) {
23 for (my $yscalar = 0 ; $yscalar <= 8 ; $yscalar += 0.5) {
24
25 my $xint = int $xscalar;
26 my $yint = int $yscalar;
9aa0b648 27
6320cdc0
SH
28 my $x = $class -> new("$xscalar");
29 my $y = $class -> new("$yscalar");
30
31 my $test = "$x $op $y";
32 my $expected = eval "$xscalar $op $yscalar";
33 my $got = eval "\$x $op \$y";
34
35 is($@, '', 'is $@ empty');
36 isa_ok($got, $class, $test);
37 is($got, $expected,
38 "$x $op $y = $xint $op $yint = $expected");
39 }
40 }
41 }
42}