[t][TT #1122] Convert t/op/numbert.t to PIR, mgrimes++
[parrot.git] / t / dynoplibs / math.t
blob49347fe860de8ebd9457eef7da49de2bc490d2ad
1 #! parrot
2 # Copyright (C) 2009, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/dynoplibs/math.t - Tests for mathematical ops
9 =head1 SYNOPSIS
11         % prove t/dynoblibs/math.t
13 =head1 DESCRIPTION
15 Tests math.ops
17 =cut
19 .loadlib 'math_ops'
20 .sub main :main
21     .include 'test_more.pir'
22     .include 'fp_equality.pasm'
23     plan(20)
24     ok(1, "load math_ops")
25     rand $I0
26     test_2_arg_int()
27     test_3_arg_int()
28     test_1_arg_num()
29     test_2_arg_num()
30     test_3_arg_num()
31     test_srand()
32     test_local_nums()
33     test_local_nums_2_arg()
34     test_local_ints()
35 .end
37 .sub test_2_arg_int
38     rand $I0, 5
39     lt $I0, 0, fail1
40     ok(1, 'rand returns a number greater than or equal to 0')
41     goto upper
42 fail1:
43     ok(0, 'rand returns a number greater than or equal to 0')
44 upper:
45     gt $I0, 5, fail2
46     ok(1, 'rand returns a number less than or equal to 5')
47     goto finish
48 fail2:
49     ok(0, 'rand returns a number less than or equal to 5')
50 finish:
51 .end
53 .sub test_3_arg_int
54     rand $I0, 5, 25
55     lt $I0, 5, fail1
56     ok(1, 'rand returns a number greater than or equal to 5')
57     goto upper
58 fail1:
59     ok(0, 'rand returns a number greater than or equal to 5')
60 upper:
61     gt $I0, 25, fail2
62     ok(1, 'rand returns a number less than or equal to 25')
63     goto finish
64 fail2:
65     ok(0, 'rand returns a number less than or equal to 25')
66 finish:
67 .end
69 .sub test_1_arg_num
70     rand $N0
71     lt $N0, 0, fail1
72     ok(1, 'rand returns a number greater than or equal to 0')
73     goto upper
74 fail1:
75     ok(0, 'rand returns a number greater than or equal to 0')
76 upper:
77     gt $N0, 1, fail2
78     ok(1, 'rand returns a number less than or equal to 1')
79     goto finish
80 fail2:
81     ok(0, 'rand returns a number less than or equal to 1')
82 finish:
83 .end
85 .sub test_2_arg_num
86     rand $N0, 5
87     lt $N0, 0, fail1
88     ok(1, 'rand returns a number greater than or equal to 0')
89     goto upper
90 fail1:
91     ok(0, 'rand returns a number greater than or equal to 0')
92 upper:
93     gt $N0, 5, fail2
94     ok(1, 'rand returns a number less than or equal to 5')
95     goto finish
96 fail2:
97     ok(0, 'rand returns a number less than or equal to 5')
98 finish:
99 .end
101 .sub test_3_arg_num
102     rand $N0, 5, 25
103     lt $N0, 5, fail1
104     ok(1, 'rand returns a number greater than or equal to 5')
105     goto upper
106 fail1:
107     ok(0, 'rand returns a number greater than or equal to 5')
108 upper:
109     gt $N0, 25, fail2
110     ok(1, 'rand returns a number less than or equal to 25')
111     goto finish
112 fail2:
113     ok(0, 'rand returns a number less than or equal to 25')
114 finish:
115 .end
117 .sub test_srand
118     srand 42
119     ok(1, 'call srand with int')
120     srand 42.0
121     ok(1, 'call srand with num')
122     rand $N0
123     srand 5
124     rand $N2
125     srand 42.0
126     rand $N1
127     .fp_eq_ok($N0, $N1, 'having the same seed generates the same numbers')
128 .end
130 .sub test_local_nums_2_arg
131     .local num foo, bar
132     foo = rand 5.0, 25.0
133     lt foo, 5, fail1
134     ok(1, 'rand returns a number greater than or equal to 5')
135     goto upper
136 fail1:
137     ok(0, 'rand returns a number greater than or equal to 5')
138 upper:
139     gt foo, 25, fail2
140     ok(1, 'rand returns a number less than or equal to 25')
141     goto finish
142 fail2:
143     ok(0, 'rand returns a number less than or equal to 25')
144 finish:
145 .end
147 .sub test_local_nums
148     .local num foo, bar
149     foo = rand
150     lt foo, 0, fail1
151     ok(1, 'rand returns a number greater than or equal to 0')
152     goto upper
153 fail1:
154     ok(0, 'rand returns a number greater than or equal to 0')
155 upper:
156     gt foo, 1, fail2
157     ok(1, 'rand returns a number less than or equal to 1')
158     goto finish
159 fail2:
160     ok(0, 'rand returns a number less than or equal to 1')
161 finish:
162 .end
164 .sub test_local_ints
165     .local int foo, bar
166     foo = rand 5, 25
167     lt foo, 5, fail1
168     ok(1, 'rand returns a number greater than or equal to 5')
169     goto upper
170 fail1:
171     ok(0, 'rand returns a number greater than or equal to 5')
172 upper:
173     gt foo, 25, fail2
174     ok(1, 'rand returns a number less than or equal to 25')
175     goto finish
176 fail2:
177     ok(0, 'rand returns a number less than or equal to 25')
178 finish:
179 .end
181 # Local Variables:
182 #   mode: cperl
183 #   cperl-indent-level: 4
184 #   fill-column: 100
185 # End:
186 # vim: expandtab shiftwidth=4 filetype=pir: