~ubuntu-branches/debian/sid/ocaml/sid

« back to all changes in this revision

Viewing changes to otherlibs/num/test/test_ratios.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-04-21 21:35:08 UTC
  • mfrom: (1.1.11 upstream) (12.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110421213508-kg34453aqmb0moha
* Fixes related to -output-obj with g++ (in debian/patches):
  - add Declare-primitive-name-table-as-const-char
  - add Avoid-multiple-declarations-in-generated-.c-files-in
  - fix Embed-bytecode-in-C-object-when-using-custom: the closing
    brace for extern "C" { ... } was missing in some cases

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
open Test;;
2
 
open Nat;;
3
 
open Big_int;;
4
 
open Ratio;;
5
 
open Int_misc;;
6
 
open Arith_status;;
7
 
 
8
 
set_error_when_null_denominator false
9
 
;;
10
 
 
11
 
let infinite_failure = "infinite or undefined rational number";;
12
 
 
13
 
testing_function "create_ratio"
14
 
;;
15
 
 
16
 
let r = create_ratio (big_int_of_int 1) (big_int_of_int (-2)) in
17
 
test 1 eq_big_int (numerator_ratio r, big_int_of_int (-1)) &&
18
 
test 2 eq_big_int (denominator_ratio r, big_int_of_int 2)
19
 
;;
20
 
 
21
 
let r = create_ratio (big_int_of_int 2) (big_int_of_int 3) in
22
 
test 3 eq_big_int (numerator_ratio r, big_int_of_int 2) &&
23
 
test 4 eq_big_int (denominator_ratio r, big_int_of_int 3)
24
 
;;
25
 
 
26
 
set_normalize_ratio true
27
 
;;
28
 
 
29
 
let r = create_ratio (big_int_of_int 12) (big_int_of_int (-16)) in
30
 
test 5 eq_big_int (numerator_ratio r, big_int_of_int (-3)) &&
31
 
test 6 eq_big_int (denominator_ratio r, big_int_of_int 4)
32
 
;;
33
 
 
34
 
set_normalize_ratio false
35
 
;;
36
 
 
37
 
let r = create_ratio (big_int_of_int 0) (big_int_of_int 0) in
38
 
test 7 eq_big_int (numerator_ratio r, big_int_of_int 0) &&
39
 
test 8 eq_big_int (denominator_ratio r, big_int_of_int 0)
40
 
;;
41
 
 
42
 
testing_function "create_normalized_ratio"
43
 
;;
44
 
 
45
 
let r = create_normalized_ratio (big_int_of_int 1) (big_int_of_int (-2)) in
46
 
test 1 eq_big_int (numerator_ratio r, big_int_of_int (-1)) &&
47
 
test 2 eq_big_int (denominator_ratio r, big_int_of_int 2)
48
 
;;
49
 
 
50
 
let r = create_normalized_ratio (big_int_of_int 2) (big_int_of_int 3) in
51
 
test 3 eq_big_int (numerator_ratio r, big_int_of_int 2) &&
52
 
test 4 eq_big_int (denominator_ratio r, big_int_of_int 3)
53
 
;;
54
 
 
55
 
set_normalize_ratio true
56
 
;;
57
 
 
58
 
let r = create_normalized_ratio (big_int_of_int 12) (big_int_of_int (-16)) in
59
 
test 5 eq_big_int (numerator_ratio r, big_int_of_int (-12)) &&
60
 
test 6 eq_big_int (denominator_ratio r, big_int_of_int 16)
61
 
;;
62
 
 
63
 
set_normalize_ratio false
64
 
;;
65
 
 
66
 
let r = create_normalized_ratio (big_int_of_int 1) (big_int_of_int 0) in
67
 
test 7 eq_big_int (numerator_ratio r, big_int_of_int 1) &&
68
 
test 8 eq_big_int (denominator_ratio r, big_int_of_int 0)
69
 
;;
70
 
 
71
 
let r = create_normalized_ratio (big_int_of_int 0) (big_int_of_int 0) in
72
 
test 9 eq_big_int (numerator_ratio r, big_int_of_int 0) &&
73
 
test 10 eq_big_int (denominator_ratio r, big_int_of_int 0)
74
 
;;
75
 
 
76
 
testing_function "null_denominator"
77
 
;;
78
 
 
79
 
test 1
80
 
 eq (null_denominator (create_ratio (big_int_of_int 1) (big_int_of_int (-2))),
81
 
     false)
82
 
;;
83
 
test 2 eq
84
 
 (null_denominator (create_ratio (big_int_of_int 1) zero_big_int),true)
85
 
;;
86
 
 
87
 
(*****
88
 
testing_function "verify_null_denominator"
89
 
;;
90
 
 
91
 
test 1
92
 
 eq (verify_null_denominator (ratio_of_string "0/1"), false)
93
 
;;
94
 
test 2
95
 
 eq (verify_null_denominator (ratio_of_string "0/0"), true)
96
 
;;
97
 
*****)
98
 
 
99
 
testing_function "sign_ratio"
100
 
;;
101
 
 
102
 
test 1
103
 
eq_int (sign_ratio (create_ratio (big_int_of_int (-2)) (big_int_of_int (-3))),
104
 
        1)
105
 
;;
106
 
test 2
107
 
eq_int (sign_ratio (create_ratio (big_int_of_int 2) (big_int_of_int (-3))),
108
 
        (-1))
109
 
;;
110
 
test 3
111
 
eq_int (sign_ratio (create_ratio zero_big_int (big_int_of_int (-3))), 0)
112
 
;;
113
 
 
114
 
testing_function "normalize_ratio"
115
 
;;
116
 
 
117
 
let r = create_ratio (big_int_of_int 12) (big_int_of_int (-16)) in
118
 
ignore (normalize_ratio r);
119
 
test 1 eq_big_int (numerator_ratio r, big_int_of_int (-3)) &&
120
 
test 2 eq_big_int (denominator_ratio r, big_int_of_int 4)
121
 
;;
122
 
 
123
 
let r = create_ratio (big_int_of_int (-1)) zero_big_int in
124
 
ignore (normalize_ratio r);
125
 
test 3 eq_big_int (numerator_ratio r, big_int_of_int (-1)) &&
126
 
test 4 eq_big_int (denominator_ratio r, zero_big_int)
127
 
;;
128
 
 
129
 
testing_function "report_sign_ratio"
130
 
;;
131
 
 
132
 
test 1
133
 
eq_big_int (report_sign_ratio
134
 
            (create_ratio (big_int_of_int 2) (big_int_of_int (-3)))
135
 
            (big_int_of_int 1),
136
 
            big_int_of_int (-1))
137
 
;;
138
 
test 2
139
 
eq_big_int (report_sign_ratio
140
 
            (create_ratio (big_int_of_int 2) (big_int_of_int 3))
141
 
             (big_int_of_int 1),
142
 
            big_int_of_int 1)
143
 
;;
144
 
 
145
 
testing_function "is_integer_ratio"
146
 
;;
147
 
 
148
 
test 1 eq
149
 
 (is_integer_ratio (create_ratio (big_int_of_int 2) (big_int_of_int (-1))),
150
 
  true)
151
 
;;
152
 
test 2 eq
153
 
 (is_integer_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)),
