1
# Before `make install' is performed this script should be runnable with
2
# `make test'. After `make install' it should work as `perl test.pl'
4
################## We start with some black magic to print on failure.
6
BEGIN { $| = 1; print "1..11\n"; }
7
END {print "not ok 1\n" unless $loaded;}
8
use Math::Round qw(:all);
12
################## End of black magic.
16
#--- Both scalar and list contexts are tested.
17
print "round............";
18
was_it_ok(2, round(2.4) == 2 &&
21
eq2(round(-3.9, -2.5), -4, -3) );
23
print "round_even.......";
24
was_it_ok(3, round_even(2.4) == 2 &&
25
round_even(2.5) == 2 &&
26
eq2(round_even(-2.6, 3.5), -3, 4) );
28
print "round_odd........";
29
was_it_ok(4, round_odd(16.4) == 16 &&
30
round_odd(16.5) == 17 &&
31
round_odd(16.6) == 17 &&
32
eq2(round_odd(-16.7, 17.5), -17, 17) );
34
print "round_rand.......";
35
was_it_ok(5, round_rand(16.4) == 16 &&
36
round_rand(16.6) == 17 &&
37
eq2(round_rand(-17.8, -29.2), -18, -29) );
39
print "nearest..........";
40
was_it_ok(6, nearest(20, 9) == 0 &&
41
nearest(20, 10) == 20 &&
42
nearest(20, 11) == 20 &&
43
sprintf("%.2f", nearest(0.01, 16.575)) eq "16.58" &&
44
eq2(nearest(20, -98, -110), -100, -120) );
46
print "nearest_ceil.....";
47
was_it_ok(7, nearest_ceil(20, 9) == 0 &&
48
nearest_ceil(20, 10) == 20 &&
49
nearest_ceil(20, 11) == 20 &&
50
eq2(nearest_ceil(20, -98, -110), -100, -100) );
52
print "nearest_floor....";
53
was_it_ok(8, nearest_floor(20, 9) == 0 &&
54
nearest_floor(20, 10) == 0 &&
55
nearest_floor(20, 11) == 20 &&
56
eq2(nearest_floor(20, -98, -110), -100, -120) );
58
print "nearest_rand.....";
59
was_it_ok(9, nearest_rand(30, 44) == 30 &&
60
nearest_rand(30, 46) == 60 &&
61
eq2(nearest_rand(30, -76, -112), -90, -120) );
63
print "nlowmult.........";
64
was_it_ok(10, nlowmult(10, 44) == 40 &&
65
nlowmult(10, 46) == 40 &&
66
eq2(nlowmult(30, -76, -91), -90, -120) );
68
print "nhimult..........";
69
was_it_ok(11, nhimult(10, 41) == 50 &&
70
nhimult(10, 49) == 50 &&
71
eq2(nhimult(30, -74, -119), -60, -90) );
73
if ($failed == 0) { print "All tests successful.\n"; }
75
$tt = ($failed == 1) ? "1 test" : "$failed tests";
76
print "$tt failed! There is no joy in Mudville.\n";
80
#--- Compare two lists with 2 elements each for equality.
82
my ($a0, $a1, $b0, $b1) = @_;
83
return ($a0 == $b0 && $a1 == $b1) ? 1 : 0;
87
my ($num, $test) = @_;
88
if ($test) { print "ok $num\n"; }
89
else { print "not ok $num\n"; $failed++; }