forked from matijapretnar/eff
/
test_pervasives.eff
190 lines (100 loc) · 3.76 KB
/
test_pervasives.eff
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
(* Check every thing in pervasives. *)
let less1 = (1 < 2) ;;
let less2 = (true < false) ;;
let less3 = ((1,true) < (0,false)) ;;
let test_equal_number = (1 = 1) ;;
let test_equal_fun = ((fun x -> x) = (fun x -> x + 1)) ;;
let whatis_std = std ;;
let whatis_raise = raise ;;
let whatis_exception = exception ;;
let whatis_divisionByZero = divisionByZero ;;
let whatis_invalidArgument = invalidArgument ;;
let whatis_assertionFault = assertionFault ;;
let whatis_failure = failure ;;
let test_divisionByZero =
handle let x = 1 / 0 in "bar" with divisionByZero#raise _ _ -> "foo"
let test_invalidArgument =
handle "invalidArgument was here" with invalidArgument#raise "foo" _ -> "No he was not" ;;
check (failwith "They say it's all about flirting.") ;;
let test_failure = handle failwith "bar" with failure#raise "bar" _ -> 42 ;;
assert ("a" = "a") ;;
let tilda_minus = (~-1) ;;
let tilda_minus_dot2 = (~-. 3.14159) ;;
let tilda_minus_dot2 = (~-. 1.0) ;;
let test_plus = (2 + 2) ;;
let test_times = (2 * 2) ;;
let test_power = (2 ** 3) ;;
let test_minus = (42 - 23) ;;
let test_minus_tilda_minus = (42 - ~-23) ;;
let test_mod1 = (5 % 3) ;;
let test_mod2 = (0 % 1) ;;
check (0 % 0) ;;
check (1 % 0) ;;
let test_plus_dot = (3.14 +. 2.7) ;;
let test_times_dot = (3.14 *. 2.7) ;;
let test_minus_dot = (3.14 -. 2.7) ;;
let test_div_dot = (3.14 /. 2.7) ;;
let test_div_dot_zero = (1.0 /. 0.0) ;;
let test_div = (100 / 3) ;;
check (1 / 0) ;;
let test_zero_div = (0 / 1) ;;
check (0 / 0) ;;
let test_carron = ("cherry" ^ "pie") ;;
let test_to_string1 = (to_string 13) ;;
let test_to_string2 = (to_string [1,2,3]) ;;
let test_to_string3 = (to_string (1,2,3)) ;;
let test_to_string4 = (to_string (fun x -> x)) ;;
let test_float = (float 42) ;;
let test_none = None ;;
let test_some = (Some 3) ;;
let test_ignore = (ignore (2 + 3)) ;;
let test_not = (not true) ;;
let test_greater1 = (3 > 2) ;;
let test_greater2 = ("foo" > "bar") ;;
let test_leq = (1 <= 1) ;;
let test_geq = (2 >= 1) ;;
let test_neq = (2 <> 3) ;;
let test_range = (range 4 9) ;;
let test_map = (map (fun x -> x * x) [1;2;3;4;5]) ;;
let test_take = (take (fun k -> 3 * k + 2) 20) ;;
let test_fold_left = (fold_left (fun a y -> 2 * a + y) 1 [1;2;3;4;5]) ;;
let test_fold_right = (fold_right (fun y a -> 2 * a + y) [1;2;3;4;5] 1) ;;
let test_iter = (fun k -> check ("iter " ^ to_string k)) [1;2;3;4;5] ;;
let test_forall = (forall (fun k -> k % 3 = 2) [1;2;3;4;5]) ;;
let test_exists = (exists (fun k -> k % 3 = 2) [1;2;3;4;5]) ;;
let test_mem = (mem "foo" ["bar"; "baz"]) ;;
let test_filter = (filter (fun k -> k > 3) [1;2;3;4;5]) ;;
let test_complement = (complement [1; 2; 3; 4; 5; 6] [2; 4; 8]) ;;
let test_intersection = (intersection [1; 2; 3; 4; 5; 6] [2; 4; 8]) ;;
let test_zip1 = (zip [1;2;3] ["a"; "b"; "c"]) ;;
check (zip [1;2;3;4;5;6] ["a"; "b"; "c"]) ;;
let test_reverse = reverse [1;2;3;4;5] ;;
let test_at = ([1;2;3] @ [4;5;6]) ;;
let test_length = (length [1;2;3;4;5]) ;;
let test_head = (head [1;2;3;4]) ;;
check (head []) ;;
let test_tail = (tail [1;2;3;4]) ;;
check (tail []) ;;
let test_abs = (abs 5, abs (~-5), abs(-5)) ;;
let test_min = (min 1 2) ;;
let test_max = (max 1 2) ;;
let test_gcd = (gcd 12 8) ;;
let test_lcm = (lcm 12 8) ;;
let test_odd = (odd 42) ;;
let test_even = (even 42) ;;
let test_id = (id 5) ;;
let test_id_id = (id id) ;;
let test_compose = (compose (fun k -> k * k) (fun j -> j +4) 10) ;;
let test_fst = (fst ("foo", 4)) ;;
let test_snd = (snd ("foo", 4)) ;;
(std#write "Does this work?") ;;
check (std#read ()) ;;
check (failwith "The cows are home.") ;;
check (rnd#int 42) ;;
check (rnd#float 42.0) ;;
let test_state =
(let r = new ref in
with state r 10 handle
r := !r + 32 ;
!r) ;;
let test_ref = (let r = ref 5 in r := !r + 10; !r) ;;