154
 
  false)
155
 
;;
156
 
 
157
 
testing_function "add_ratio"
158
 
;;
159
 
 
160
 
let r = add_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 2))
161
 
                   (create_ratio (big_int_of_int 2) (big_int_of_int 3)) in
162
 
test 1 eq_big_int (numerator_ratio r, big_int_of_int 7) &&
163
 
test 2 eq_big_int (denominator_ratio r, big_int_of_int 6)
164
 
;;
165
 
 
166
 
let r = add_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3))
167
 
                   (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in
168
 
test 3 eq_big_int (numerator_ratio r, big_int_of_int 1) &&
169
 
test 4 eq_big_int (denominator_ratio r, big_int_of_int 6)
170
 
;;
171
 
 
172
 
let r = add_ratio (create_ratio (big_int_of_int 2) zero_big_int)
173
 
                   (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in
174
 
test 5 eq_big_int (numerator_ratio r, big_int_of_int 4) &&
175
 
test 6 eq_big_int (denominator_ratio r, zero_big_int)
176
 
;;
177
 
 
178
 
let r = add_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3))
179
 
                   (create_ratio (big_int_of_int 1) zero_big_int) in
180
 
test 7 eq_big_int (numerator_ratio r, big_int_of_int 3) &&
181
 
test 8 eq_big_int (denominator_ratio r, zero_big_int)
182
 
;;
183
 
 
184
 
let r = add_ratio (create_ratio (big_int_of_int 2) zero_big_int)
185
 
                   (create_ratio (big_int_of_int 1) zero_big_int) in
186
 
test 9 eq_big_int (numerator_ratio r, zero_big_int) &&
187
 
test 10 eq_big_int (denominator_ratio r, zero_big_int)
188
 
;;
189
 
 
190
 
let r = add_ratio (create_ratio (big_int_of_string "12724951")
191
 
                                 (big_int_of_string "26542080"))
192
 
                   (create_ratio (big_int_of_string "-1")
193
 
                                 (big_int_of_string "81749606400")) in
194
 
test 11 eq_big_int (numerator_ratio r,
195
 
                     big_int_of_string "1040259735682744320") &&
196
 
test 12 eq_big_int (denominator_ratio r,
197
 
                     big_int_of_string "2169804593037312000")
198
 
;;
199
 
 
200
 
let r1,r2 =
201
 
 (create_ratio (big_int_of_string "12724951")
202
 
                                 (big_int_of_string "26542080"),
203
 
                   create_ratio (big_int_of_string "-1")
204
 
                                 (big_int_of_string "81749606400")) in
205
 
 
206
 
let bi1 = mult_big_int (numerator_ratio r1) (denominator_ratio r2)
207
 
and  bi2 = mult_big_int (numerator_ratio r2) (denominator_ratio r1)
208
 
in
209
 
test 1
210
 
eq_big_int (bi1,
211
 
            big_int_of_string "1040259735709286400")
212
 
&&
213
 
test 2
214
 
eq_big_int (bi2,
215
 
            big_int_of_string "-26542080")
216
 
&& test 3
217
 
eq_big_int (mult_big_int (denominator_ratio r1) (denominator_ratio r2),
218
 
            big_int_of_string "2169804593037312000")
219
 
&& test 4
220
 
eq_big_int (add_big_int bi1 bi2,
221
 
            big_int_of_string "1040259735682744320")
222
 
;;
223
 
 
224
 
testing_function "sub_ratio"
225
 
;;
226
 
 
227
 
let r = sub_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3))
228
 
                   (create_ratio (big_int_of_int 1) (big_int_of_int 2)) in
229
 
test 1  eq_big_int (numerator_ratio r, big_int_of_int 1) &&
230
 
test 2 eq_big_int (denominator_ratio r, big_int_of_int 6)
231
 
;;
232
 
 
233
 
let r = sub_ratio (create_ratio (big_int_of_int 2) zero_big_int)
234
 
                   (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in
235
 
test 3 eq_big_int (numerator_ratio r, big_int_of_int 4) &&
236
 
test 4 eq_big_int (denominator_ratio r, zero_big_int)
237
 
;;
238
 
 
239
 
let r = sub_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3))
240
 
                   (create_ratio (big_int_of_int 1) zero_big_int) in
241
 
test 5 eq_big_int (numerator_ratio r, big_int_of_int (-3)) &&
242
 
test 6 eq_big_int (denominator_ratio r, zero_big_int)
243
 
;;
244
 
 
245
 
let r = sub_ratio (create_ratio (big_int_of_int 2) zero_big_int)
246
 
                   (create_ratio (big_int_of_int 1) zero_big_int) in
