blob: 1458fdcb87f1d80a6d6dea2829cd54702c05ea8b (
plain)
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
|
open Printf
let error_occurred = ref false
let function_tested = ref ""
let testing_function s =
function_tested := s;
print_newline();
print_string s;
print_newline()
let test test_number eq_fun (answer, correct_answer) =
flush stdout;
flush stderr;
if not (eq_fun answer correct_answer) then begin
fprintf stderr ">>> Bad result (%s, test %d)\n" !function_tested test_number;
error_occurred := true;
false
end else begin
printf " %d..." test_number;
true
end
let failure_test test_number fun_to_test arg =
flush stdout;
flush stderr;
try
fun_to_test arg;
fprintf stderr ">>> Failure expected (%s, test %d)\n"
!function_tested test_number;
error_occurred := true;
false
with _ ->
printf " %d..." test_number;
true
let failwith_test test_number fun_to_test arg correct_failure =
try
fun_to_test arg;
fprintf stderr ">>> Failure expected (%s, test %d)\n"
!function_tested test_number;
error_occurred := true;
false
with x ->
if x = correct_failure then begin
printf " %d..." test_number;
true
end else begin
fprintf stderr ">>> Bad failure (%s, test %d)\n"
!function_tested test_number;
error_occurred := true;
false
end
let eq = (==)
let eq_int = (==)
let eq_string = (=)
let sixtyfour = (1 lsl 31) <> 0
|