open Mp9common let rubric_version = "1.1" let rubric_title = "CS421 Fall 2014 MP9" (************************************************************************** * You can add new test cases by adding new elements to the following lists * Format is: * TESTARG(, , , , ..., ) * * is the number of argument that the function being tested takes. **************************************************************************) let parse s = Solution.main Picomllex2.token (Lexing.from_string s) let parse_stu s = Student.main Picomllex.token (Lexing.from_string s) (* 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 = [ (*Problem 1*) 1, "(* Q1 *) let x = true;;"; 1, " let x = 62395;;"; 1, " let x = ();;"; 1, " let x = \"hi there\";;"; 1, " let x = 3.45;;"; (*Problem 2*) 1, "(* Q2 *) let x = (3);;"; 1, " let x = (true);;"; 1, " let x = (\"hello\");;"; 1, " let x = (());;"; 1, " let x = (1.123);;"; (*Problem 3*) 1, "(* Q3 *) (3, 4);;"; 1, " (\"hi\", (3, 4));;"; 1, " (1.82, (2, 9));;"; 1, " ((), (2, 9));;"; 1, " ((2, 9), true);;"; (*Problem 4*) 1, "(* Q4 *) hd [];;"; 1, " tl [];;"; 1, " print_int 1;;"; 1, " ~ 1;;"; 1, " fst (1, 2);;"; 1, " snd (1, 2);;"; 1, " print_int (snd (1, 2));;"; 1, " print_int (~(snd (1, 2)));;"; (*Problem 5*) 1, "(* Q5 *) 3 + 9;;"; 1, " 3 - 2 - 1 + 4 + 5 + 6;;"; 2, " 3. *. 2.0 -. 1.6 *. 4. /. 2.0 +. 4.13 ;;"; 2, " let x = 3 * 2 - 4 * 5 + 3 * 10 + 32;;"; 2, " let x = \"hi\" ^ \"gh\" ^ \"er\";;"; 2, " let x = 3. ** 4. ** 5. ** 6. +. (3. -. 2.) *. 9.;;"; 2, " let x = ( 3 + (1 - 7) , 3. *. (2.0 -. 1.6));;"; (*Problem 6*) 2, "(* Q6 *) let x = 3 < 4;;"; 2, " let x = 3 < 2 = 4;;"; 2, " let x = 3 = 2 = 1 = 6 < 7 < 8;;"; 2, " let x = 3+2 < 3+5;;"; 2, " let x = 3. +. 2. < 3. +. 5.;;"; 2, " let x = (3 + 8) = (11 - 2);;"; (*Problem 7*) 2, "(* Q7 *) let x = 1 :: [];;"; 2, " let rec f x = 3 :: 5 :: 2 :: 1 :: x;;"; 2, " let x = []::(1::2::[])::(3::[])::[];;"; 2, " let x = \"hi\"::\"hola\"::\"privyet\"::\"konichiwa\"::\"namaste\"::\"salut\"::\"chao\"::[];;"; 2, " let x = (3,(2))::(1,2)::(1+2,3*(1+2))::[];;"; (*Problem 8*) 1, "(* Q8 *) let x = let x = 3 in true;;"; 1, " let rec f x = 3::x in 5;;"; 1, " let x = let x = let rec g y = true in 9 in 2;;"; 1, " let x = let rec h x = 13 in let y = 4 in 7;;"; 1, " let y = 9 + let x = 3 in x;;"; 1, " let y = let x = 3 in x * 9;;"; 1, " let y = 2::let x = 3 in x::[];;"; 1, " let y = 3 x + x;;"; 3, " fun x -> if x then 3 else 4;;"; 3, " 3::if true then 2::[] else 4::[];;"; 3, " 12 = if true then 2 else 4;;"; 4, " if true then fun x -> if x then 1 else 3 else fun x -> 4;;"; 3, " 2 * if true then 2+9 else 4;;"; 2, " let iszero = fun n -> if n = 0 then true else false in iszero 9;;"; (*Problem 10*) 2, "(* Q10 *)(fun x -> x + x + 3) 4;;"; 2, " (fun x -> x) fun x -> if x then 3 else 4;;"; 2, " (fun x -> x) if true then 3 else 4;;"; 2, " let f = (fun x -> x) in f 3 + if true then 3 else 4;;"; 2, " let rec f y = (fun x -> if x = 0 then 1 else x * f (x - 1)) in f 3;;"; (*Problem 11*) 1, "(* Q11 *)let x = true && false || true;;"; 2, " let x = 3 < 4 && false && true || false && true || false || true;;"; 2, " true || if true then false else true;;"; 2, " let f = fun x -> x in f true || false;;"; 2, " true && let f = fun x -> x in f false;;"; 2, " 3 = 4 && 3. ** 2. < 2. *. 1.;;"; (*Problem 12*) 1, "(* Q12 *)raise 3;;"; 1, " raise (fun x -> x) 4 + 3;;"; 1, " let f = fun x -> x in raise f 4 + 2;;"; 2, " let f = fun x -> x in 3 + f raise 4 + 2;;" (* 111 points *) ] (* This list is for extra credit problems *) let extra_test_cases = [ (*Problem 13*) 2, "(* Q13 *)[2; 4; 8];;"; 2, " [\"Thank you\";\"Arigatou\";\"Spasibo\";\"Xie Xie\";\"Gracias\";\"Multumesc\"];;"; 1, " [fun x -> x ; fun x -> 2 * x ; fun x -> if true then x else 3*x];;"; (*Problem 14*) 2, "(* Q14 *)try \"hi\" with 1 -> \"one\" | 2 -> \"two\";;"; 2, " let e = try true with 4 -> false | _ -> true;;"; 2, " try \"hi\" with 1 -> \"one\" | 2 -> try \"hello\" with 3 -> \"three\" | 4 -> \"four\";;"; 2, " try true with 4 -> false | _ -> true | 5 -> if true then false else true;;"; 2, " try 1 with 4 -> 3 * 2 | 1 -> raise 2;;" (* 15 points *) ] let rubric = List.map (fun (w,s) -> TEST1ARG_TWOFUN(w, parse, parse_stu, s)) test_cases let extra_rubric = List.map (fun (w,s) -> TEST1ARG_TWOFUN(w, parse, parse_stu, s)) extra_test_cases