247
 
test 7 eq_big_int (numerator_ratio r, zero_big_int) &&
248
 
test 8 eq_big_int (denominator_ratio r, zero_big_int)
249
 
;;
250
 
 
251
 
testing_function "mult_ratio"
252
 
;;
253
 
 
254
 
let r = mult_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3))
255
 
                    (create_ratio (big_int_of_int 7) (big_int_of_int 5)) in
256
 
test 1 eq_big_int (numerator_ratio r, big_int_of_int 14) &&
257
 
test 2 eq_big_int (denominator_ratio r, big_int_of_int 15)
258
 
;;
259
 
 
260
 
let r = mult_ratio (create_ratio (big_int_of_int 2) zero_big_int)
261
 
                    (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in
262
 
test 3 eq_big_int (numerator_ratio r, big_int_of_int (-2)) &&
263
 
test 4 eq_big_int (denominator_ratio r, zero_big_int)
264
 
;;
265
 
 
266
 
let r = mult_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3))
267
 
                   (create_ratio (big_int_of_int 1) zero_big_int) in
268
 
test 5 eq_big_int (numerator_ratio r, big_int_of_int 2) &&
269
 
test 6 eq_big_int (denominator_ratio r, zero_big_int)
270
 
;;
271
 
 
272
 
let r = mult_ratio (create_ratio (big_int_of_int 2) zero_big_int)
273
 
                   (create_ratio (big_int_of_int 1) zero_big_int) in
274
 
test 7 eq_big_int (numerator_ratio r, big_int_of_int 2) &&
275
 
test 8 eq_big_int (denominator_ratio r, zero_big_int)
276
 
;;
277
 
 
278
 
testing_function "div_ratio"
279
 
;;
280
 
 
281
 
let r = div_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3))
282
 
                   (create_ratio (big_int_of_int 5) (big_int_of_int 7)) in
283
 
test 1 eq_big_int (numerator_ratio r, big_int_of_int 14) &&
284
 
test 2 eq_big_int (denominator_ratio r, big_int_of_int 15)
285
 
;;
286
 
 
287
 
let r = div_ratio (create_ratio (big_int_of_int 2) zero_big_int)
288
 
                   (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in
289
 
test 3 eq_big_int (numerator_ratio r, big_int_of_int (-4)) &&
290
 
test 4 eq_big_int (denominator_ratio r, zero_big_int)
291
 
;;
292
 
 
293
 
let r = div_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3))
294
 
                   (create_ratio (big_int_of_int 1) zero_big_int) in
295
 
test 5 eq_big_int (numerator_ratio r, zero_big_int) &&
296
 
test 6 eq_big_int (denominator_ratio r, big_int_of_int 3)
297
 
;;
298
 
 
299
 
let r = div_ratio (create_ratio (big_int_of_int 2) zero_big_int)
300
 
                   (create_ratio (big_int_of_int 1) zero_big_int) in
301
 
test 7 eq_big_int (numerator_ratio r, zero_big_int) &&
302
 
test 8 eq_big_int (denominator_ratio r, zero_big_int)
303
 
;;
304
 
 
305
 
testing_function "integer_ratio"
306
 
;;
307
 
 
308
 
test 1
309
 
eq_big_int (integer_ratio
310
 
            (create_ratio (big_int_of_int 5) (big_int_of_int 3)),
311
 
            big_int_of_int 1)
312
 
;;
313
 
test 2
314
 
eq_big_int (integer_ratio
315
 
            (create_ratio (big_int_of_int 5) (big_int_of_int (-3))),
316
 
            big_int_of_int (-1))
317
 
;;
318
 
test 3
319
 
eq_big_int (integer_ratio
320
 
            (create_ratio (big_int_of_int 3) (big_int_of_int 2)),
321
 
            big_int_of_int 1)
322
 
;;
323
 
test 4
324
 
eq_big_int (integer_ratio
325
 
            (create_ratio (big_int_of_int 3) (big_int_of_int (-2))),
326
 
            big_int_of_int (-1))
327
 
;;
328
 
 
329
 
failwith_test 5
330
 
integer_ratio (create_ratio (big_int_of_int 3) zero_big_int)
331
 
(Failure("integer_ratio "^infinite_failure))
332
 
;;
333
 
 
334
 
testing_function "floor_ratio"
335
 
;;
336
 
 
337
 
test 1
338
 
eq_big_int (floor_ratio
339
 
            (create_ratio (big_int_of_int 5) (big_int_of_int 3)),
340
 
            big_int_of_int 1)
341
 
;;
342
 
test 2
343
 
eq_big_int (floor_ratio
344
 
            (create_ratio (big_int_of_int 5) (big_int_of_int (-3))),
345
 
            big_int_of_int (-2))
346
 
;;
347
 
test 3
348
 
eq_big_int (floor_ratio
349
 
            (create_ratio (big_int_of_int 3) (big_int_of_int 2)),
350
 
            big_int_of_int 1)
351
 
;;
352
 
test 4
353
 
eq_big_int (floor_ratio
354
 
            (create_ratio (big_int_of_int 3) (big_int_of_int (-2))),
355
 
            big_int_of_int (-2))
356
 
;;
357
 
 
358
 
failwith_test 5 floor_ratio (create_ratio (big_int_of_int 3) zero_big_int)
359
 
Division_by_zero
360
 
;;
361
 
 
362
 
 
363
 
testing_function "round_ratio"
364
 
;;
365
 
 
366
 
test 1
367
 
eq_big_int (round_ratio
368
 
            (create_ratio (big_int_of_int 5) (big_int_of_int 3)),
369
 
            big_int_of_int 2)
370
 
;;
371
 
test 2
372
 
eq_big_int (round_ratio
373
 
            (create_ratio (big_int_of_int 5) (big_int_of_int (-3))),
374
 
            big_int_of_int (-2))
