3
5
6
10
11test_suites([test_is, test_arith, test_plus, test_minus, test_times,
12 test_division, test_mod, test_floor, test_round, test_ceiling,
13 test_truncate, test_floatarith, test_abs, test_sqrt,
14 test_power]).
15
16
21
22test_is_1(Result) :- 'is'(Result, 3 + 11.0).
23test_is_2(X, Y) :- X = 1 + 2, Y is X * 3.
24test_is_3 :- X = foo, 'is'(X, 77).
25test_is_4(N) :- 'is'(77, N).
26
27throws_exception(test_is_4).
28
29
34
35test_arith_1 :- '=:='(0, 1).
36test_arith_2 :- '=\\='(0, 1).
37test_arith_3 :- '<'(0, 1).
38test_arith_4 :- '>'(0, 1).
39test_arith_5 :- '>='(0, 1).
40test_arith_6 :- '=<'(0, 1).
41test_arith_7 :- '=:='(1.0, 1).
42test_arith_8 :- '=\\='(1.0, 1).
43test_arith_9 :- '<'(1.0, 1).
44test_arith_10 :- '>'(1.0, 1).
45test_arith_11 :- '>='(1.0, 1).
46test_arith_12 :- '=<'(1.0, 1).
47test_arith_13 :- '=:='(3 * 2, 7 - 1).
48test_arith_14 :- '=\\='(3 * 2, 7 - 1).
49test_arith_15 :- '<'(3 * 2, 7 - 1).
50test_arith_16 :- '>'(3 * 2, 7 - 1).
51test_arith_17 :- '>='(3 * 2, 7 - 1).
52test_arith_18 :- '=<'(3 * 2, 7 - 1).
53test_arith_19(X) :- '=:='(X, 5).
54test_arith_20(X) :- '=\\='(X, 5).
55test_arith_21(X) :- '<'(X, 5).
56test_arith_22(X) :- '>'(X, 5).
57test_arith_23(X) :- '>='(X, 5).
58test_arith_24(X) :- '=<'(X, 5).
59
60throws_exception(test_arith_19).
61throws_exception(test_arith_20).
62throws_exception(test_arith_21).
63throws_exception(test_arith_22).
64throws_exception(test_arith_23).
65throws_exception(test_arith_24).
66
67test_arith_1b :- 0 =:= 1.
68test_arith_2b :- 0 =\= 1.
69test_arith_3b :- 0 < 1.
70test_arith_4b :- 0 > 1.
71test_arith_5b :- 0 >= 1.
72test_arith_6b :- 0 =< 1.
73test_arith_7b :- 1.0 =:= 1.
74test_arith_8b :- 1.0 =\= 1.
75test_arith_9b :- 1.0 < 1.
76test_arith_10b :- 1.0 > 1.
77test_arith_11b :- 1.0 >= 1.
78test_arith_12b :- 1.0 =< 1.
79test_arith_13b :- 3 * 2 =:= 7 - 1.
80test_arith_14b :- 3 * 2 =\= 7 - 1.
81test_arith_15b :- 3 * 2 < 7 - 1.
82test_arith_16b :- 3 * 2 > 7 - 1.
83test_arith_17b :- 3 * 2 >= 7 - 1.
84test_arith_18b :- 3 * 2 =< 7 - 1.
85test_arith_19b(X) :- X =:= 5.
86test_arith_20b(X) :- X =\= 5.
87test_arith_21b(X) :- X < 5.
88test_arith_22b(X) :- X > 5.
89test_arith_23b(X) :- X >= 5.
90test_arith_24b(X) :- X =< 5.
91
92throws_exception(test_arith_19b).
93throws_exception(test_arith_20b).
94throws_exception(test_arith_21b).
95throws_exception(test_arith_22b).
96throws_exception(test_arith_23b).
97throws_exception(test_arith_24b).
98
99
104
105test_plus_1(X) :- X is '+'(7, 35).
106test_plus_2(X) :- X is '+'(0, 3 + 11).
107test_plus_3(X) :- X is '+'(0, 3.2 + 11).
108test_plus_4(X, N) :- X is '+'(77, N).
109test_plus_5(X) :- Y = foo, X is '+'(Y, 77).
110
111throws_exception(test_plus_4).
112throws_exception(test_plus_5).
113
114test_plus_1b(X) :- X is 7 + 35.
115test_plus_2b(X) :- X is 0 + (3 + 11).
116test_plus_3b(X) :- X is 0 + (3.2 + 11).
117test_plus_4b(X, N) :- X is 77 + N.
118test_plus_5b(X) :- Y = foo, X is Y + 77.
119
120throws_exception(test_plus_4b).
121throws_exception(test_plus_5b).
122
129
130
135
136test_minus_1(X) :- X is '-'(7).
137test_minus_2(X) :- X is '-'(3 - 11).
138test_minus_3(X) :- X is '-'(3.2 - 11).
139test_minus_4(X, N) :- X is '-'(N).
140test_minus_5(X) :- Y = foo, X is '-'(Y).
141test_minus_6(X) :- X is '-'(7, 35).
142test_minus_7(X) :- X is '-'(20, 3 + 11).
143test_minus_8(X) :- X is '-'(0, 3.2 + 11).
144test_minus_9(X, N) :- X is '-'(77, N).
145test_minus_10(X) :- Y = foo, X is '-'(Y, 77).
146
147throws_exception(test_minus_4).
148throws_exception(test_minus_5).
149throws_exception(test_minus_9).
150throws_exception(test_minus_10).
151
152test_minus_1b(X) :- X is -7.
153test_minus_2b(X) :- X is -(3 - 11).
154test_minus_3b(X) :- X is -(3.2 - 11).
155test_minus_4b(X, N) :- X is -N.
156test_minus_5b(X) :- Y = foo, X is -Y.
157test_minus_6b(X) :- X is 7 - 35.
158test_minus_7b(X) :- X is 20 - (3 + 11).
159test_minus_8b(X) :- X is 0 - (3.2 + 11).
160test_minus_9b(X, N) :- X is 77 - N.
161test_minus_10b(X) :- Y = foo, X is Y - 77.
162
163throws_exception(test_minus_4b).
164throws_exception(test_minus_5b).
165throws_exception(test_minus_9b).
166throws_exception(test_minus_10b).
167
174
175
180
181test_times_1(X) :- X is '*'(7, 35).
182test_times_2(X) :- X is '*'(0, 3 + 11).
183test_times_3(X) :- X is '*'(1.5, 3.2 + 11).
184test_times_4(X, N) :- X is '*'(77, N).
185test_times_5(X) :- Y = foo, X is '*'(Y, 77).
186
187throws_exception(test_times_4).
188throws_exception(test_times_5).
189
190test_times_1b(X) :- X is 7 * 35.
191test_times_2b(X) :- X is 0 * (3 + 11).
192test_times_3b(X) :- X is 1.5 * (3.2 + 11).
193test_times_4b(X, N) :- X is 77 * N.
194test_times_5b(X) :- Y = foo, X is Y * 77.
195
196throws_exception(test_times_4b).
197throws_exception(test_times_5b).
198
205
206
211
212test_division_1(X) :- X is '/'(7, 35).
213test_division_2(X) :- X is '/'(7.0, 35).
214test_division_3(X) :- X is '/'(140, 3 + 11).
215test_division_4(X) :- X is '/'(20.1644, 3.2 + 11).
216test_division_5(X) :- X is '/'(7, -3). 217test_division_6(X) :- X is '/'(-7, 3). 218test_division_7(X, N) :- X is '/'(77, N).
219test_division_8(X) :- Y = foo, X is '/'(Y, 77).
220test_division_9(X) :- X is '/'(3, 0).
221
222throws_exception(test_division_7).
223throws_exception(test_division_8).
224throws_exception(test_division_9).
225
226test_division_1b(X) :- X is 7 / 35.
227test_division_2b(X) :- X is 7.0 / 35.
228test_division_3b(X) :- X is 140 / (3 + 11).
229test_division_4b(X) :- X is 20.1644 / (3.2 + 11).
230test_division_5b(X) :- X is 7 / -3. 231test_division_6b(X) :- X is -7 / 3. 232test_division_7b(X, N) :- X is 77 / N.
233test_division_8b(X) :- Y = foo, X is Y / 77.
234test_division_9b(X) :- X is 3 / 0.
235
236throws_exception(test_division_7b).
237throws_exception(test_division_8b).
238throws_exception(test_division_9b).
239
240
245
246test_mod_1(X) :- X is mod(7, 3).
247test_mod_2(X) :- X is mod(0, 3 + 11).
248test_mod_3(X, N) :- X is mod(77, N).
249test_mod_4(X) :- Y = foo, X is mod(Y, 77).
250test_mod_5(X) :- X is mod(7.5, 2).
251test_mod_6(X) :- X is mod(7, 0).
252test_mod_7(X) :- X is mod(7, -2).
253
254throws_exception(test_mod_3).
255throws_exception(test_mod_4).
256throws_exception(test_mod_5).
257throws_exception(test_mod_6).
259 260
261
266
267test_floor_1(X) :- X is floor(7.4).
268test_floor_2(X) :- X is floor(-0.4).
269
270
275
276test_round_1(X) :- X is round(7.5).
277test_round_2(X) :- X is round(7.6).
278test_round_3(X) :- X is round(-0.6).
279test_round_4(X, N) :- X is round(N).
280
281throws_exception(test_round_4).
282
283
288
289test_ceiling_1(X) :- X is ceiling(-0.5).
290
291
296
297test_truncate_1(X) :- X is truncate(-0.5).
298test_truncate_2(X) :- Y = foo, X is truncate(Y).
299
300throws_exception(test_truncate_2).
301
302
307
308test_floatarith_1(X) :- X is float(7).
309test_floatarith_2(X) :- X is float(7.3).
310test_floatarith_3(X) :- X is float(5 / 3).
311test_floatarith_4(X, N) :- X is float(N).
312test_floatarith_5(X) :- Y = foo, X is float(Y).
313
314throws_exception(test_floatarith_4).
315throws_exception(test_floatarith_5).
316
323
324
329
330test_abs_1(X) :- X is abs(7).
331test_abs_2(X) :- X is abs(3 - 11).
332test_abs_3(X) :- X is abs(3.2 - 11.0).
333test_abs_4(X, N) :- X is abs(N).
334test_abs_5(X) :- Y = foo, X is abs(Y).
335
336throws_exception(test_abs_4).
337throws_exception(test_abs_5).
338
339
344
345test_sqrt_1(X) :- X is sqrt(0.0).
346test_sqrt_2(X) :- X is sqrt(4.0).
347test_sqrt_3(X) :- X is sqrt(0).
348test_sqrt_4(X) :- X is sqrt(1.0).
349test_sqrt_5(X, N) :- X is sqrt(N).
350test_sqrt_6(X) :- Y = foo, X is sqrt(Y).
351test_sqrt_7(X) :- X is sqrt(-1.0).
352
353throws_exception(test_sqrt_5).
354throws_exception(test_sqrt_6).
355throws_exception(test_sqrt_7).
356
357
362
363test_power_1(X) :- X is '**'(5, 3).
364test_power_2(X) :- X is '**'(-5.0, 3).
365test_power_3(X) :- X is '**'(5, -1).
366test_power_4(X, N) :- X is '**'(77, N).
367test_power_5(X) :- Y = foo, X is '**'(Y, 2).
368test_power_6(X) :- X is '**'(5, 3.0).
369test_power_7(X) :- X is '**'(0.0, 0).
370
371throws_exception(test_power_4).
372throws_exception(test_power_5).
373
374test_power_1b(X) :- X is 5 ** 3.
375test_power_2b(X) :- X is -5.0 ** 3.
376test_power_3b(X) :- X is 5 ** -1.
377test_power_4b(X, N) :- X is 77 ** N.
378test_power_5b(X) :- Y = foo, X is Y ** 2.
379test_power_6b(X) :- X is 5 ** 3.0.
380test_power_7b(X) :- X is 0.0 ** 0.
381
382throws_exception(test_power_4b).
383throws_exception(test_power_5b)