blib/lib/Math/test1.pl untested

filter: Statementstmt 0.0% 0 / 75 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 98 CC 3 SCAR 14.6
CC
3
Cov
0%
END
6.0
was_it_ok
6.0
BEGIN
2.0
CRAP 4.3
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 #------ Tests for original version of phrtsd
4  
5 ################# We start with some black magic to print on failure.
6  
7 BEGIN { $| = 1; print "1..16\n"; }
8 END {print "not ok 1\n" unless $loaded;}
9 use Math::Random qw(:all);
10 $loaded = 1;
11 print "ok 1\n";
12  
13 ################# End of black magic.
14  
15 #------ SUBROUTINES
16 #--- Compare two 3-element arrays for equality to 5 decimal places.
17 sub eq5a {
18 $a0 = sprintf("%.5f", $_[0]);
19 $a1 = sprintf("%.5f", $_[1]);
20 $a2 = sprintf("%.5f", $_[2]);
21 $b0 = sprintf("%.5f", $_[3]);
22 $b1 = sprintf("%.5f", $_[4]);
23 $b2 = sprintf("%.5f", $_[5]);
24 return ($a0 eq $b0) && ($a1 eq $b1) && ($a2 eq $b2);
25 }
26  
27 sub was_it_ok {
28 my ($num, $test) = @_;
29 if ($test) { print "ok $num\n"; }
30 else { print "not ok $num\n"; $failed++; }
31 }
32  
33 #------ TESTS
34 # NOTE: Do not change the order of these tests!! Since at least
35 # one new variate is produced every time, the results will differ
36 # if the order is changed. If new tests have to be added, add them
37 # at the end.
38  
39 $failed = 0;
40 random_set_seed_from_phrase("En arkhe en ho Logos");
41  
42 print "random_uniform..................";
43 @result = random_uniform(3, 0, 1.5);
44 was_it_ok(2, eq5a(@result, 0.02021, 0.72981, 0.28370));
45  
46 print "random_uniform_integer..........";
47 @result = random_uniform_integer(3, 1, 999999);
48 was_it_ok(3, eq5a(@result, 877502, 385465, 712626));
49  
50 print "random_permutation..............";
51 @result = random_permutation(qw[A 2 c iv E 6 g viii]);
52 was_it_ok(4, "@result" eq "iv c 6 2 E A g viii");
53  
54 print "random_permuted_index...........";
55 @result = random_permuted_index(9);
56 was_it_ok(5, "@result" eq "8 5 3 7 0 6 2 1 4");
57  
58 print "random_normal...................";
59 @result = random_normal(3, 50, 2.3);
60 was_it_ok(6, eq5a(@result, 49.96739, 52.24146, 47.73983));
61  
62 print "random_chi_square...............";
63 @result = random_chi_square(3, 4);
64 was_it_ok(7, eq5a(@result, 2.53270, 1.71850, 5.85347));
65  
66 print "random_f........................";
67 @result = random_f(3, 2, 5);
68 was_it_ok(8, eq5a(@result, 1.14801, 2.97847, 0.01688));
69  
70 print "random_beta.....................";
71 @result = random_beta(3, 17, 23);
72 was_it_ok(9, eq5a(@result, 0.49457, 0.55133, 0.37236));
73  
74 print "random_binomial.................";
75 @result = random_binomial(3, 31, 0.43);
76 was_it_ok(10, eq5a(@result, 17, 17, 18));
77  
78 print "random_poisson..................";
79 @result = random_poisson(3, 555);
80 was_it_ok(11, eq5a(@result, 571, 560, 579));
81  
82 print "random_exponential..............";
83 @result = random_exponential(3, 444);
84 was_it_ok(12, eq5a(@result, 1037.53566, 20.06634, 1063.81861));
85  
86 print "random_gamma....................";
87 @result = random_gamma(3, 11, 4);
88 was_it_ok(13, eq5a(@result, 0.22119, 0.60820, 0.27125));
89  
90 print "random_multinomial..............";
91 @result = random_multinomial(3, 0.1, 0.72, 0.18);
92 was_it_ok(14, eq5a(@result, 0, 2, 1));
93  
94 print "random_negative_binomial........";
95 @result = random_negative_binomial(3, 10, 0.63);
96 was_it_ok(15, eq5a(@result, 7, 8, 2));
97  
98 print "random_multivariate_normal......";
99 @result = random_multivariate_normal(2,1,1,
100 [0.1,0.0],
101 [0.0,0.1]);
102 @result = (map { @$_ } @result);
103 was_it_ok(16,eq5a(@result[0..2],0.61592,0.016556,1.27741));
104  
105  
106 if ($failed == 0) { print "All tests successful.\n" }
107 else {
108 $tt = ($failed == 1) ? "1 test" : "$failed tests";
109 print "$tt failed! There is no joy in Mudville.\n";
110 }