375
 
;;
376
 
test 3
377
 
eq_big_int (round_ratio
378
 
            (create_ratio (big_int_of_int 3) (big_int_of_int 2)),
379
 
            big_int_of_int 2)
380
 
;;
381
 
test 4
382
 
eq_big_int (round_ratio
383
 
            (create_ratio (big_int_of_int 3) (big_int_of_int (-2))),
384
 
            big_int_of_int (-2))
385
 
;;
386
 
 
387
 
failwith_test 5
388
 
round_ratio (create_ratio (big_int_of_int 3) zero_big_int)
389
 
Division_by_zero
390
 
;;
391
 
 
392
 
 
393
 
testing_function "ceiling_ratio"
394
 
;;
395
 
 
396
 
test 1
397
 
eq_big_int (ceiling_ratio
398
 
            (create_ratio (big_int_of_int 5) (big_int_of_int 3)),
399
 
            big_int_of_int 2)
400
 
;;
401
 
test 2
402
 
eq_big_int (ceiling_ratio
403
 
            (create_ratio (big_int_of_int 5) (big_int_of_int (-3))),
404
 
            big_int_of_int (-1))
405
 
;;
406
 
test 3
407
 
eq_big_int (ceiling_ratio
408
 
            (create_ratio (big_int_of_int 3) (big_int_of_int 2)),
409
 
            big_int_of_int 2)
410
 
;;
411
 
test 4
412
 
eq_big_int (ceiling_ratio
413
 
            (create_ratio (big_int_of_int 3) (big_int_of_int (-2))),
414
 
            big_int_of_int (-1))
415
 
;;
416
 
test 5
417
 
eq_big_int (ceiling_ratio
418
 
            (create_ratio (big_int_of_int 4) (big_int_of_int 2)),
419
 
            big_int_of_int 2)
420
 
;;
421
 
failwith_test 6
422
 
ceiling_ratio (create_ratio (big_int_of_int 3) zero_big_int)
423
 
Division_by_zero
424
 
;;
425
 
 
426
 
testing_function "eq_ratio"
427
 
;;
428
 
 
429
 
test 1
430
 
eq_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3),
431
 
          create_ratio (big_int_of_int (-20)) (big_int_of_int (-12)))
432
 
;;
433
 
test 2
434
 
eq_ratio (create_ratio (big_int_of_int 1) zero_big_int,
435
 
          create_ratio (big_int_of_int 2) zero_big_int)
436
 
;;
437
 
 
438
 
let neq_ratio x y = not (eq_ratio x y);;
439
 
 
440
 
test 3
441
 
neq_ratio (create_ratio (big_int_of_int 1) zero_big_int,
442
 
           create_ratio (big_int_of_int (-1)) zero_big_int)
443
 
;;
444
 
test 4
445
 
neq_ratio (create_ratio (big_int_of_int 1) zero_big_int,
446
 
           create_ratio zero_big_int zero_big_int)
447
 
;;
448
 
test 5
449
 
eq_ratio (create_ratio zero_big_int zero_big_int,
450
 
          create_ratio zero_big_int zero_big_int)
451
 
;;
452
 
 
453
 
testing_function "compare_ratio"
454
 
;;
455
 
 
456
 
test 1
457
 
eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0))
458
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 0)),
459
 
        0)
460
 
;;
461
 
test 2
462
 
eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0))
463
 
                       (create_ratio (big_int_of_int 1) (big_int_of_int 0)),
464
 
        0)
465
 
;;
466
 
test 3
467
 
eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0))
468
 
                       (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)),
469
 
        0)
470
 
;;
471
 
test 4
472
 
eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0))
473
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 0)),
474
 
        0)
475
 
;;
476
 
test 5
477
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0))
478
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 0)),
479
 
        0)
480
 
;;
481
 
test 6
482
 
eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0))
483
 
                       (create_ratio (big_int_of_int 5) (big_int_of_int 3)),
484
 
        0)
485
 
;;
486
 
test 7
487
 
eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3))
488
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 0)),
489
 
        0)
490
 
;;
491
 
test 8
492
 
eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0))
493
 
                       (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)),
494
 
        0)
495
 
;;
496
 
test 9
497
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-5)) (big_int_of_int 3))
498
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 0)),
499
 
        0)
500
 
;;
501
 
test 10
502
 
eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0))
503
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 1)),
504
 
        0)
505
 
;;
506
 
test 11
507
 
eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 1))
508
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 0)),
509
 
        0)
510
 
;;
511
 
test 12
512
 
eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0))
513
 
                       (create_ratio (big_int_of_int 1) (big_int_of_int 0)),
514
 
        0)
515
 
;;
516
 
test 13
517
 
eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0))
518
 
                       (create_ratio (big_int_of_int 2) (big_int_of_int 0)),
519
 
        0)
520
 
;;
521
 
test 14
522
 
eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0))
523
 
                       (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)),
524
 
        1)
525
 
;;
526
 
test 15
527
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0))
528
 
                       (create_ratio (big_int_of_int 1) (big_int_of_int 0)),
529
 
        (-1))
530
 
;;
531
 
test 16
532
 
eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3))
533
 
                       (create_ratio (big_int_of_int 1) (big_int_of_int 0)),
534
 
        (-1))
535
 
;;
536
 
test 17
537
 
eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0))
538
 
                       (create_ratio (big_int_of_int 5) (big_int_of_int 3)),
539
 
        1)
540
 
;;
541
 
test 18
542
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-5)) (big_int_of_int 3))
543
 
                       (create_ratio (big_int_of_int 1) (big_int_of_int 0)),
544
 
        (-1))
545
 
;;
546
 
test 19
547
 
eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0))
548
 
                       (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)),
549
 
        1)
550
 
;;
551
 
test 20
552
 
eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0))
553
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 3)),
554
 
        1)
555
 
;;
556
 
test 21
557
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0))
558
 
                       (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)),
