open Mp9common
let rubric_version = "1.3"
let rubric_title = "CS421 Fasll 2011 MP9"

(**************************************************************************
 * You can add new test cases by adding new elements to the following lists
 * Format is:
 * TEST<X>ARG(<weight>, <function_name>, <arg1>, <arg2>, ..., <argX>)
 *
 * <X> is the number of argument that the function being tested takes.
 **************************************************************************)

let parse s = Picomlparse.main Picomllex.token (Lexing.from_string s)

(* These lists are for regular problems *)

let eval_exp_tests = 
[
(* Problem 2 *)
TEST1ARG(1, eval_exp, (ConExp(Int 2), []));
(* Problem 4 *)
TEST1ARG(1, eval_exp, (VarExp "x", [("x", Intval 2)]));
(* Problem 5 *)
TEST1ARG(1, eval_exp, (BinExp (Add, ConExp(Int(3)), ConExp(Int(4))),  []));
(* Problem 6 *)
TEST1ARG(1, eval_exp, (LetExp("y", ConExp(Int 5), VarExp "y"), []));
(* Problem 7 *)
TEST1ARG(1, eval_exp, (FunExp("x", BinExp (Add, VarExp "x", VarExp "x")), []));
(* Problem 8 *)
TEST1ARG(1, eval_exp, (MonExp (Head,
                               BinExp(Cons, ConExp (Int 1), ConExp Nil)), []));
(* Problem 9 *)
TEST1ARG(1, eval_exp, (AppExp(FunExp("x", VarExp "x"),
                              ConExp(Int 5)), []));
(* Problem 10 *)
TEST1ARG(1, eval_exp, (IfExp(ConExp(Bool true), 
                            ConExp(Int 1), ConExp(Int 0)), []))
]

(* Declaration test cases should go in this list.
 * The first element of the pair is the weight of the case,
 * and the second is the string to be given to the parser.
 *)

let eval_dec_test_cases = [
(* Problem 1 *)

1, "(* Q1  and Q2*) 2;;"; 

(* Problem 3 *)
1, "(* Q3 *) let x = 2;;";

(* Problem 11 *)
1, "(* Q11 *) let rec f y = 1;;";

(*Problem 12*)
1, "(* Q12 *) let rec f x = x + 1 in f 3;;";

(*Problem 13*)
1, "(* Q13 *) let rec f x = if x = 0 then 1 else x * f (x - 1) in f 3 ;;"
]

let rubric = eval_exp_tests @ 
             (List.map 
             (fun (w,s) -> TEST2SARG(w, eval_dec, s, []))
             eval_dec_test_cases)


(* This list is for extra credit problems *)
let extra_test_cases = [
(* Problem 14 *)
1, "(* Q14 *) let f = fun x -> raise 4 in f 17.0 15;;";
(*Problem 15*)
1, "(* Q15 *) raise 1;;";
1, "(* Q16 *) 4/0;;";
1, "(* Q17 *) try 4 / 0 with 0 -> 9999;;"
]

let extra_rubric = List.map 
             (fun (w,s) -> TEST2SARG(w, eval_dec, s, []))
             extra_test_cases
