1
2
3# Test Script for the PDL interface to the GSL library
4#  This tests only that the interface is working, i.e. that the
5#   functions can be called. The actual return values are not
6#   checked.
7#  The GSL library already has a extensive test suite, and we
8#  do not want to duplicate that effort here.
9
10use PDL;
11use Test::More;
12
13BEGIN
14{
15   use PDL::Config;
16   if ( $PDL::Config{WITH_GSL} ) {
17      eval " use PDL::GSL::RNG; ";
18      unless ($@) {
19         plan tests => 19;
20      } else {
21         plan skip_all => "PDL::GSL::RNG not installed.";
22      }
23   } else {
24      plan skip_all => "PDL::GSL::RNG not compiled.";
25   }
26}
27
28$image = zeroes(10,10);
29$ndim = 2;
30$name = '';
31$sigma = 1;
32
33# new() function Test:
34$rng = PDL::GSL::RNG->new('taus');
35
36ok(1,'new() function');
37
38# set_seed(); function Test:
39$rng->set_seed(666);
40
41ok(1,'set_seed(); function');
42
43my $rng2 = PDL::GSL::RNG->new('taus')->set_seed(666);
44is(ref $rng2, 'PDL::GSL::RNG', 'PDL::GSL::RNG->new(..)->set_seed(..)');
45
46# min() function Test:
47$min = $rng->min(); $max = $rng->max();
48
49ok(1,'min() function');
50
51# rmax() function Test:
52$min = $rng->min(); $max = $rng->max();
53
54ok(1,'rmax() function');
55
56# name() function Test:
57$name = $rng->name();
58
59ok(1,'name() function');
60
61# get_uniform() function Test:
62$a = zeroes 5,6; $max=100;
63
64$o = $rng->get_uniform(10,10); $rng->get_uniform($a);
65
66ok(1,'get_uniform() function');
67
68# get_uniform_pos() function Test:
69$a = zeroes 5,6;
70
71$o = $rng->get_uniform_pos(10,10); $rng->get_uniform_pos($a);
72
73ok(1,'get_uniform_pos() function');
74
75# get() function Test:
76$a = zeroes 5,6;
77
78$o = $rng->get(10,10); $rng->get($a);
79
80ok(1,'get() function');
81
82# get_int() function Test:
83$a = zeroes 5,6; $max=100;
84
85$o = $rng->get(10,10); $rng->get($a);
86
87ok(1,'get_int() function');
88
89# ran_gaussian() function Test:
90$o = $rng->ran_gaussian($sigma,10,10);
91
92$rng->ran_gaussian($sigma,$a);
93
94
95ok(1,'ran_gaussian() function');
96
97# $rng->ran_gaussian_var() function Test:
98$sigma_pdl = rvals zeroes 11,11; $o = $rng->ran_gaussian_var($sigma_pdl);
99
100
101ok(1,'ran_gaussian_var() method');
102
103# ran_additive_gaussian() function Test:
104$rng->ran_additive_gaussian(1,$image);
105
106ok(1,'ran_additive_gaussian() method');
107
108# ran_additive_poisson() function Test:
109$rng->ran_additive_poisson(1,$image);
110
111ok(1,'ran_additive_poisson() method');
112
113# ran_feed_poisson() function Test:
114$rng->ran_feed_poisson($image);
115
116ok(1,'ran_feed_poisson() method');
117
118# ran_bivariate_gaussian() function Test:
119$o = $rng->ran_bivariate_gaussian(1,2,0.5,1000);
120
121ok(1,'ran_bivariate_gaussian() method');
122
123# ran_dir() function Test:
124$o = $rng->ran_dir($ndim,12);
125
126ok(1,'ran_dir() method');
127
128# ran_discrete_preproc() function Test:
129$prob = pdl [0.1,0.3,0.6];
130
131$discrete_dist_handle = $rng->ran_discrete_preproc($prob);
132
133$o = $rng->ran_discrete($discrete_dist_handle,100);
134
135ok(1,'ran_discrete_preproc() method');
136
137# ran_discrete() function Test:
138$prob = pdl [0.1,0.3,0.6];
139
140$discrete_dist_handle = $rng->ran_discrete_preproc($prob);
141
142$o = $rng->ran_discrete($discrete_dist_handle,100);
143
144ok(1,'ran_discrete() method');
145
146