559
 
        0)
560
 
;;
561
 
test 22
562
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0))
563
 
                       (create_ratio (big_int_of_int (-2)) (big_int_of_int 0)),
564
 
        0)
565
 
;;
566
 
test 23
567
 
eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3))
568
 
                       (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)),
569
 
        1)
570
 
;;
571
 
test 24
572
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0))
573
 
                       (create_ratio (big_int_of_int 5) (big_int_of_int 3)),
574
 
        (-1))
575
 
;;
576
 
test 25
577
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-5)) (big_int_of_int 3))
578
 
                       (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)),
579
 
        1)
580
 
;;
581
 
test 26
582
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0))
583
 
                       (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)),
584
 
        (-1))
585
 
;;
586
 
test 27
587
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0))
588
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 3)),
589
 
        (-1))
590
 
;;
591
 
test 28
592
 
eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3))
593
 
                       (create_ratio (big_int_of_int 3) (big_int_of_int 2)),
594
 
        1)
595
 
;;
596
 
test 29
597
 
eq_int (compare_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 2))
598
 
                       (create_ratio (big_int_of_int 5) (big_int_of_int 3)),
599
 
        (-1))
600
 
;;
601
 
test 30
602
 
eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3))
603
 
                       (create_ratio (big_int_of_int (-3)) (big_int_of_int 2)),
604
 
        1)
605
 
;;
606
 
test 31
607
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-3)) (big_int_of_int 2))
608
 
                       (create_ratio (big_int_of_int 5) (big_int_of_int 3)),
609
 
        (-1))
610
 
;;
611
 
test 32
612
 
eq_int (compare_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 2))
613
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 3)),
614
 
        1)
615
 
;;
616
 
test 33
617
 
eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 2))
618
 
                       (create_ratio (big_int_of_int 5) (big_int_of_int 3)),
619
 
        (-1))
620
 
;;
621
 
test 34
622
 
eq_int (compare_ratio (create_ratio (big_int_of_int (-3)) (big_int_of_int 2))
623
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 3)),
624
 
        (-1))
625
 
;;
626
 
test 35
627
 
eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 2))
628
 
                       (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)),
629
 
        1)
630
 
;;
631
 
test 36
632
 
eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 2))
633
 
                       (create_ratio (big_int_of_int 0) (big_int_of_int 3)),
634
 
        0)
635
 
;;
636
 
 
637
 
testing_function "eq_big_int_ratio"
638
 
;;
639
 
 
640
 
test 1
641
 
eq_big_int_ratio (big_int_of_int 3,
642
 
                  (create_ratio (big_int_of_int 3) (big_int_of_int 1)))
643
 
;;
644
 
test 2
645
 
eq
646
 
(not (eq_big_int_ratio (big_int_of_int 1)
647
 
                       (create_ratio (big_int_of_int 3) (big_int_of_int 1))),
648
 
true)
649
 
;;
650
 
 
651
 
test 3
652
 
eq
653
 
(not (eq_big_int_ratio (big_int_of_int 1)
654
 
                       (create_ratio (big_int_of_int 3) (big_int_of_int 2))),
655
 
 true)
656
 
;;
657
 
 
658
 
test 4
659
 
eq
660
 
(not (eq_big_int_ratio (big_int_of_int 1)
661
 
                       (create_ratio (big_int_of_int 3) (big_int_of_int 0))),
662
 
 true)
663
 
;;
664
 
 
665
 
test 5
666
 
eq
667
 
(not (eq_big_int_ratio (big_int_of_int 1)
668
 
                       (create_ratio (big_int_of_int (-3)) (big_int_of_int 2))),
669
 
 true)
670
 
;;
671
 
 
672
 
testing_function "compare_big_int_ratio"
673
 
;;
674
 
 
675
 
test 1
676
 
eq_int (compare_big_int_ratio
677
 
           (big_int_of_int 1)
678
 
            (create_ratio (big_int_of_int 3) (big_int_of_int 0)), (-1))
679
 
;;
680
 
test 2
681
 
eq_int (compare_big_int_ratio
682
 
           (big_int_of_int 1)
683
 
            (create_ratio (big_int_of_int 0) (big_int_of_int 0)), 0)
684
 
;;
685
 
test 3
686
 
eq_int (compare_big_int_ratio
687
 
           (big_int_of_int 1)
688
 
            (create_ratio (big_int_of_int (-3)) (big_int_of_int 0)), 1)
689
 
;;
690
 
test 4
691
 
eq_int (compare_big_int_ratio
692
 
           (big_int_of_int (-1))
693
 
            (create_ratio (big_int_of_int 3) (big_int_of_int 0)), (-1))
694
 
;;
695
 
test 5
696
 
eq_int (compare_big_int_ratio
697
 
           (big_int_of_int (-1))
698
 
            (create_ratio (big_int_of_int 0) (big_int_of_int 0)), 0)
699
 
;;
700
 
test 6
701
 
eq_int (compare_big_int_ratio
702
 
           (big_int_of_int (-1))
703
 
            (create_ratio (big_int_of_int (-3)) (big_int_of_int 0)), 1)
704
 
;;
705
 
test 7
706
 
eq_int (compare_big_int_ratio
707
 
           (big_int_of_int 1)
708
 
            (create_ratio (big_int_of_int 1) (big_int_of_int 1)), 0)
709
 
;;
710
 
test 8
711
 
eq_int (compare_big_int_ratio
712
 
           (big_int_of_int 1)
713
 
            (create_ratio (big_int_of_int 3) (big_int_of_int 2)), (-1))
714
 
;;
715
 
test 9
716
 
eq_int (compare_big_int_ratio
717
 
           (big_int_of_int 1)
718
 
            (create_ratio (big_int_of_int 2) (big_int_of_int 3)), 1)
719
 
;;
720
 
 
721
 
 
722
 
 
723
 
testing_function "int_of_ratio"
724
 
;;
725
 
 
726
 
