import deriving 0.1.1a
[deriving.git] / tests / eq_tests.ml
blob41b08b1b66b14b6789e105dd3a195580c65fb038
1 open Defs
3 let sum =
4 begin
5 assert (Eq_sum.eq S0 S0);
6 assert (not (Eq_sum.eq S0 (S1 0)));
7 assert (Eq_sum.eq (S1 0) (S1 0));
8 assert (Eq_sum.eq (Stup (3,0.0)) (Stup (3,0.0)));
9 assert (not (Eq_sum.eq (Stup (0,0.0)) (Stup (1,0.0))));
10 end
12 let nullsum =
13 begin
14 assert (Eq_nullsum.eq N2 N2)
15 end
17 let r1 =
18 begin
19 assert (Eq_r1.eq
20 { r1_l1 = 10; r1_l2 = 20 }
21 { r1_l1 = 10; r1_l2 = 20 });
22 assert (not (Eq_r1.eq
23 { r1_l1 = 20; r1_l2 = 10 }
24 { r1_l1 = 10; r1_l2 = 20 }));
25 end
27 let r2 =
28 begin
29 let l, r = ({ r2_l1 = 10; r2_l2 = 20},
30 { r2_l1 = 10; r2_l2 = 20}) in
31 assert (Eq_r2.eq l l);
32 assert (not (Eq_r2.eq l r));
33 assert (not (Eq_r2.eq r l));
34 end
36 let r3 =
37 begin
38 let l, r = ({ r3_l1 = 10; r3_l2 = 20},
39 { r3_l1 = 10; r3_l2 = 20}) in
40 assert (Eq_r3.eq l l);
41 assert (not (Eq_r3.eq l r));
42 assert (not (Eq_r3.eq r l));
43 end
45 let intseq =
46 begin
47 assert (Eq_intseq.eq INil INil);
48 assert (Eq_intseq.eq
49 (ICons (1,INil))
50 (ICons (1,INil)));
51 assert (not (Eq_intseq.eq
52 (ICons (1,INil))
53 INil));
54 assert (not (Eq_intseq.eq
55 INil
56 (ICons (1,INil))));
57 assert (not (Eq_intseq.eq
58 INil
59 (let rec i = ICons(1,i) in i)));
60 end
62 let uses_seqs =
63 begin
64 let eq = Eq_uses_seqs.eq in
65 assert (eq (INil,Cons(1.0,Nil)) (INil,Cons(1.0,Nil)));
66 assert (not (eq (INil,Cons(1.0,Nil)) (INil,Cons(2.0,Nil))));
67 assert (not (eq (ICons (1,INil),Nil) (INil,Nil)));
68 end
70 let poly0 =
71 begin
72 let eq = Eq_poly0.eq in
73 assert (eq `T0 `T0);
74 assert (not (eq `T1 `T3));
75 end
77 let poly1 =
78 begin
79 let eq = Eq_poly1.eq in
80 assert (eq `T0 `T0);
81 assert (eq (`T1 10) (`T1 10));
82 assert (not (eq (`T1 20) (`T1 10)));
83 assert (not (eq (`T1 20) `T0));
84 end
86 let poly2 =
87 begin
88 let eq = Eq_poly2.eq in
89 assert (eq (P (3, `T0, 0.0)) (P (3, `T0, 0.0)));
90 assert (eq (P (4, `T1 10, 2.0)) (P (4, `T1 10, 2.0)));
91 assert (not (eq (P (5, `T1 10, 2.0)) (P (5, `T0, 2.0))));
92 assert (not (eq (P (6, `T0, 2.0)) (P (6, `T0, 10.0))));
93 assert (not (eq (P (0, `T0, 2.0)) (P (7, `T0, 2.0))));
94 end
97 let poly3 =
98 begin
99 let eq = Eq_poly3.eq in
100 assert (eq `Nil `Nil);
101 assert (eq (`Cons (3,`Nil)) (`Cons (3,`Nil)));
102 assert (eq (`Cons (3,`Cons (4,`Nil))) (`Cons (3,`Cons (4,`Nil))));
103 assert (not (eq (`Cons (3,`Cons (4,`Nil))) (`Cons (3,`Nil))));
106 let poly3b =
107 begin
108 let eq = Eq_poly3b.eq in
109 assert (eq (0,`Nil,`F) (0,`Nil,`F));
110 assert (not (eq (0,`Cons (1,`Nil),`F) (0,`Nil,`F)));
111 assert (not (eq (1,`Nil,`F) (0,`Nil,`F)));
115 let poly7_8 =
116 begin
117 let module M7 = Eq_poly7(Eq.Eq_int) in
118 let module M8 = Eq_poly8(Eq.Eq_int) in
119 assert (M7.eq (Foo (`F 0)) (Foo (`F 0)));
120 assert (not (M7.eq (Foo (`F 0)) (Foo (`F 1))));
121 assert (M8.eq
122 {x = `G (`H (`I (Foo (`F 0))))}
123 {x = `G (`H (`I (Foo (`F 0))))});
124 assert (not
125 (M8.eq
126 {x = `G (`H (`I (Foo (`F 0))))}
127 {x = `G (`H (`I (Foo (`F 1))))}));
130 let poly10 =
131 begin
132 let eq = Eq_poly10.eq in
133 assert (eq `F `F);
134 assert (eq `Nil `Nil);
135 assert (not (eq `Nil `F));
138 let mutrec =
139 begin
140 let rec cyclic_1 = S (0, cyclic_2)
141 and cyclic_2 = S (1, cyclic_1) in
142 assert (not (Eq_mutrec_a.eq cyclic_1 cyclic_2));
143 assert (not
144 (Eq_mutrec_d.eq
145 (`T {l1 = cyclic_1; l2 = cyclic_2})
146 (`T {l1 = cyclic_2; l2 = cyclic_1})));
149 let pmutrec =
150 begin
151 let module M_a = Eq_pmutrec_a(Eq.Eq_int)(Eq.Eq_bool) in
152 let module M_b = Eq_pmutrec_b(Eq.Eq_int)(Eq.Eq_bool) in
153 let module M_c = Eq_pmutrec_c(Eq.Eq_int)(Eq.Eq_bool) in
154 let module M_d = Eq_pmutrec_d(Eq.Eq_int)(Eq.Eq_bool) in
156 let rec cyclic_1 = SS (0, cyclic_2, true)
157 and cyclic_2 = SS (1, cyclic_1, true) in
158 assert (not (M_a.eq cyclic_1 cyclic_2));
159 assert (not
160 (M_d.eq
161 (`T {pl1 = cyclic_1; pl2 = cyclic_2})
162 (`T {pl1 = cyclic_2; pl2 = cyclic_1})));
166 let ff1 =
167 begin
168 let module M = Eq_ff1(Eq.Eq_bool) in
169 assert (M.eq (F (true,false)) (F (true,false)));
170 assert (M.eq (G (-1)) (G (-1)));
171 assert (not (M.eq (F (false,true)) (F (true,false))));
172 assert (not (M.eq (G (-1)) (G 0)));
173 assert (not (M.eq (G (-1)) (F (true, true))));
176 let ff2 =
177 begin
178 let module M = Eq_ff2(Eq.Eq_bool)(Eq.Eq_bool) in
179 assert (M.eq
180 (F1 (F2 (Cons (true,Nil), 0, None)))
181 (F1 (F2 (Cons (true,Nil), 0, None))));
183 assert (not (M.eq
184 (F2 (Nil, 0, None))
185 (F2 (Cons (true,Nil), 0, None))));
187 assert (not (M.eq
188 (F2 (Cons (true,Nil), 0, Some true))
189 (F2 (Cons (true,Nil), 0, Some false))));
191 assert (not (M.eq
192 (F2 (Cons (true,Nil), 0, None))
193 (F2 (Cons (true,Nil), 0, Some false))));
196 let tup0 =
197 begin
198 assert (Eq_tup0.eq () ());
201 let tup2 =
202 begin
203 assert (Eq_tup2.eq (10,5.0) (10,5.0));
204 assert (not (Eq_tup2.eq (10,5.0) (11,5.0)));
205 assert (not (Eq_tup2.eq (10,5.0) (10,4.0)));
208 let tup3 =
209 begin
210 assert (Eq_tup3.eq (10,2.5,true) (10,2.5,true));
211 assert (not (Eq_tup3.eq (10,2.5,true) (11,2.5,true)));
212 assert (not (Eq_tup3.eq (10,2.5,true) (10,2.4,true)));
213 assert (not (Eq_tup3.eq (10,2.5,true) (10,2.5,false)));
216 let tup4 =
217 begin
218 assert (Eq_tup4.eq (1,2,true,()) (1,2,true,()));
219 assert (not (Eq_tup4.eq (1,2,true,()) (0,2,true,())));
220 assert (not (Eq_tup4.eq (1,2,true,()) (1,3,true,())));
221 assert (not (Eq_tup4.eq (1,2,true,()) (1,2,false,())));
224 let withref =
225 begin
226 let x = ref 0 in
227 assert (Eq_withref.eq (WR (0,x)) (WR (0,x)));
228 assert (not (Eq_withref.eq (WR (0,x)) (WR (0,ref 0))));
231 let t =
232 begin
233 assert (Eq_t.eq 0 0);
234 assert (Eq_t.eq (-10) (-10));
235 assert (Eq_t.eq 14 14);
236 assert (not (Eq_t.eq 14 0));
237 assert (not (Eq_t.eq 0 14));
238 assert (not (Eq_t.eq (-1) 0));