1995-11-06 02:34:19 -08:00
|
|
|
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
|
1999-09-02 10:58:43 -07:00
|
|
|
fprintf stderr "*** Bad result (%s, test %d)\n" !function_tested test_number;
|
|
|
|
flush stderr;
|
1995-11-06 02:34:19 -08:00
|
|
|
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;
|
1999-09-02 10:58:43 -07:00
|
|
|
fprintf stderr "*** Failure expected (%s, test %d)\n"
|
1995-11-06 02:34:19 -08:00
|
|
|
!function_tested test_number;
|
1999-09-02 10:58:43 -07:00
|
|
|
flush stderr;
|
1995-11-06 02:34:19 -08:00
|
|
|
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;
|
1999-09-02 10:58:43 -07:00
|
|
|
fprintf stderr "*** Failure expected (%s, test %d)\n"
|
1995-11-06 02:34:19 -08:00
|
|
|
!function_tested test_number;
|
1999-09-02 10:58:43 -07:00
|
|
|
flush stderr;
|
1995-11-06 02:34:19 -08:00
|
|
|
error_occurred := true;
|
|
|
|
false
|
|
|
|
with x ->
|
|
|
|
if x = correct_failure then begin
|
|
|
|
printf " %d..." test_number;
|
|
|
|
true
|
|
|
|
end else begin
|
1999-09-02 10:58:43 -07:00
|
|
|
fprintf stderr "*** Bad failure (%s, test %d)\n"
|
1995-11-06 02:34:19 -08:00
|
|
|
!function_tested test_number;
|
1999-09-02 10:58:43 -07:00
|
|
|
flush stderr;
|
1995-11-06 02:34:19 -08:00
|
|
|
error_occurred := true;
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
let eq = (==)
|
|
|
|
let eq_int = (==)
|
|
|
|
let eq_string = (=)
|
|
|
|
|
1995-11-06 05:15:28 -08:00
|
|
|
let sixtyfour = (1 lsl 31) <> 0
|