test 1
727
 
eq_int (int_of_ratio (create_ratio (big_int_of_int 4) (big_int_of_int 2)),
728
 
        2)
729
 
;;
730
 
 
731
 
test 2
732
 
eq_int (int_of_ratio
733
 
        (create_ratio (big_int_of_int biggest_int) (big_int_of_int 1)),
734
 
        biggest_int)
735
 
;;
736
 
 
737
 
failwith_test 3
738
 
int_of_ratio (create_ratio (big_int_of_int 4) (big_int_of_int 0))
739
 
(Failure "integer argument required")
740
 
;;
741
 
 
742
 
failwith_test 4
743
 
int_of_ratio (create_ratio (succ_big_int (big_int_of_int biggest_int))
744
 
                             (big_int_of_int 1))
745
 
(Failure "integer argument required")
746
 
;;
747
 
 
748
 
failwith_test 5
749
 
int_of_ratio (create_ratio (big_int_of_int 4) (big_int_of_int 3))
750
 
(Failure "integer argument required")
751
 
;;
752
 
 
753
 
testing_function "ratio_of_int"
754
 
;;
755
 
 
756
 
test 1
757
 
eq_ratio (ratio_of_int 3,
758
 
          create_ratio (big_int_of_int 3) (big_int_of_int 1))
759
 
;;
760
 
 
761
 
test 2
762
 
eq_ratio (ratio_of_nat (nat_of_int 2),
763
 
          create_ratio (big_int_of_int 2) (big_int_of_int 1))
764
 
;;
765
 
 
766
 
testing_function "nat_of_ratio"
767
 
;;
768
 
 
769
 
let nat1 = nat_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 1))
770
 
and nat2 = nat_of_int 3 in
771
 
test 1
772
 
eq (eq_nat nat1 0 (length_nat nat1) nat2 0 (length_nat nat2), true)
773
 
;;
774
 
 
775
 
failwith_test 2
776
 
nat_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 0))
777
 
(Failure "nat_of_ratio")
778
 
;;
779
 
 
780
 
failwith_test 3
781
 
nat_of_ratio (create_ratio (big_int_of_int (-3)) (big_int_of_int 1))
782
 
(Failure "nat_of_ratio")
783
 
;;
784
 
 
785
 
failwith_test 4
786
 
nat_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 2))
787
 
(Failure "nat_of_ratio")
788
 
;;
789
 
 
790
 
testing_function "ratio_of_big_int"
791
 
;;
792
 
 
793
 
test 1
794
 
eq_ratio (ratio_of_big_int (big_int_of_int 3),
795
 
          create_ratio (big_int_of_int 3) (big_int_of_int 1))
796
 
;;
797
 
 
798
 
testing_function "big_int_of_ratio"
799
 
;;
800
 
 
801
 
test 1
802
 
eq_big_int (big_int_of_ratio
803
 
                (create_ratio (big_int_of_int 3) (big_int_of_int 1)),
804
 
            big_int_of_int 3)
805
 
;;
806
 
test 2
807
 
eq_big_int (big_int_of_ratio
808
 
                (create_ratio (big_int_of_int (-3)) (big_int_of_int 1)),
809
 
            big_int_of_int (-3))
810
 
;;
811
 
 
812
 
failwith_test 3
813
 
big_int_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 0))
814
 
(Failure "big_int_of_ratio")
815
 
;;
816
 
 
817
 
testing_function "string_of_ratio"
818
 
;;
819
 
 
820
 
test 1
821
 
eq_string (string_of_ratio
822
 
              (create_ratio (big_int_of_int 43) (big_int_of_int 35)),
823
 
           "43/35")
824
 
;;
825
 
test 2
826
 
eq_string (string_of_ratio
827
 
              (create_ratio (big_int_of_int 42) (big_int_of_int 0)),
828
 
           "1/0")
829
 
;;
830
 
 
831
 
set_normalize_ratio_when_printing false
832
 
;;
833
 
 
834
 
test 3
835
 
eq_string (string_of_ratio
836
 
              (create_ratio (big_int_of_int 42) (big_int_of_int 35)),
837
 
           "42/35")
838
 
;;
839
 
 
840
 
set_normalize_ratio_when_printing true
841
 
;;
842
 
 
843
 
test 4
844
 
eq_string (string_of_ratio
845
 
              (create_ratio (big_int_of_int 42) (big_int_of_int 35)),
846
 
           "6/5")
847
 
;;
848
 
 
849
 
testing_function "ratio_of_string"
850
 
;;
851
 
 
852
 
test 1
853
 
eq_ratio (ratio_of_string ("123/3456"),
854
 
          create_ratio (big_int_of_int 123) (big_int_of_int 3456))
855
 
;;
856
 
 
857
 
(***********
858
 
test 2
859
 
eq_ratio (ratio_of_string ("12.3/34.56"),
860
 
          create_ratio (big_int_of_int 1230) (big_int_of_int 3456))
861
 
;;
862
 
test 3
863
 
eq_ratio (ratio_of_string ("1.23/325.6"),
864
 
          create_ratio (big_int_of_int 123) (big_int_of_int 32560))
865
 
;;
866
 
test 4
867
 
eq_ratio (ratio_of_string ("12.3/345.6"),
868
 
          create_ratio (big_int_of_int 123) (big_int_of_int 3456))
869
 
;;
870
 
test 5
871
 
eq_ratio (ratio_of_string ("12.3/0.0"),
872
 
          create_ratio (big_int_of_int 123) (big_int_of_int 0))
873
 
;;
874
 
***********)
875
 
test 6
876
 
eq_ratio (ratio_of_string ("0/0"),
877
 
          create_ratio (big_int_of_int 0) (big_int_of_int 0))
878
 
;;
879
 
 
880
 
test 7
881
 
eq_ratio (ratio_of_string "1234567890",
882
 
          create_ratio (big_int_of_string "1234567890") unit_big_int)
