open Mp7common
let rubric_version = "1.0"
let rubric_title = "CS421 Spring 2008 MP7"

(**************************************************************************
 * 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.
 **************************************************************************)


(* 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.
 *)

(* This list is for regular problems *)
let test_cases = [

1, "class A {public int main(int i){ return i;}}";
1, "class A {public int main(int i){ return ((i+2)*6-2)/5;}}";
1, "class A {public int main(int i){ return 5 < 3;}}";
1, "class A {public int main(int i){ return !true;}}";
1, "class A {public int main(int i){ return dummy.m(3);} public int m(int a){return a;}}" ;
1, "class A {public int main(int i){ i=1; System.out.println(i); i=2; System.out.println(i); i=3; System.out.println(i); return i;}}
";

1, "class A {public int main(int i){ {i=1; i=2;} return i;}}";
1, "class A {public int main(int i){ {i=1; i=2;} return i;}}";
1, "class A {public int main(int i){ if(true) if(false) i=5; else i=2; else i=3; return i;}}";
1, "class A {public int main(int i){ i=0; while(i<5){System.out.println(i); i=i+1;} return i;}}";
1, "class A {public int main(int i){ i=0; while(true){System.out.println(i); if(i<5) i=i+1; else break;} return i;}}";
1, "class A {public int main(int i){ i=0; while(i<5){i=i+1; continue; System.out.println(i);} return i;}}";
1, "class A {public int main(int i){ return dummy.fact(5);} public int fact(int a){ if((a<2)) a=1; else a=a*dummy.fact(a-1); return
 a;}}";
]

let extra_test_cases = [
1, "class A {public int main(int i){ return false & x;}}";
1, "class A {public int main(int i){ return true  | x;}}";
]


let parse s = Minijavaparse.program Minijavalex.tokenize (Lexing.from_string s)
let eval_sol s = try Some(Mp7common.execProg (Solution.compile (parse s))) with _ -> None
let eval_stu s = try Some(Mp7common.execProg (Student.compile (parse s)) ) with _ -> None


let mptest weight pair = compare isEq 4 weight pair;;
output := "";;

let rubric = List.map 
             (fun (w,s) -> turnOffShortCircuit(); TEST1ARG_TWOFUN(w, eval_sol, eval_stu, s))
             test_cases;;

let extra_rubric = List.map
             (fun (w,s) -> turnOnShortCircuit(); TEST1ARG_TWOFUN(w, eval_sol, eval_stu, s))
             extra_test_cases
;;


