open Mp6common
let rubric_version = "1.0"
let rubric_title = "CS421 Fall 2015 MP6"

(**************************************************************************
 * 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, (ConstExp(IntConst 2), []));
(* Problem 4 *)
TEST1ARG(1, eval_exp, (VarExp "x", [("x", IntVal 2)]));
(* Problem 5 *)
TEST1ARG(1, eval_exp, (MonOpAppExp(IntNegOp, ConstExp (IntConst 2)), []));
(* Problem 6 *)
TEST1ARG(1, eval_exp, (BinOpAppExp (IntPlusOp, ConstExp(IntConst(3)), ConstExp(IntConst(4))),  []));
(* Problem 7 *)
TEST1ARG(1, eval_exp, (IfExp(ConstExp(TrueConst), 
                            ConstExp(IntConst 1), ConstExp(IntConst 0)), []));
(* Problem 8 *)
TEST1ARG(1, eval_exp, (LetInExp("y", ConstExp(IntConst 5), VarExp "y"), []));
(* Problem 9 *)
TEST1ARG(1, eval_exp, (FunExp ("x", VarExp "x"), []));
(* Problem 10 *)
TEST1ARG(1, eval_exp, (AppExp (FunExp ("x", VarExp "x"), ConstExp (IntConst 7)), []));
(* Problem 12 *)
TEST1ARG(1, eval_exp, (AppExp (VarExp "even", ConstExp (IntConst 3)),
[("even",
   RecVarVal ("even", "x",
    IfExp (BinOpAppExp (EqOp, VarExp "x", ConstExp (IntConst 0)),
     ConstExp (TrueConst),
     IfExp (BinOpAppExp (EqOp, VarExp "x", ConstExp (IntConst 1)),
      ConstExp (FalseConst),
      AppExp (VarExp "even",
       BinOpAppExp (IntMinusOp, VarExp "x", ConstExp (IntConst 2))))),
    []))]))
]

(* 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 even x = if x = 0 then true else if x = 1 then false else even (x - 2);;";

(*Problem 13*)
1, "(* Q13 *) 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) -> TEST1ARG(w, eval_dec, (parse s, [])))
             eval_dec_test_cases)

(* This list is for extra credit / graduate student problems *)
let grad_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 grad_rubric = List.map 
             (fun (w,s) -> TEST1ARG(w, eval_dec, (parse s, [])))
             grad_test_cases

let extra_rubric = []