883
 
;;
884
 
failwith_test 8
885
 
ratio_of_string "frlshjkurty" (Failure "invalid digit");;
886
 
 
887
 
(***********
888
 
testing_function "msd_ratio"
889
 
;;
890
 
 
891
 
test 1
892
 
eq_int (msd_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 1)),
893
 
        0)
894
 
;;
895
 
test 2
896
 
eq_int (msd_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 12)),
897
 
        (-2))
898
 
;;
899
 
test 3
900
 
eq_int (msd_ratio (create_ratio (big_int_of_int 12) (big_int_of_int 1)),
901
 
        1)
902
 
;;
903
 
test 4
904
 
eq_int (msd_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 2)),
905
 
        (-1))
906
 
;;
907
 
test 5
908
 
eq_int (msd_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 1)),
909
 
        0)
910
 
;;
911
 
test 6
912
 
eq_int (msd_ratio (create_ratio (big_int_of_int 25) (big_int_of_int 21)),
913
 
        0)
914
 
;;
915
 
test 7
916
 
eq_int (msd_ratio (create_ratio (big_int_of_int 35) (big_int_of_int 21)),
917
 
        0)
918
 
;;
919
 
test 8
920
 
eq_int (msd_ratio (create_ratio (big_int_of_int 215) (big_int_of_int 31)),
921
 
        0)
922
 
;;
923
 
test 9
924
 
eq_int (msd_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 30)),
925
 
        (-2))
926
 
;;
927
 
test 10
928
 
eq_int (msd_ratio (create_ratio (big_int_of_int 2345)
929
 
                                     (big_int_of_int 23456)),
930
 
        (-2))
931
 
;;
932
 
test 11
933
 
eq_int (msd_ratio (create_ratio (big_int_of_int 2345)
934
 
                                     (big_int_of_int 2346)),
935
 
        (-1))
936
 
;;
937
 
test 12
938
 
eq_int (msd_ratio (create_ratio (big_int_of_int 2345)
939
 
                                     (big_int_of_int 2344)),
940
 
        0)
941
 
;;
942
 
test 13
943
 
eq_int (msd_ratio (create_ratio (big_int_of_int 23456)
944
 
                                     (big_int_of_int 2345)),
945
 
        1)
946
 
;;
947
 
test 14
948
 
eq_int (msd_ratio (create_ratio (big_int_of_int 23467)
949
 
                                     (big_int_of_int 2345)),
950
 
        1)
951
 
;;
952
 
failwith_test 15
953
 
msd_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0))
954
 
("msd_ratio "^infinite_failure)
955
 
;;
956
 
failwith_test 16
957
 
msd_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0))
958
 
("msd_ratio "^infinite_failure)
959
 
;;
960
 
failwith_test 17
961
 
msd_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0))
962
 
("msd_ratio "^infinite_failure)
963
 
;;
964
 
*************************)
965
 
 
966
 
testing_function "round_futur_last_digit"
967
 
;;
968
 
 
969
 
let s = "+123456" in
970
 
test 1 eq (round_futur_last_digit s 1 (pred (String.length s)),
971
 
            false) &&
972
 
test 2 eq_string (s, "+123466")
973
 
;;
974
 
 
975
 
let s = "123456" in
976
 
test 3 eq (round_futur_last_digit s 0 (String.length s), false) &&
977
 
test 4 eq_string (s, "123466")
978
 
;;
979
 
 
980
 
let s = "-123456" in
981
 
test 5 eq (round_futur_last_digit s 1 (pred (String.length s)),
982
 
            false) &&
983
 
test 6 eq_string (s, "-123466")
984
 
;;
985
 
 
986
 
let s = "+123496" in
987
 
test 7 eq (round_futur_last_digit s 1 (pred (String.length s)),
988
 
            false) &&
989
 
test 8 eq_string (s, "+123506")
990
 
;;
991
 
 
992
 
let s = "123496" in
993
 
test 9 eq (round_futur_last_digit s 0 (String.length s), false) &&
994
 
test 10 eq_string (s, "123506")
995
 
;;
996
 
 
997
 
let s = "-123496" in
998
 
test 11 eq (round_futur_last_digit s 1 (pred (String.length s)),
999
 
            false) &&
1000
 
test 12 eq_string (s, "-123506")
1001
 
;;
1002
 
 
1003
 
let s = "+996" in
1004
 
test 13 eq (round_futur_last_digit s 1 (pred (String.length s)),
1005
 
            true) &&
1006
 
test 14 eq_string (s, "+006")
1007
 
;;
1008
 
 
1009
 
let s = "996" in
1010
 
test 15 eq (round_futur_last_digit s 0 (String.length s), true) &&
1011
 
test 16 eq_string (s, "006")
1012
 
;;
1013
 
 
1014
 
let s = "-996" in
1015
 
test 17 eq (round_futur_last_digit s 1 (pred (String.length s)),
1016
 
             true) &&
1017
 
test 18 eq_string (s, "-006")
1018
 
;;
1019
 
 
1020
 
let s = "+6666666" in
1021
 
test 19 eq (round_futur_last_digit s 1 (pred (String.length s)),
1022
 
             false) &&
1023
 
test 20 eq_string (s, "+6666676")
1024
 
;;
1025
 
 
1026
 
let s = "6666666" in
1027
 
test 21 eq (round_futur_last_digit s 0 (String.length s), false) &&
1028
 
test 22 eq_string (s, "6666676")
1029
 
;;
1030
 
 
1031
 
let s = "-6666666" in
1032
 
test 23 eq (round_futur_last_digit s 1 (pred (String.length s)),
1033
 
             false) &&
1034
 
test 24 eq_string (s, "-6666676")
1035
 
;;
1036
 
 
1037
 
testing_function "approx_ratio_fix"
1038
 
;;
1039
 
 
1040
 
let s = approx_ratio_fix 5
1041
 
                          (create_ratio (big_int_of_int 2)
1042
 
                                        (big_int_of_int 3)) in
