File: eq_tests.ml

package info (click to toggle)
ocaml-deriving-ocsigen 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 628 kB
  • ctags: 1,159
  • sloc: ml: 6,334; makefile: 63; sh: 18
file content (273 lines) | stat: -rw-r--r-- 7,418 bytes parent folder | download | duplicates (2)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
open Tests_defs

open Deriving_Eq

let sum =
  begin
    assert (Eq_sum.eq S0 S0);
    assert (not (Eq_sum.eq S0 (S1 0)));
    assert (Eq_sum.eq (S1 0) (S1 0));
    assert (Eq_sum.eq (Stup (3,0.0)) (Stup (3,0.0)));
    assert (not (Eq_sum.eq (Stup (0,0.0)) (Stup (1,0.0))));
  end

let nullsum =
  begin
    assert (Eq_nullsum.eq N2 N2)
  end

let r1 = 
  begin
    assert (Eq_r1.eq
              { r1_l1 = 10; r1_l2 = 20 }
              { r1_l1 = 10; r1_l2 = 20 });
    assert (not (Eq_r1.eq
                   { r1_l1 = 20; r1_l2 = 10 }
                   { r1_l1 = 10; r1_l2 = 20 }));
    assert (not (Eq_r1.eq
                   { r1_l1 = 20; r1_l2 = 10 }
                   { r1_l1 = 20; r1_l2 = 20 }));
  end

let r2 =
  begin
    let l, r = ({ r2_l1 = 10; r2_l2 = 20},
                { r2_l1 = 10; r2_l2 = 20}) in
    assert (Eq_r2.eq l l);
    assert (not (Eq_r2.eq l r));
    assert (not (Eq_r2.eq r l));
  end

let r3 =
  begin
    let l, r = ({ r3_l1 = 10; r3_l2 = 20},
                { r3_l1 = 10; r3_l2 = 20}) in
    assert (Eq_r3.eq l l);
    assert (not (Eq_r3.eq l r));
    assert (not (Eq_r3.eq r l));
  end

let intseq = 
  begin
    assert (Eq_intseq.eq INil INil); 
    assert (Eq_intseq.eq
              (ICons (1,INil))
              (ICons (1,INil)));
    assert (not (Eq_intseq.eq
                   (ICons (1,INil))
                   INil));
    assert (not (Eq_intseq.eq
                   INil
                   (ICons (1,INil))));
    assert (not (Eq_intseq.eq
                   INil
                 (let rec i = ICons(1,i) in i)));
  end

let uses_seqs = 
  begin
    let eq = Eq_uses_seqs.eq in
      assert (eq (INil,Cons(1.0,Nil)) (INil,Cons(1.0,Nil)));
      assert (not (eq (INil,Cons(1.0,Nil)) (INil,Cons(2.0,Nil))));
      assert (not (eq (ICons (1,INil),Nil) (INil,Nil)));
  end

let poly0 =
  begin
    let eq = Eq_poly0.eq in
      assert (eq `T0 `T0);
      assert (not (eq `T1 `T3));
  end

let poly1 = 
  begin
    let eq = Eq_poly1.eq in
      assert (eq `T0 `T0);
      assert (eq (`T1 10) (`T1 10));
      assert (not (eq (`T1 20) (`T1 10)));
      assert (not (eq (`T1 20) `T0));
  end

let poly2 = 
  begin
    let eq = Eq_poly2.eq in
      assert (eq (P (3, `T0, 0.0)) (P (3, `T0, 0.0)));
      assert (eq (P (4, `T1 10, 2.0)) (P (4, `T1 10, 2.0)));
      assert (not (eq (P (5, `T1 10, 2.0)) (P (5, `T0, 2.0))));
      assert (not (eq (P (6, `T0, 2.0)) (P (6, `T0, 10.0))));
      assert (not (eq (P (0, `T0, 2.0)) (P (7, `T0, 2.0))));
  end


let poly3 =
  begin
    let eq = Eq_poly3.eq in
      assert (eq `Nil `Nil);
      assert (eq (`Cons (3,`Nil)) (`Cons (3,`Nil)));
      assert (eq (`Cons (3,`Cons (4,`Nil))) (`Cons (3,`Cons (4,`Nil))));
      assert (not (eq (`Cons (3,`Cons (4,`Nil))) (`Cons (3,`Nil))));
  end

let poly3b = 
  begin
    let eq = Eq_poly3b.eq in
      assert (eq (0,`Nil,`F)  (0,`Nil,`F));
      assert (not (eq (0,`Cons (1,`Nil),`F)  (0,`Nil,`F)));
      assert (not (eq (1,`Nil,`F)  (0,`Nil,`F)));
  end


let poly7_8 = 
  begin
    let module M7 = Eq_poly7(Eq_int) in
    let module M8 = Eq_poly8(Eq_int) in
      assert (M7.eq (Foo (`F 0)) (Foo (`F 0)));
      assert (not (M7.eq (Foo (`F 0)) (Foo (`F 1))));
      assert (M8.eq
                {x = `G (`H (`I (Foo (`F 0))))}
                {x = `G (`H (`I (Foo (`F 0))))});
      assert (not
                (M8.eq
                   {x = `G (`H (`I (Foo (`F 0))))}
                   {x = `G (`H (`I (Foo (`F 1))))}));
  end

let poly10 = 
  begin
    let eq = Eq_poly10.eq in
      assert (eq `F `F);
      assert (eq `Nil `Nil);
      assert (not (eq `Nil `F));
  end

