File: test_suite.ml

package info (click to toggle)
mlgmp 20021123-20
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 512 kB
  • sloc: ansic: 3,257; ml: 3,126; makefile: 167
file content (106 lines) | stat: -rw-r--r-- 5,285 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
open Gmp;;

assert ((Z.from_int 578) = (let r = Z2.create () in Z2.copy r (Z.from_int 578); r));
assert ((Z.from_int 578) = (let r = Z2.create () in Z2.from_int r 578; r));
assert ((Z.from_int 578) = (let r = Z2.create () in Z2.from_string_base r 10 "578"; r));
(*to be used only with corrected sources *)
(*assert ((Z.from_int 578) = (Z.copy (Z.from_int 578)));*)
assert ((Z.from_int 578) = (let r = Z2.create () in Z2.from_float r 578.; r));
assert ((Z.from_int 578) = (Z.from_string_base ~base: 10 "578"));
assert ((Z.from_int 578) = (Z.from_float 578.));
assert ((Z.to_string_base ~base: 10 (Z.from_int 578)) = "578");
assert ((Z.to_int (Z.from_int 578)) = 578);
assert ((Z.to_float (Z.from_int 578)) = 578.);
assert ((Z.add (Z.from_int 45) (Z.from_int (- 51))) = (Z.from_int (- 6)));
assert ((Z.sub (Z.from_int 45) (Z.from_int (- 51))) = (Z.from_int 96));
assert ((Z.mul (Z.from_int 45) (Z.from_int (- 51))) = (Z.from_int (- 2295)));
assert ((Z.add_ui (Z.from_int 45) 37) = (Z.from_int 82));
assert ((Z.sub_ui (Z.from_int 45) 37) = (Z.from_int 8));
assert ((Z.to_int (Z.mul_ui (Z.from_int 45) 37)) = 1665);
assert ((Z.neg (Z.from_int 45)) = (Z.from_int (- 45)));
assert ((Z.abs (Z.from_int (- 45))) = (Z.from_int 45));
assert ((Z.modulo (Z.from_int 6502) (Z.from_int 45)) = (Z.from_int 22));
assert ((Z.mul_2exp (Z.from_int 45) 2) = (Z.from_int 180));
assert ((Z.fdiv_q_2exp (Z.from_int 45) 2) = (Z.from_int 11));
assert ((Z.powm (Z.from_int 3) (Z.from_int 57) (Z.from_int 4))
      = (Z.from_int 3));
assert ((Z.powm_ui (Z.from_int 3) 57 (Z.from_int 4))
      = (Z.from_int 3));
assert ((Z.cdiv_qr (Z.from_int 3) (Z.from_int 2)) =
	((Z.from_int 2), (Z.from_int (-1))));
assert (Z.equal (Z.mul2exp (Z.from_int 3) 2) (Z.from_int 12));
assert (Z.equal (Z.cdiv_q_2exp (Z.from_int 13) 1) (Z.from_int 7));
assert (Z.perfect_power_p (Z.pow_ui (Z.from_int 13) 45));
assert (Z.perfect_square_p ( Z.pow_ui (Z.from_string "134897980976978091") 2));
assert ((Z.legendre (Z.from_int 4) (Z.from_int 23)) = 1);
assert ((Z.legendre (Z.from_int 5) (Z.from_int 23)) = -1);
assert (Z.is_probab_prime (Z.nextprime (Z.from_string "1348913489791348979809769780980976978097980976978098097980979809809")) 30);

(* TODO: the rest of Z is missing *)