1043
 
test 1
1044
 
eq_string (s, "+0.66667")
1045
 
;;
1046
 
 
1047
 
test 2
1048
 
eq_string (approx_ratio_fix 5
1049
 
                             (create_ratio (big_int_of_int 20)
1050
 
                                           (big_int_of_int 3)),
1051
 
           "+6.66667")
1052
 
;;
1053
 
test 3
1054
 
eq_string (approx_ratio_fix 5
1055
 
                             (create_ratio (big_int_of_int 2)
1056
 
                                           (big_int_of_int 30)),
1057
 
           "+0.06667")
1058
 
;;
1059
 
test 4
1060
 
eq_string (approx_ratio_fix 5
1061
 
                             (create_ratio (big_int_of_string "999996")
1062
 
                                           (big_int_of_string "1000000")),
1063
 
           "+1.00000")
1064
 
;;
1065
 
test 5
1066
 
eq_string (approx_ratio_fix 5
1067
 
                             (create_ratio (big_int_of_string "299996")
1068
 
                                           (big_int_of_string "100000")),
1069
 
           "+2.99996")
1070
 
;;
1071
 
test 6
1072
 
eq_string (approx_ratio_fix 5
1073
 
                             (create_ratio (big_int_of_string "2999996")
1074
 
                                           (big_int_of_string "1000000")),
1075
 
           "+3.00000")
1076
 
;;
1077
 
test 7
1078
 
eq_string (approx_ratio_fix 4
1079
 
                             (create_ratio (big_int_of_string "299996")
1080
 
                                           (big_int_of_string "100000")),
1081
 
           "+3.0000")
1082
 
;;
1083
 
test 8
1084
 
eq_string (approx_ratio_fix 5
1085
 
                             (create_ratio (big_int_of_int 29996)
1086
 
                                           (big_int_of_string "100000")),
1087
 
           "+0.29996")
1088
 
;;
1089
 
test 9
1090
 
eq_string (approx_ratio_fix 5
1091
 
                             (create_ratio (big_int_of_int 0)
1092
 
                                           (big_int_of_int 1)),
1093
 
           "+0")
1094
 
;;
1095
 
failwith_test 10
1096
 
(approx_ratio_fix 5) (create_ratio (big_int_of_int 1) (big_int_of_int 0))
1097
 
(Failure "approx_ratio_fix infinite or undefined rational number")
1098
 
;;
1099
 
failwith_test 11
1100
 
(approx_ratio_fix 5) (create_ratio (big_int_of_int 0) (big_int_of_int 0))
1101
 
(Failure "approx_ratio_fix infinite or undefined rational number")
1102
 
;;
1103
 
 
1104
 
(* PR#4566 *)
1105
 
test 12
1106
 
eq_string (approx_ratio_fix 8
1107
 
                            (create_ratio (big_int_of_int 9603)
1108
 
                                          (big_int_of_string "100000000000")),
1109
 
 
1110
 
          "+0.00000010")
1111
 
;;
1112
 
test 13
1113
 
eq_string (approx_ratio_fix 1
1114
 
                            (create_ratio (big_int_of_int 94)
1115
 
                                          (big_int_of_int 1000)),
1116
 
          "+0.1")
1117
 
;;
1118
 
test 14
1119
 
eq_string (approx_ratio_fix 1
1120
 
                            (create_ratio (big_int_of_int 49)
1121
 
                                          (big_int_of_int 1000)),
1122
 
          "+0.0")
1123
 
;;
1124
 
 
1125
 
testing_function "approx_ratio_exp"
1126
 
;;
1127
 
 
1128
 
test 1
1129
 
eq_string (approx_ratio_exp 5
1130
 
                             (create_ratio (big_int_of_int 2)
1131
 
                                           (big_int_of_int 3)),
1132
 
           "+0.66667e0")
1133
 
;;
1134
 
test 2
1135
 
eq_string (approx_ratio_exp 5
1136
 
                             (create_ratio (big_int_of_int 20)
1137
 
                                           (big_int_of_int 3)),
1138
 
           "+0.66667e1")
1139
 
;;
1140
 
test 3
1141
 
eq_string (approx_ratio_exp 5
1142
 
                             (create_ratio (big_int_of_int 2)
1143
 
                                           (big_int_of_int 30)),
1144
 
           "+0.66667e-1")
1145
 
;;
1146
 
test 4
1147
 
eq_string (approx_ratio_exp 5
1148
 
                             (create_ratio (big_int_of_string "999996")
1149
 
                                           (big_int_of_string "1000000")),
1150
 
           "+1.00000e0")
1151
 
;;
1152
 
test 5
1153
 
eq_string (approx_ratio_exp 5
1154
 
                             (create_ratio (big_int_of_string "299996")
1155
 
                                           (big_int_of_string "100000")),
1156
 
           "+0.30000e1")
1157
 
;;
1158
 
test 6
1159
 
eq_string (approx_ratio_exp 5
1160
 
                             (create_ratio (big_int_of_int 29996)
1161
 
                                           (big_int_of_string "100000")),
1162
 
           "+0.29996e0")
1163
 
;;
1164
 
test 7
1165
 
eq_string (approx_ratio_exp 5
1166
 
                             (create_ratio (big_int_of_int 0)
1167
 
                                           (big_int_of_int 1)),
1168
 
           "+0.00000e0")
1169
 
;;
1170
 
failwith_test 8
1171
 
(approx_ratio_exp 5) (create_ratio (big_int_of_int 1) (big_int_of_int 0))
1172
 
(Failure "approx_ratio_exp infinite or undefined rational number")
1173
 
;;
1174
 
failwith_test 9
1175
 
(approx_ratio_exp 5) (create_ratio (big_int_of_int 0) (big_int_of_int 0))
1176
 
(Failure "approx_ratio_exp infinite or undefined rational number")
1177
 
;;