(************************************************************************** * 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 Ml2common (* This was carried over from MP2 (2015). *) let q5_stu f lst = List.fold_right (Student.split_step f) lst Student.split_base let q5_sol f lst = List.fold_right (Solution.split_step f) lst Solution.split_base (* This list is for regular problems *) let rubric = [ (*****************************) (***** PROBLEMS FROM MP2 *****) (*****************************) TEST2ARG_TWOFUN(1, q5_sol, q5_stu, (fun x -> x = 5), []) ; TEST2ARG_TWOFUN(1, q5_sol, q5_stu, (fun x -> x > 2), [0;2;3;5;1;4]) ; TEST2ARG_TWOFUN(1, q5_sol, q5_stu, (fun x -> x< 5), [0;9;-5;5;2;3;5;1;4]) ; TEST2ARG_TWOFUN(1, q5_sol, q5_stu, (fun x -> x< 5.0), [0.0;9.3;-5.4;5.6;2.1;3.3;5.7;1.2;4.5]) ; TEST2ARG_TWOFUN(1, q5_sol, q5_stu, (fun x -> (x-3)< 5), [0;99;-5;55;32;3;5;1;4]) ; TEST1ARG( 1, rle, [] ); TEST1ARG( 1, rle, [1;1;1;2;2;2;3;1;1;1] ); TEST1ARG( 1, rle, [1;1;3;21;21;2;2;2;-3;-3;-3;-3;3;1;1;1] ); TEST1ARG( 1, rle, [1.0;1.0;1.0;2.0;2.0;2.0;3.0;1.0;1.0;1.0] ); TEST1ARG( 1, rle, ["1.0";"1.0";"1.0";"2.0";"2.0";"2.0"] ); TEST2ARG( 1, concat, "34 + ", ["b"; "5";"99"; "hello"]); TEST2ARG( 1, concat, "", []); TEST2ARG( 1, concat, "", [""; "";""; ""]); TEST2ARG( 1, concat, "", ["d"; "f"; "g"; "h"]); TEST2ARG( 1, concat, " + ", ["a"; "3"; "z^2"]); TEST2ARG( 1, concat, "a", ["b"]); TEST2ARG( 1, concat, "a", ["b"; "c"]); TEST2ARG( 1, app_all, [(fun x -> x > 0); (fun y -> y mod 2 = 0); (fun x -> x * x = x)], []); TEST2ARG( 1, app_all, [], []); TEST2ARG( 1, app_all, [], [()]); TEST2ARG( 1, app_all, [(fun x -> x > 0); (fun y -> y mod 2 = 0); (fun x -> x * x = x)], [1; 3; 6]); TEST2ARG( 1, app_all, [(fun x -> x < 0); (fun y -> y + 2 = 0); (fun x -> x * x -5 = x)], [1; 3; 6;2;3;4;5;6;7;8;9;10]); TEST2ARG( 1, app_all, [(fun x -> x > 0.0); (fun y -> y -. 2.0 = 0.0); (fun x -> x *. x = x)], [1.0; 3.0; 6.0;5.5]); TEST2ARG( 1, app_all, [(fun x -> x = "0"); (fun y -> y ^ "2" = "2"); (fun x -> x = x)], ["1"; "3"; "6"; ""]); TEST2ARG( 1, app_all, [(fun x -> x*5-9 > 0); (fun y -> (y+3) mod 2 = 0); (fun x -> x *x * x = x)], [1;-1; 3;2;5; 6;89;0]); (*****************************) (***** PROBLEMS FROM ML2 *****) (*****************************) (***********************) (** Transform PrimOps **) (***********************) (* This problem will not be given on the ML. *) TEST3ARG( 0, consk, 1, [], print_int_list); TEST3ARG( 0, concatk, "hello", "world", print_string); TEST2ARG( 0, string_of_intk, 1, print_string); TEST2ARG( 0, ceilk, 3.14, report_float); (* But these will be! *) TEST4ARG( 1, add_mul_modk, 3, 3, 3, (fun x -> (x, report_int x))); TEST4ARG( 1, add_mul_modk, 1, 2, 4, (fun x -> x)); TEST4ARG( 1, add_mul_modk, -5, 45, 99, (fun x -> if x > 9 then "hi" else "bye")); TEST4ARG( 1, add_mul_modk, 5, 6, 7, (fun x -> if x = 0 then 3.0 else -55.7)); TEST4ARG( 1, add_mul_modk, 5, 6, 7, (fun x -> (x + 2 , report_int x))); TEST5ARG( 1, parabolak, 1, 0, 0, 0, (fun x -> x)); TEST5ARG( 1, parabolak, 1, 3, 7, 2, (fun x -> (x, report_int x))); TEST5ARG( 1, parabolak, 3, 2, 1, 0, (fun x -> x-67)); TEST5ARG( 1, parabolak, 1, 1, 1, 1, (fun x -> x+x -1) ); TEST5ARG( 1, parabolak, 1, 1, 1, 1, float_of_int ); TEST3ARG( 1, keep_the_changek, 3.00, 0.50, report_float); TEST3ARG( 1, keep_the_changek, 0.00, 0.450, (fun x->(x,()))); TEST3ARG( 1, keep_the_changek, 323.00, 0.450, (fun x->x)); TEST3ARG( 1, keep_the_changek, 3333.00, -9.50, (fun x-> x<0.0)); TEST3ARG( 1, keep_the_changek, 563.00, 890.896, report_float); TEST4ARG( 1, usernamek, 47, "xx", "HelloKitty", print_string); TEST4ARG( 1, usernamek, -56, "xx99", "buhHelloKitty", (fun x -> x^"5")); TEST4ARG( 1, usernamek, 3457, "hahaxx", "HelloKittyblub", (fun x -> x)); TEST4ARG( 1, usernamek, 0, "xxhuhuhu", "HellohelloKitty", print_string); TEST4ARG( 1, usernamek, 1, "x", "y", print_string); (***********************) (*** CPS & Recursion ***) (***********************) TEST1ARG( 1, even_odd, [-1;0;1]); TEST1ARG( 1, even_odd, [0;4;2]); TEST2ARG( 1, even_oddk, [4;4;7;8;9;34;56;78;-1;0;1], print_pair_int_list); TEST2ARG( 1, even_oddk, [-89;4324;-1;0;1], print_pair_int_list); TEST2ARG( 1, even_oddk, [-1;0;234;453;781], print_pair_int_list); TEST2ARG( 1, even_oddk, [-341;99;0;12341],(fun x-> x)); TEST2ARG( 1, even_oddk, [-1;0;1], print_pair_int_list); TEST2ARG( 1, even_oddk, [-1;0;1], print_pair_int_list); TEST1ARG( 1, enlike, ["xxx"]); TEST1ARG( 1, enlike, ["xxx"; "yyy"]); TEST2ARG( 1, enlikek, ["xxx"], print_string_list); TEST2ARG( 1, enlikek, ["totally"; "that’s so fetch"], print_string_list); TEST2ARG( 1, enlikek, ["oh"; "wow"], print_string_list); TEST2ARG( 1, enlikek, ["no?";"what"; "really?"], (fun x-> x)); TEST2ARG( 1, enlikek, ["345";"435";"!!!"; ""], print_string_list); TEST2ARG( 1, enlikek, [], print_string_list); TEST1ARG( 1, low_five, []); TEST1ARG( 1, low_five, [10;8;7;5;6;13;4;2;9;1;(13)]); TEST2ARG( 1, low_fivek, [], print_int_list); TEST2ARG( 1, low_fivek, [1;3;5;7;9], print_int_list); TEST2ARG( 1, low_fivek, [5;5;5;5;25;5;25], print_int_list); TEST2ARG( 1, low_fivek, [91;43;5;0;1;2;3;2;1;-55], (fun x-> x=x)); TEST2ARG( 1, low_fivek, [51;-99;-5;-5;-3;5;7;9], (fun x-> x)); TEST2ARG( 1, low_fivek, [1;3;5;7;9], print_int_list); TEST2ARG( 1, map, (fun x -> x + 1), [0;1;2]); TEST2ARG( 1, map, print_string, ["s";"t";"u"]); TEST3ARG( 1, mapk, (addk 1), [0;1;2], (fun x -> (x,List.length x))); TEST3ARG( 1, mapk, deck, [-456;145;22], print_int_list); TEST3ARG( 1, mapk, inck, [0;5;6;7;8;9;0;1246;1;2], (fun x-> x)); TEST3ARG( 1, mapk, deck, [4560;1546;2342], print_int_list); TEST3ARG( 1, mapk, (fun x k -> k(x ^ "s")), ["u";"v"], (fun x -> x)); TEST3ARG( 1, mapk, inck, [], (fun x -> x)) ] (* Note: the last entry should not be followed by a semicolon. *) let extra_rubric = [ (*****************************) (***** PROBLEMS FROM MP2 *****) (*****************************) TEST2ARG( 1, sub_list, [1;1;2;1;1;4;1], [1;2;1;1;1] ); TEST2ARG( 1, sub_list, [], [1;2;1;1;1] ); TEST2ARG( 1, sub_list, [1;1;2;1;1;1], [1;2;1;91;1] ); TEST2ARG( 1, sub_list, [1.0;1.0;2.0;1.0;1.0;4.0;1.0], [1.0;2.0;1.0;1.0;1.0] ); TEST7ARG( 1, distributek, inck, inck, addk, 1, 2, 3, report_int); TEST7ARG( 1, distributek, (fun x k -> k 4), (fun y k -> k(List.length y)), (fun w s k -> k(s^string_of_int w)), (), [1.7], "hi", (fun s -> (s, print_string s))); TEST7ARG( 1, distributek, deck, deck, subk, 5, 0, 9, (fun x -> x-67)); TEST7ARG( 1, distributek, inck, deck, addk, -111, 22, 563, (fun x -> (x,x*98))); TEST3ARG( 1, map_split_pair, (fun x -> (x = "h")), (fun s -> (s,s)), ["h";"j";"h"]); TEST4ARG( 1, map_split_pairk, (fun x -> geqk x 5), inck, [2;4;6;8], print_pair_int_list); TEST4ARG( 1, map_split_pairk, (fun x -> eqk x "h"), (fun s k -> k (s,s)),["h"], (fun (l1,l2) -> l1 @ l2)); TEST4ARG( 1, map_split_pairk, (fun x -> geqk 7 x ), deck, [99;-103;2;4;6;8], print_pair_int_list); TEST4ARG( 1, map_split_pairk, (fun x -> geqk x 5), deck, [2;4;6;8], print_pair_int_list); TEST3ARG( 1, transform_if, (fun x -> x >= 2), (fun x -> x * 2), [1;2;3]); TEST4ARG( 1, transform_ifk, (fun x -> geqk x 2), (fun x -> mulk x 2), [2;4;6;8], print_int_list); TEST4ARG( 1, transform_ifk, (fun x -> eqk x "s"), (fun x k -> k (x ^ "s")), ["t";"s";"ts";"s"], (fun x -> (x,x))); TEST4ARG( 1, transform_ifk, (fun x -> geqk x (-12)), (fun x -> mulk x 3), [2;4;6;8], print_int_list); TEST4ARG( 1, transform_ifk, (fun x -> geqk 2 45), (fun x -> addk x (-99)), [452;234;-99;2;4;6;8], print_int_list) ]