This repository has been archived by the owner on May 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.ml
363 lines (353 loc) · 10.6 KB
/
tests.ml
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
(* some int Items*)
let i0 = CstInt(0);;
let i1 = CstInt(1);;
let i2 = CstInt(-2);;
let i3 = CstInt(3);;
let i4 = CstInt(100);;
(* some float Items*)
let f0 = CstFloat(0.);;
let f1 = CstFloat(1.);;
let f2 = CstFloat(-2.);;
let f3 = CstFloat(3.);;
let f4 = CstFloat(100.);;
(* some boolean Items *)
let b0 = CstFalse;;
let b1 = CstTrue;;
(* some string Items*)
let s0 = CstString("");;
let s1 = CstString("aaaa");;
let s2 = CstString("bbb");;
let s3 = CstString("123456789");;
print_string "testing set constructors: ";;
print_string "Set 0: ";;
let set0 = Empty(Float);;
eval set0 emptyEnv;;
print_string "Set 1: ";;
let set1 = Singleton(i3);;
eval set1 emptyEnv;;
print_string "Set 2: ";;
let set2 = Of(Bool, []);;
eval set2 emptyEnv;;
print_string "Set 3: ";;
let set3 = Of(Int,[]);;
eval set3 emptyEnv;;
print_string "Set 6: ";;
let set6 = Singleton(f3);;
eval set6 emptyEnv;;
print_string "Set 7: ";;
let set7 = Singleton(s3);;
eval set7 emptyEnv;;
print_string "Set 8: ";;
let set8 = Singleton(b0);;
eval set8 emptyEnv;;
print_string "Set 9: ";;
let set9 = Of(Int,[i0;i1;i2;i3;i4]);;
eval set9 emptyEnv;;
print_string "Set 10: ";;
let set10 = Of(Int, [i0]) ;;
eval set10 emptyEnv;;
print_string "Set 11: ";;
let set11 = Singleton(i0) ;;
eval set11 emptyEnv;;
print_string "testing if Set 10 and 11 are different: ";;
let b = set10<>set11;;
(eval (set10) emptyEnv)<>(eval (set11) emptyEnv);;
print_string "testing operations for integers: ";;
print_string "testing the sum: ";;
let op0 = Sum(i3,i2);;
eval op0 emptyEnv;;
print_string "testing the subtraction: ";;
let op1 = Sub(i0,i2);;
eval op1 emptyEnv;;
print_string "testing the negation: ";;
let op3 = Neg(i2);;
eval op3 emptyEnv;;
print_string "testing the multiplication: ";;
let op4 = Times(i2,i4);;
eval op4 emptyEnv;;
print_string "testing the division: ";;
let op5 = Div(i4,Neg(i2));;
eval op5 emptyEnv;;
print_string "testing the equality: ";;
let op6 = Eq(i0,i0);;
eval op6 emptyEnv;;
let op7 = Eq(i0,i3);;
eval op7 emptyEnv;;
print_string "testing < and >: ";;
let op8 = BiggerThan(i2,i0);;
eval op8 emptyEnv;;
let op9 = BiggerThan(i0,i2);;
eval op9 emptyEnv;;
let op1 = LessThan(i0,i2);;
eval op1 emptyEnv;;
print_string "testing IsZero: ";;
let op2 = IsZero(i0);;
eval op2 emptyEnv;;
let op3 = IsZero(i1);;
eval op3 emptyEnv;;
print_string "testing the modulus: ";;
let op0 = Mod(i4,i3);;
eval op0 emptyEnv;;
print_string "testing operations for floats: ";;
print_string "testing the sum: ";;
let op0 = Sum(f3,f2);;
eval op0 emptyEnv;;
print_string "testing the subtraction: ";;
let op1 = Sub(f0,f2);;
eval op1 emptyEnv;;
print_string "testing the negation: ";;
let op3 = Neg(f2);;
eval op3 emptyEnv;;
print_string "testing the multiplication: ";;
let op4 = Times(f2,f4);;
eval op4 emptyEnv;;
print_string "testing the division: ";;
let op5 = Div(f4,Neg(f2));;
eval op5 emptyEnv;;
print_string "testing the equality: ";;
let op6 = Eq(f0,f0);;
eval op6 emptyEnv;;
let op7 = Eq(f0,f3);;
eval op7 emptyEnv;;
print_string "testing < and >: ";;
let op8 = BiggerThan(f2,f0);;
eval op8 emptyEnv;;
let op9 = BiggerThan(f0,f2);;
eval op9 emptyEnv;;
let op1 = LessThan(f0,f2);;
eval op1 emptyEnv;;
print_string "testing operations for booleans: ";;
print_string "testing the negation: ";;
let op0 = Not(b1);;
eval op0 emptyEnv;;
print_string "testing the and: ";;
let op1 = And(op0, b1);;
eval op1 emptyEnv;;
print_string "testing the and the negation: ";;
let op2 = And(Not(op1), b1);;
eval op2 emptyEnv;;
print_string "testing the or: ";;
let op3 = Or(op0, b0);;
eval op3 emptyEnv;;
print_string "testing operations for strings: ";;
print_string "testing the equality: ";;
let op0 = Eq(s1,s1);;
eval op0 emptyEnv;;
let op1 = Eq(s1, s0);;
eval op1 emptyEnv;;
print_string "testing < and >: ";;
let op2 = BiggerThan(s2, s1);;
eval op2 emptyEnv;;
let op3 = BiggerThan(s1, s2);;
eval op3 emptyEnv;;
let op4 = LessThan(s0,s2);;
eval op4 emptyEnv;;
let op5 = LessThan(s2,s0);;
eval op5 emptyEnv;;
let op6 = LessThan(s0,s0);;
eval op6 emptyEnv;;
print_string "testing the concatenation: ";;
let op7 = Concat(s1,s2);;
eval op7 emptyEnv;;
let op8 = Concat(op7,s3);;
eval op8 emptyEnv;;
print_string "testing operations for sets: ";;
print_string "testing the union: ";;
let op1 = Union(set9, Add(Add(set1,CstInt(189)), CstInt(22)));;
eval op1 emptyEnv;;
let op2 = Union(set3, set1);;
eval op2 emptyEnv;;
let op3 = Union(set6, set0);;
eval op3 emptyEnv;;
print_string "testing the intersection: ";;
let op4 = Intersection(set0,set6);;
eval op4 emptyEnv;;
let op5 = Intersection(set6,set0);;
eval op5 emptyEnv;;
let op6 = Intersection(set9, Add(Add(set10, i3), CstInt(22)));;
eval op6 emptyEnv;;
let op7 = Intersection(set8,set8);;
eval op7 emptyEnv;;
let op8 = Intersection(set9,set11);;
eval op8 emptyEnv;;
print_string "testing the difference: ";;
let op8 = Difference(set9,set11);;
eval op8 emptyEnv;;
let op9 = Difference(set6,set0);;
eval op9 emptyEnv;;
let op1 = Difference(set0,set6);;
eval op1 emptyEnv;;
print_string "testing the insertion: ";;
let op2 = Add(set7, s2);;
eval op2 emptyEnv;;
let op3 = Add(set9, CstInt(77));;
eval op3 emptyEnv;;
let op5 = Add(set0,f1);;
eval op5 emptyEnv;;
print_string "testing the removal: ";;
let op2 = Remove(set7, s3);;
eval op2 emptyEnv;;
let op3 = Remove(set9, i4);;
eval op3 emptyEnv;;
print_string "testing the minimum and maximum: ";;
let op0 = GetMin(set9);;
eval op0 emptyEnv;;
let op1 = GetMax(set9);;
eval op1 emptyEnv;;
let op2 = GetMin(set0);;
eval op2 emptyEnv;;
let op3 = GetMax(set0);;
eval op3 emptyEnv;;
let op4 = GetMin(set1);;
eval op4 emptyEnv;;
let op5 = GetMax(set1);;
eval op5 emptyEnv;;
print_string "testing IsEmpty: ";;
let op0 = IsEmpty(set0);;
eval op0 emptyEnv;;
let op1 = IsEmpty(set9);;
eval op1 emptyEnv;;
print_string "testing the head: ";;
let op4 = Head(set9);;
eval op4 emptyEnv;;
let op5 = Head(set8);;
eval op5 emptyEnv;;
print_string "testing the length: ";;
let op6 = Length(set7);;
eval op6 emptyEnv;;
let op7 = Length(set9);;
eval op7 emptyEnv;;
let op8 = Length(Remove(set7,s3));;
eval op8 emptyEnv;;
let op9 = Length(Empty(String)) ;;
eval op9 emptyEnv ;;
print_string "testing IsInside: ";;
let op0 = IsInside((Empty(String), s0));;
eval op0 emptyEnv;;
let op1 = IsInside(set9, i0);;
eval op1 emptyEnv;;
let op2 = IsInside(set9, CstInt(33));;
eval op2 emptyEnv;;
print_string "testing IsSubset: ";;
let op0 = IsSubset(set0, set0);;
eval op0 emptyEnv;;
let op3 = IsSubset(Empty(Int),set9);;
eval op3 emptyEnv;;
let op4 = IsSubset((Add(Empty(Int),CstInt 0)),set9);;
eval op4 emptyEnv;;
let op5 = IsSubset(set1, set9);;
eval op5 emptyEnv;;
let op6 = IsSubset(set9, set1);;
eval op6 emptyEnv;;
print_string "testing functions: ";;
(* tests with pred = even, with pred = odd and finally with pred = neg*)
let pred_even=Fun("x",Ifthenelse(Eq(Mod(Den("x"),CstInt(2)),CstInt(0)),CstTrue,CstFalse));;
let pred_odd=Fun("x",Ifthenelse(Not(Eq(Mod(Den("x"),CstInt(2)),CstInt(0))),CstTrue,CstFalse));;
let pred_neg=Fun("x", Neg(Den("x")))
let make_even=Fun("x",Times(Den("x"),CstInt(2)));;
print_string "testing ForAll: ";;
let forall_even=ForAll(pred_even,set9);;
eval forall_even emptyEnv;;
let forall_odd=ForAll(pred_odd,set9);;
eval forall_odd emptyEnv;;
let forall_odd=ForAll(pred_odd,set1);;
eval forall_odd emptyEnv;;
print_string "testing Exists: ";;
let exists_even=Exists(pred_even,set9);;
eval exists_even emptyEnv;;
let exists_odd=Exists(pred_odd,set9);;
eval exists_odd emptyEnv;;
let exists_even=Exists(pred_even,set1);;
eval exists_even emptyEnv;;
print_string "testing Filter: ";;
let filter_even=Filter(pred_even,set9);;
let filter_odd=Filter(pred_odd,set9);;
eval filter_even emptyEnv;;
eval filter_odd emptyEnv;;
print_string "testing Map: ";;
let map_make_even=Map(make_even,set9);;
eval map_make_even emptyEnv;;
let str = Of(String, [CstString("1:");CstString("2:");
CstString("3:");CstString("4:")]) ;;
let pred_concat = Fun("x", Concat(Den("x"), s1)) ;;
let map_concat= Map(pred_concat,str);;
eval map_concat emptyEnv;;
print_string "the mapping function can change types of the resulting set: ";;
let map_turn_to_one = Map(Fun("x", CstInt(1)), set7) ;;
eval map_turn_to_one emptyEnv ;;
let map_neg = Map(pred_neg, set9);;
eval map_neg emptyEnv ;;
print_string "--------------------------------------------------------------";;
print_string "testing failures: ";;
print_string "testing type mismatch: ";;
print_string "Set 4: ";;
let set4 = Of(Int,[f0;i1;i0;i4]);;
eval set4 emptyEnv;;
print_string "on the union: ";;
let op0 = Union(set0,set1);;
eval op0 emptyEnv;;
print_string "on the insertion: ";;
let op4 = Add(set7,b0);;
eval op4 emptyEnv;;
print_string "on IsInside: ";;
let op3 = IsInside(set9, b1);;
eval op3 emptyEnv;;
print_string "on IsSubset: ";;
let op1 = IsSubset(set9, set0);;
eval op1 emptyEnv;;
let op2 = IsSubset(set0, set9);;
eval op2 emptyEnv;;
print_string "on the Map: ";;
let map_failure=Map(make_even,set6);;
eval map_failure emptyEnv;;
print_string "testing for duplicate items: ";;
print_string "Set 5: ";;
let set5 = Of(Int,[i0;i1;i1;i2]);;
eval set5 emptyEnv;;
print_string "on the insertion: ";;
let op3 = Add(set9,i4);;
eval op3 emptyEnv;;
print_string "testing the division by zero: ";;
let op2 = Div(i1, i0);;
eval op2 emptyEnv;;
let op3 = Div(f1, f0);;
eval op3 emptyEnv;;
print_string "testing set consistency: ";;
print_string "on the insertion: ";;
let op5 = Add(set9,Empty(Int));;
eval op5 emptyEnv;;
print_string "testing item presence: ";;
print_string "on the removal: ";;
let op1 = Remove(set0,f0);;
eval op1 emptyEnv;;
let op3 = Remove(set7,s2);;
eval op3 emptyEnv;;
print_string "testing if the set is empty: ";;
print_string "on the head: ";;
let op2 = Head(set3);;
eval op2 emptyEnv;;
let op3 = Head(set0);;
eval op3 emptyEnv;;
print_string "testing if the predicate is a boolean: ";;
print_string "on the ForAll: ";;
let forall_failure = ForAll(pred_neg, set9);;
eval forall_failure emptyEnv;;
print_string "on the Exists: ";;
let exists_failure = Exists(pred_neg, set9);;
eval exists_failure emptyEnv ;;
print_string "on the Filter: ";;
let filter_failure = Filter(pred_neg, set9);;
eval filter_failure emptyEnv ;;
print_string "testing if the pred in f(pred,set) is actually a predicate: ";;
print_string "on the ForAll: ";;
let forall_failure = ForAll(CstInt(3), set9);;
eval forall_failure emptyEnv;;
print_string "on the Exists: ";;
let exists_failure = Exists(CstInt(3), set9);;
eval exists_failure emptyEnv ;;
print_string "on the Filter: ";;
let filter_failure = Filter(CstInt(3), set9);;
eval filter_failure emptyEnv ;;
print_string "on the Map: ";;
let pred_map_failure = Map(CstInt(3),set9) ;;
eval pred_map_failure emptyEnv;;