-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab1_test.sml
More file actions
76 lines (56 loc) · 1.72 KB
/
lab1_test.sml
File metadata and controls
76 lines (56 loc) · 1.72 KB
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
(* test test_name test_function
TYPE: string -> (unit -> bool) -> unit
PRE: true
POST: ()
SIDE-EFFECTS: any side-effects of test_function () other than
exceptions; prints whether the test test_name succeeded (i.e.,
test_function () = true), failed, or an exception was raised
*)
fun test test_name test_function =
(
if test_function () then
print (" + SUCCESSFUL TEST, name: " ^ test_name ^ "\n")
else
print (" - FAILED TEST, name: " ^ test_name ^ "\n")
)
handle _ =>
print (" - EXCEPTION RAISED IN TEST, name: " ^ test_name ^ "\n");
(* Do not modify the following line. Rename your file instead.
The file that you submit needs to have this name. *)
use "lab1.sml";
(* TYPE: unit -> unit
PRE: true
POST: ()
SIDE-EFFECTS: performs several tests and prints their results
*)
(fn () =>
(
(* Test B *)
test "B.1_1"
(fn () => plus 1 1 = 2);
test "B.1_2"
(fn () => plus 7 4 = 11);
(* Test C *)
test "C.1"
(fn () => ( fun1 0 = 42; true ));
test "C.2"
(fn () => ( fun2 0 0 = 42; true ));
test "C.3"
(fn () => ( fun3 0 = (42, 42); true ));
test "C.4"
(fn () => ( fun4 (0, 0) = 42; true ));
test "C.5"
(fn () => ( fun5 0 0.0 "foo" = "bar"; true ));
test "C.6"
(fn () => ( fun6 (0, ("foo", "bar", 0)) = (42, "baz"); true ));
(* Test D *)
test "D_1"
(fn () => lcm 1 = 1);
test "D_2"
(fn () => lcm 3 = 6);
test "D_3"
(fn () => lcm 5 = 60);
test "D_4"
(fn () => lcm 10 = 2520)
)
) ();