(************************************************************************** * 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. **************************************************************************) open Mp4common let report x = string_of_int x;; let int_to_float x = float_of_int x;; let float_to_int x = int_of_float x;; let sqrk x k = k(x*x);; let idx = fun x->x;; let intk_test_stu x y = Student.timesk x y (Student.addk 1) (Student.subk 2);; let intk_test_sol x y = Solution.timesk x y (Solution.addk 1) (Solution.subk 2);; let floatk_test_stu x y = Student.multk x y (Student.take_awayk ~-.4.0) (Student.plusk 5.5);; let floatk_test_sol x y = Solution.multk x y (Solution.take_awayk ~-.4.0) (Solution.plusk 5.5);; let consk_test_stu x y = Student.consk x y (fun l -> Student.consk l []) let consk_test_sol x y = Solution.consk x y (fun l -> Solution.consk l []) let less_test_stu x y = Student.lessk x y (Student.lessk false) let less_test_sol x y = Solution.lessk x y (Solution.lessk false) let eq_test_stu x y = Student.eqk x y (Student.eqk false) let eq_test_sol x y = Solution.eqk x y (Solution.eqk false) (* This list is for regular problems *) let rubric = [ TEST3ARG(1, subk, 10, 5, report); TEST3ARG(1, catk, "hi ", "there", (fun x -> x)); TEST3ARG(1, plusk, 3.0, 4.0, (fun x -> Solution.multk x x (fun y -> ("Result: " ^ string_of_float y ^ "\n")))); TEST3ARG(1, lessk, 2, 7, (fun b -> (report (if b then 3 else 4)))); TEST3ARG_TWOFUN(1, intk_test_stu, intk_test_sol, 3, 5, report); TEST3ARG_TWOFUN(1, floatk_test_stu, floatk_test_sol, 2.0, ~-.3.0, (fun x -> (x,x))); TEST3ARG(1, catk, "hi ", "there", (fun x -> x = "hithere")); TEST3ARG_TWOFUN(1, consk_test_stu, consk_test_sol, 4.9, [], (fun x -> string_of_float(List.hd (List.hd x)))); TEST3ARG_TWOFUN(1, less_test_stu, less_test_sol, "a", "b", idx); TEST3ARG_TWOFUN(1, eq_test_stu, eq_test_sol, (1,"a"), (3,"4"), (fun b -> if b then 22.5 else 31.9)); TEST3ARG(0, addk, 1, 2, (fun x -> ())); TEST3ARG(0, subk, 1, 2, (fun x -> ())); TEST3ARG(0, timesk, 1, 2, (fun x -> ())); TEST3ARG(0, plusk, 1.0, 2.0, (fun x -> ())); TEST3ARG(0, take_awayk, 1.0, 2.0, (fun x -> ())); TEST3ARG(0, multk, 1.0, 2.0, (fun x -> ())); TEST3ARG(0, catk, "a", "b", (fun x -> ())); TEST3ARG(0, consk, 1, [], (fun x -> ())); TEST3ARG(0, lessk, 1, 2, (fun x -> ())); TEST3ARG(0, eqk, 1, 2, (fun x -> ())); TEST3ARG(0, addk, 1, 2, (fun x -> x)); TEST3ARG(0, subk, 1, 2, (fun x -> x)); TEST3ARG(0, timesk, 1, 2, (fun x -> x)); TEST3ARG(0, plusk, 1.0, 2.0, (fun x -> x)); TEST3ARG(0, take_awayk, 1.0, 2.0, (fun x -> x)); TEST3ARG(0, multk, 1.0, 2.0, (fun x -> x)); TEST3ARG(0, catk, "a", "b", (fun x -> x)); TEST3ARG(0, consk, 1, [], (fun x -> x)); TEST3ARG(0, lessk, 1, 2, (fun x -> x)); TEST3ARG(0, eqk, 1, 2, (fun x -> x)); TEST5ARG(1, abcdk, 2.0, 3.0, 4.0, 5.0, (fun y -> report (int_of_float y))); TEST5ARG(1, abcdk, 0.0, 7.0, 4.0, ~-.80.0, int_of_float); TEST5ARG(1, abcdk, 2.0, 9.0, 4.0, 5.0, idx); TEST5ARG(1, abcdk, ~-.1.0, 8.0, 4.0, 2.0, (fun x -> x = 29.0)); TEST5ARG(1, abcdk, ~-.2.15, ~-.3.0, 0.0, ~-.80.0, string_of_float); TEST5ARG(0, abcdk, 1.0, 2.0, 3.0, 4.0, (fun x -> ())); TEST5ARG(0, abcdk, 1.0, 2.0, 3.0, 4.0, (fun x -> x)); TEST2ARG(1, fact_range, 5, 1); TEST2ARG(1, fact_range, 0, 5); TEST3ARG(1, fact_rangek, 7, 5, report); TEST3ARG(1, fact_rangek, 0, 5, (fun x -> x = 1)); TEST3ARG(1, fact_rangek, 1, 0, (fun x -> (x,x))); TEST3ARG(0, fact_rangek, 0, 0, (fun x -> ())); TEST3ARG(0, fact_rangek, 0, 0, (fun x -> x)); TEST1ARG(1, duplicate_evens, [1; 2; 3; 4]); TEST1ARG(1, duplicate_evens, ["a"]); TEST2ARG(1, duplicate_evensk, [1; 2; 3; 4], Solution.duplicate_evens); TEST2ARG(1, duplicate_evensk, [], (fun x -> ("a",5.5 :: x))); TEST2ARG(1, duplicate_evensk, [[];[0];[1];[2];[3]], (fun l -> Solution.consk l [[]] idx)); TEST2ARG(1, duplicate_evensk, ["a"], (fun x -> (x,x))); TEST2ARG(0, duplicate_evensk, ["a"], (fun x -> ())); TEST2ARG(0, duplicate_evensk, [4.3], (fun x -> x)); TEST3ARG(1, first_or_default, (fun i -> 0 < i), [1; -2; 3; -4; 5], 0); TEST3ARG(1, first_or_default, (fun s -> s = []), [["a"]; ["b"]; ["c"]; ["d"]], ["0"]); TEST3ARG(0, first_or_default, (fun i -> true), [()], ()); TEST4ARG(1, first_or_defaultk, (Solution.lessk 0), [1; -2; 3; -4; 5], 0, report); TEST4ARG(1, first_or_defaultk, (Solution.lessk 0), [-1; -2; 3; -4; 5], 0, report); TEST4ARG(1, first_or_defaultk, (fun i -> fun f -> f true), [], "a", ((^)"b")); TEST4ARG(1, first_or_defaultk, (fun i -> fun f -> f false), [], "a", ((^)"b")); TEST4ARG(1, first_or_defaultk, (fun x -> Solution.eqk [1;2;3] (1::x)), [[1;1]; [2;3]; [3;2]; [-4]; [5]], [1], (List.map string_of_int)); TEST4ARG(1, first_or_defaultk, (Solution.eqk 0), [1; -2; 3; -4; 5], 10, report); TEST4ARG(0, first_or_defaultk, (fun i -> fun f -> true), [()], (), (fun x -> false)); TEST4ARG(0, first_or_defaultk, (fun i -> fun f -> 0), [0], 0, (fun x -> x)); TEST2ARG(1, app_all, [((+) 1); (fun x -> x * x); (fun x -> 13)], 5); TEST2ARG(1, app_all, [(fun x -> x = "hi"); (fun y -> y < "bye")], "a"); TEST3ARG(1, app_allk, [(Solution.addk 1); (fun x -> Solution.timesk x x); (fun x -> (fun k -> k 13))], 5, (fun x -> x) ); TEST3ARG(1, app_allk, [], "a", (fun x -> x)); TEST3ARG(4, app_allk, [(Solution.plusk 1.0); (fun x -> Solution.take_awayk x 1.0); (Solution.multk 2.0)], 10.0, (List.map string_of_float)); TEST3ARG(0, app_allk, [(fun y -> fun k -> k "a")], 1, (fun x -> ())); TEST3ARG(0, app_allk, [(fun y -> fun k -> k true)], "b", (fun x -> x)); TEST3ARG(1, sum_wholesk, [0; 1; 2; 3], report, (fun i -> "Error: " ^ (string_of_int i) ^ " is not a whole number\n")); TEST3ARG(1, sum_wholesk, [0; -1; 2; 3], report, (fun i -> "Error: " ^ (string_of_int i) ^ " is not a whole number\n")); TEST3ARG(1, sum_wholesk, [], report, (fun i -> ("Error: " ^ (string_of_int i) ^ " is not a whole number\n"))); TEST3ARG(1, sum_wholesk, [], idx, (fun i -> 13)); TEST3ARG(1, sum_wholesk, [2], report, (fun i -> ("Error: " ^ (string_of_int i) ^ " is not a whole number\n"))); TEST3ARG(1, sum_wholesk, [-1], report, (fun i -> ("Error: " ^ (string_of_int i) ^ " is not a whole number\n"))); TEST3ARG(1, sum_wholesk, [0], idx, (fun i -> 13)); TEST3ARG(1, sum_wholesk, [3], idx, (fun i -> 13)) ] (* Note: the last entry should not be followed by a semicolon. *) (* This list is for extra credit problems *) let extra_rubric = [ TEST4ARG(1, average_averagek,[[1.; 2.; 3.]; [4.; 5.]; [6.; 7.; 8.]; [9.]], (fun a -> "Result: " ^ (string_of_float a) ^ "\n"), (fun () -> "Empty list!\n"), (fun n -> ("Empty list at position " ^ string_of_int n ^ "\n"))); TEST4ARG(1,average_averagek, [[1.; 2.; 3.]; [4.; 5.]; []; [9.]], (fun a -> "Result: " ^ (string_of_float a) ^ "\n"), (fun () -> "Empty list!\n"), (fun n -> ("Empty list at position " ^ string_of_int n ^ "\n"))); TEST4ARG(1,average_averagek, [], (fun a -> "Result: " ^ (string_of_float a) ^ "\n"), (fun () -> "Empty list!\n"), (fun n -> ("Empty list at position " ^ string_of_int n ^ "\n"))); TEST4ARG(1, average_averagek, [[1.]], (fun a -> "Result: " ^ (string_of_float a) ^ "\n"), (fun () -> "Empty list!\n"), (fun n -> ("Empty list at position " ^ string_of_int n ^ "\n"))); TEST4ARG(1, average_averagek, [[1.; 2.; 3.]; [4.; 5.]; [6.; 7.; 8.]; [9.]], (fun a -> (a, a > 5.5)), (fun () -> (0.0, false)), (fun n -> (~-.1.0 *. (float_of_int n)), n > 0)); TEST4ARG(1, average_averagek, [[1.; 2.; 3.]; [4.; 5.]; []; [9.]], (fun a -> (a, a > 5.5)), (fun () -> (0.0, false)), (fun n -> (~-.1.0 *. (float_of_int n)), n > 0)); TEST4ARG(1, average_averagek, [], (fun a -> (a, a > 5.5)), (fun () -> (0.0, false)), (fun n -> (~-.1.0 *. (float_of_int n)), n > 0)); TEST4ARG(0, average_averagek, [[1.]], (fun a -> (a, a > 5.5)), (fun () -> (0.0, false)), (fun n -> (~-.1.0 *. (float_of_int n)), n > 0)); TEST4ARG(0, average_averagek, [[1.]], (fun a -> true), (fun () -> true), (fun n -> true)) ]