let mutrec = 
  begin
    let rec cyclic_1 = S (0, cyclic_2)
    and     cyclic_2 = S (1, cyclic_1) in
      assert (not (Eq_mutrec_a.eq cyclic_1 cyclic_2));
      assert (not 
                (Eq_mutrec_d.eq 
                   (`T {l1 = cyclic_1; l2 = cyclic_2})
                   (`T {l1 = cyclic_2; l2 = cyclic_1})));
  end

let pmutrec = 
  begin
    let module M_a = Eq_pmutrec_a(Eq_int)(Eq_bool) in
    let module M_b = Eq_pmutrec_b(Eq_int)(Eq_bool) in
    let module M_c = Eq_pmutrec_c(Eq_int)(Eq_bool) in
    let module M_d = Eq_pmutrec_d(Eq_int)(Eq_bool) in
    
    let rec cyclic_1 = SS (0, cyclic_2, true)
    and     cyclic_2 = SS (1, cyclic_1, true) in
      assert (not (M_a.eq cyclic_1 cyclic_2));
      assert (not 
                (M_d.eq 
                   (`T {pl1 = cyclic_1; pl2 = cyclic_2})
                   (`T {pl1 = cyclic_2; pl2 = cyclic_1})));
  end


let ff1 =
  begin
    let module M = Eq_ff1(Eq_bool) in
      assert (M.eq (F (true,false)) (F (true,false)));
      assert (M.eq (G (-1)) (G (-1)));
      assert (not (M.eq (F (false,true)) (F (true,false))));
      assert (not (M.eq (G (-1)) (G 0)));
      assert (not (M.eq (G (-1)) (F (true, true))));
  end

let ff2 = 
  begin
    let module M = Eq_ff2(Eq_bool)(Eq_bool) in
      assert (M.eq
                (F1 (F2 (Cons (true,Nil), 0, None)))
                (F1 (F2 (Cons (true,Nil), 0, None))));

      assert (not (M.eq
                     (F2 (Nil, 0, None))
                     (F2 (Cons (true,Nil), 0, None))));

      assert (not (M.eq
                     (F2 (Cons (true,Nil), 0, Some true))
                     (F2 (Cons (true,Nil), 0, Some false))));

      assert (not (M.eq
                     (F2 (Cons (true,Nil), 0, None))
                     (F2 (Cons (true,Nil), 0, Some false))));
  end

let tup0 =
  begin
    assert (Eq_tup0.eq () ());
  end

let tup2 = 
  begin
    assert (Eq_tup2.eq (10,5.0) (10,5.0));
    assert (not (Eq_tup2.eq (10,5.0) (11,5.0)));
    assert (not (Eq_tup2.eq (10,5.0) (10,4.0)));
  end

let tup3 =
  begin
    assert (Eq_tup3.eq (10,2.5,true) (10,2.5,true));
    assert (not (Eq_tup3.eq (10,2.5,true) (11,2.5,true)));
    assert (not (Eq_tup3.eq (10,2.5,true) (10,2.4,true)));
    assert (not (Eq_tup3.eq (10,2.5,true) (10,2.5,false)));
  end

let tup4 =
  begin
    assert (Eq_tup4.eq (1,2,true,()) (1,2,true,()));
    assert (not (Eq_tup4.eq (1,2,true,()) (0,2,true,())));
    assert (not (Eq_tup4.eq (1,2,true,()) (1,3,true,())));
    assert (not (Eq_tup4.eq (1,2,true,()) (1,2,false,())));
  end

let withref =
  begin
    let x = ref 0 in
      assert (Eq_withref.eq (WR (0,x)) (WR (0,x)));
      assert (not (Eq_withref.eq (WR (0,x)) (WR (0,ref 0))));
  end

let t =
  begin
    assert (Eq_t.eq 0 0);
    assert (Eq_t.eq (-10) (-10));
    assert (Eq_t.eq 14 14);
    assert (not (Eq_t.eq 14 0));
    assert (not (Eq_t.eq 0 14));
    assert (not (Eq_t.eq (-1) 0));
  end

let ii =
  begin
    assert (Eq_ii.eq
	      {int32 = 0l ; int64 = 1L ; nativeint = 2n; }
	      {int32 = 0l ; int64 = 1L ; nativeint = 2n; });
    assert (not (Eq_ii.eq
	      {int32 = 0l ; int64 = 1L ; nativeint = 2n; }
	      {int32 = 1l ; int64 = 1L ; nativeint = 2n; }));
    assert (not (Eq_ii.eq
	      {int32 = 0l ; int64 = 1L ; nativeint = 2n; }
	      {int32 = 0l ; int64 = 2L ; nativeint = 2n; }));
    assert (not (Eq_ii.eq
	      {int32 = 0l ; int64 = 1L ; nativeint = 2n; }
	      {int32 = 0l ; int64 = 1L ; nativeint = 3n; }));
  end

let ii' =
  begin
    assert (Eq_ii'.eq
	      {int32' = 0l ; int64' = 1L ; }
	      {int32' = 0l ; int64' = 1L ; });
    assert (not (Eq_ii'.eq
	      {int32' = 0l ; int64' = 1L ; }
	      {int32' = 1l ; int64' = 1L ; }));
    assert (not (Eq_ii'.eq
	      {int32' = 0l ; int64' = 1L ; }
	      {int32' = 0l ; int64' = 2L ; }));
  end