begin
assert ((Q.from_int 578) = (Q.from_z (Z.from_string_base ~base: 10 "578")));
let one = Q.from_int 1 in
let two = Q.add one one in
let three = Q.add one two in
let six = Q.mul two three in
let a = Q.inv two
and b = Q.div one three in
let c = Q.sub a b in
assert ((Q.from_float 1.5) = (Q.div three two));
assert ((Q.to_float (Q.div three two)) = 1.5);
assert (c = (Q.div one six));
assert ((Q.neg c) = (Q.neg (Q.div one six)));
assert ((Q.get_den c) = (Q.get_num six));
assert ((Q.cmp_ui a 1 2) = 0);
assert ((Q.compare (Q.inv b) (Q.from_ints 3 1)) = 0);
assert ((Q.compare b (Q.from_ints 1 3)) = 0);
assert ((Q.sgn a) > 0);
assert (not (Q.is_zero a));
assert (Q.is_zero (Q.sub c (Q.from_zs (Z.from_int 1) (Z.from_int 6))));
assert (Z.equal (Q.get_den c) (Z.from_int 6));
assert (Z.equal (Q.get_den c) (Q.get_num six));
assert (Q.equal c (Q.from_ints 1 6));
assert ((Q.to_string one) = "1/1");
assert ((Printf.sprintf "%a" Q.sprintf c) = "1/6");
end;

assert ((F.from_int 578) = (F.from_string_base ~base: 10 "578"));
assert ((F.from_int 578) = (F.from_float 578.));
assert ((float_of_string (F.to_string (F.from_int 578))) = 578.);
assert ((F.to_float (F.from_int 578)) = 578.);

assert ((F.add (F.from_int 45) (F.from_int (- 51))) = (F.from_int (- 6)));
assert ((F.sub (F.from_int 45) (F.from_int (- 51))) = (F.from_int 96));
assert ((F.mul (F.from_int 45) (F.from_int (- 51))) = (F.from_int (- 2295)));
assert ((F.add_ui (F.from_int 45) 37) = (F.from_int 82));
assert ((F.sub_ui (F.from_int 45) 37) = (F.from_int 8));
assert ((F.to_float (F.mul_ui (F.from_int 45) 37)) = 1665.);
assert ((F.neg (F.from_int 45)) = (F.from_int (- 45)));
assert ((F.abs (F.from_int (- 45))) = (F.from_int 45));
assert ((F.floor (F.from_string "-2.2947E3")) = (F.from_int (- 2295)));
assert ((F.compare (F.from_string "478.99") (F.from_float 478.67)) > 0);
assert ((F.sgn (F.from_string "-478.99")) < 0);
assert (F.eq (F.from_string "478.99") (F.from_float 478.99) ~prec: 6);

begin
try
assert ((FR.from_int 578) = (FR.from_string_base ~base: 10 "578"));
assert ((FR.from_int 578) = (FR.from_float 578.));
assert ((float_of_string (FR.to_string (FR.from_int 578))) = 578.);
assert ((FR.to_float (FR.from_int 578)) = 578.);
assert ((FR.add (FR.from_int 45) (FR.from_int (- 51))) = (FR.from_int (- 6)));
assert ((FR.sub (FR.from_int 45) (FR.from_int (- 51))) = (FR.from_int 96));
assert ((FR.mul (FR.from_int 45)(FR.from_int (- 51)))=(FR.from_int (- 2295)));
assert ((FR.add_ui (FR.from_int 45) 37) = (FR.from_int 82));
assert ((FR.sub_ui (FR.from_int 45) 37) = (FR.from_int 8));
assert ((FR.to_float (FR.mul_ui (FR.from_int 45) 37)) = 1665.);
assert ((FR.neg (FR.from_int 45)) = (FR.from_int (- 45)));
assert ((FR.abs (FR.from_int (- 45))) = (FR.from_int 45));
assert ((FR.floor (FR.from_string "-2.2947E3")) = (FR.from_int (- 2295)));
assert ((FR.compare (FR.from_string "478.99") (FR.from_float 478.67)) > 0);
assert ((FR.sgn (FR.from_string "-478.99")) < 0);
assert (FR.eq (FR.from_string "478.99") (FR.from_float 478.99) ~prec: 6)

with Unimplemented _ -> ()
end;;