~ubuntu-branches/ubuntu/trusty/horae/trusty

« back to all changes in this revision

Viewing changes to 0CPAN/Math-Round-0.05/test.pl

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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'
3
 
 
4
 
################## We start with some black magic to print on failure.
5
 
 
6
 
BEGIN { $| = 1; print "1..11\n"; }
7
 
END {print "not ok 1\n" unless $loaded;}
8
 
use Math::Round qw(:all);
9
 
$loaded = 1;
10
 
print "ok 1\n";
11
 
 
12
 
################## End of black magic.
13
 
 
14
 
my $failed = 0;
15
 
 
16
 
#--- Both scalar and list contexts are tested.
17
 
print "round............";
18
 
was_it_ok(2, round(2.4) == 2 &&
19
 
  round(2.5) == 3 &&
20
 
  round(2.6) == 3 &&
21
 
  eq2(round(-3.9, -2.5), -4, -3) );
22
 
 
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) );
27
 
 
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) );
33
 
 
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) );
38
 
 
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) );
45
 
 
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) );
51
 
 
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) );
57
 
 
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) );
62
 
 
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) );
67
 
 
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) );
72
 
 
73
 
if ($failed == 0) { print "All tests successful.\n"; }
74
 
else {
75
 
   $tt = ($failed == 1) ? "1 test" : "$failed tests";
76
 
   print "$tt failed!  There is no joy in Mudville.\n";
77
 
}
78
 
 
79
 
 
80
 
#--- Compare two lists with 2 elements each for equality.
81
 
sub eq2 {
82
 
 my ($a0, $a1, $b0, $b1) = @_;
83
 
 return ($a0 == $b0 && $a1 == $b1) ? 1 : 0;
84
 
}
85
 
 
86
 
sub was_it_ok {
87
 
 my ($num, $test) = @_;
88
 
 if ($test) { print "ok $num\n"; }
89
 
 else       { print "not ok $num\n"; $failed++; }
90
 
}