(***************** Question 3 and 4 *************************************************) (* 5 points for each test case *) (** --Test-Begin-- **) let val tree1 = Leaf(5) val result1 = map_n_tree((fn x => Leaf(x)), tree1) val expected1 = Leaf (Leaf 5) in if result1 = expected1 then "TEST SUCCEEDED" else "TEST 1 FAILED" end; (** --Test-End-- **) (** --Test-Begin-- **) let val tree2 = N_branch([Leaf 12, N_branch([Leaf 15, Leaf 13, Leaf 18])]) val result2 = map_n_tree((fn(x)=>x*10), tree2) val expected2 = N_branch [Leaf 120, N_branch [Leaf 150, Leaf 130, Leaf 180]] in if result2 = expected2 then "TEST SUCCEEDED" else "TEST 2 FAILED" end; (** --Test-End-- **) (*2*) (** --Test-Begin-- **) let val tree2 = L_N_branch(11, [L_Leaf 12, L_N_branch(13, [L_Leaf 15, L_Leaf 13, L_Leaf 18])]) val result2 = map_labeled_n_tree((fn x => "visited"), tree2) val expected2 = L_N_branch("visited", [L_Leaf "visited", L_N_branch ("visited", [L_Leaf "visited", L_Leaf "visited", L_Leaf "visited"])]) in if result2 = expected2 then "TEST SUCCEEDED" else "TEST 3 FAILED" end; (** --Test-End-- **) (** --Test-Begin-- **) let val tree3 = L_N_branch([1, 2], [L_Leaf [3, 4], L_N_branch([4, 5], [L_Leaf [6, 7], L_Leaf [8], L_Leaf [9, 10, 11]])]) val result3 = map_labeled_n_tree((fn(ls) => (map(fn(x)=> (x * x)+1) ls)), tree3) val expected3 = L_N_branch([2, 5], [L_Leaf [10, 17],L_N_branch ([17, 26], [L_Leaf [37, 50],L_Leaf [65],L_Leaf [82, 101, 122]])]) in if result3 = expected3 then "TEST SUCCEEDED" else "TEST 4 FAILED" end; (** --Test-End-- **) (*3*) (** --Test-Begin-- **) let val tree2 = L_N_branch([1, 2], [L_Leaf[4, 5], L_N_branch([3, 4], [L_Leaf [6, 7], L_Leaf [8], L_Leaf [9, 10, 11]])]) val result2 = preorder_labeled_n_tree(tree2) val expected2 = [[1, 2], [4, 5], [3, 4], [6, 7], [8],[9, 10, 11]] in if result2 = expected2 then "TEST SUCCEEDED" else "TEST 5 FAILED" end; (** --Test-End-- **) (** --Test-Begin-- **) let val tree3 = L_N_branch("Your" ,[L_N_branch("answer", [L_Leaf "is", L_Leaf "right", L_Leaf "Congratulations", L_Leaf "!!"])]) val result3 = preorder_labeled_n_tree(tree3) val expected3 = ["Your", "answer", "is", "right", "Congratulations", "!!"] in if result3 = expected3 then "TEST SUCCEEDED" else "TEST 6 FAILED" end; (** --Test-End-- **) (*4*) (** --Test-Begin-- **) let val tree1 = L_N_branch(1, [L_Leaf 2, L_N_branch(3, [L_Leaf 5, L_Leaf 3, L_Leaf 8])]) val result1 = replace_labeled_n_tree(3, 30, tree1) val expected1 = L_N_branch (1, [L_Leaf 2, L_N_branch (30, [L_Leaf 5, L_Leaf 30, L_Leaf 8])]) in if result1 = expected1 then "TEST SUCCEEDED" else "TEST 7 FAILED" end; (** --Test-End-- **) (** --Test-Begin-- **) let val tree3 = L_Leaf "a" val result3 = replace_labeled_n_tree("c", "b", tree3) val expected3 = L_Leaf "a" in if result3 = expected3 then "TEST SUCCEEDED" else "TEST 8 FAILED" end; (** --Test-End-- **) (***************** Question 4 *************************************************) (*1*) (** --Test-Begin-- **) let val testcase2 = evens_from(1) val result2 = take(encrypt_seq (1234, testcase2), 8) val expected2 = [5, 6, 7, 8, 13, 14, 15, 16] in if result2 = expected2 then "TEST SUCCEEDED" else "TEST 9 FAILED" end; (** --Test-End-- **) (** --Test-Begin-- **) let val testcase3 = Nil val result3 = encrypt_seq(1234, testcase3) val checkNil = fn Nil => "TEST SUCCEEDED" | _ => "TEST 10 FAILED" in checkNil(result3) end; (** --Test-End-- **) (*2*) (** --Test-Begin-- **) let val testcase1 = take (neg_key_seq(1234), 8) val expected1 = [~4, ~3, ~2, ~1, ~4, ~3, ~2, ~1] in if testcase1 = expected1 then "TEST SUCCEEDED" else "TEST 11 FAILED" end; (** --Test-End-- **) (** --Test-Begin-- **) let val testcase2 = take (neg_key_seq(1), 8) val expected2 = [~1, ~1, ~1, ~1, ~1, ~1, ~1, ~1] in if testcase2 = expected2 then "TEST SUCCEEDED" else "TEST 12 FAILED" end; (** --Test-End-- **) (*3*) (** --Test-Begin-- **) let val testcase1 = encrypt_seq (1234, evens_from(4)) val result1 = take(decrypt_seq(4, testcase1), 8) val expected1 = [4, 5, 6, 7, 12, 13, 14, 15] in if result1 = expected1 then "TEST SUCCEEDED" else "TEST 13 FAILED" end; (** --Test-End-- **) (** --Test-Begin-- **) let val testcase2 = encrypt_seq (1234, evens_from(4)) val result2 = take(decrypt_seq(1234, testcase2), 8) val expected2 = [4, 6, 8, 10, 12, 14, 16, 18] in if result2 = expected2 then "TEST SUCCEEDED" else "TEST 14 FAILED" end; (** --Test-End-- **)