38 lines
1.7 KiB
Standard ML
38 lines
1.7 KiB
Standard ML
open Util.Assert
|
|
open Hellocaml
|
|
|
|
(* These tests are provided by you -- they will be graded manually *)
|
|
|
|
(* You should also add additional test cases here to help you *)
|
|
(* debug your program. *)
|
|
|
|
let e1 = Mult(Add(Const 1L, Const 2L), Add(Const 3L, Const 4L))
|
|
let e2 = Add(Mult(Const 1L, Const 2L), Mult(Const 3L, Const 4L))
|
|
let ctx3 = [("x", 10L); ("y", 20L)]
|
|
let e3 = Add(Mult(Const 1L, Var "x"), Mult(Var "y", Const 4L))
|
|
|
|
let student_tests : suite = [
|
|
Test ("Student-Provided Tests For Problem 1-3", [
|
|
("case1", assert_eqf (fun () -> prob3_ans) 42);
|
|
("case2", assert_eqf (fun () -> (prob3_case2 17)) 25);
|
|
("case3", assert_eqf (fun () -> prob3_case3) 64);
|
|
]);
|
|
|
|
Test ("Student-Provided Tests for Problem 4-1", [
|
|
("vars_of1", assert_eqf (fun () -> vars_of (Mult(Mult( Var "z", Var "w" ), Mult (Var "y", Mult (Var "x", Const 1L))))) ["w"; "x"; "y"; "z"]);
|
|
]);
|
|
|
|
Test ("Student-Provided Tests for Problem 4-4", [
|
|
("optimize1", assert_eqf (fun () -> optimize (Neg(Neg(Const 0L)))) (Const 0L));
|
|
("optimize2", assert_eqf (fun () -> optimize (Neg(Neg(Neg(Const 0L))))) (Const 0L));
|
|
("optimize3", assert_eqf (fun () -> optimize (Neg(Neg(Neg(Const 1L))))) (Const (-1L)));
|
|
("optimize4", assert_eqf (fun () -> optimize (Mult(Add(Const 5L, Const 5L), Neg(Neg(Const 1L))))) (Const (10L)));
|
|
]);
|
|
|
|
Test ("Student-Provided Tests for Problem 5", [
|
|
("compile1", assert_eqf (fun () -> interpret [] e1) (answer (execute [] [] (compile e1))));
|
|
("compile2", assert_eqf (fun () -> interpret [] e2) (answer (execute [] [] (compile e2))));
|
|
("compile3", assert_eqf (fun () -> interpret ctx3 e3) (answer (execute ctx3 [] (compile e3))));
|
|
]);
|
|
|
|
]
|