(* ** Course: Concepts of Programming Languages (BU CAS CS 320) ** Semester: Summer I, 2009 ** Instructor: Hongwei Xi (hwxi AT cs DOT bu DOT edu) *) // // Assignment Two (Due: Monday, June 1, 2009) // (* ****** ****** *) staload "assignment2.sats" (* ****** ****** *) dynload "assignment2_solu.dats" dynload "assgn2ex4_solu.dats"; dynload "assgn2ex5_solu.dats" (* ****** ****** *) extern fun exp_eval_check (e: exp, ans: int): bool = "assgn2ex4_exp_eval_check" (* ****** ****** *) staload _(*anonymous*) = "prelude/DATS/list.dats" staload _(*anonymous*) = "prelude/DATS/list0.dats" extern fun string_implode (cs: list0 char): string = "atspre_string_implode" extern fun string_explode (str: string): list0 char = "atspre_string_explode" (* ****** ****** *) implement main () = let // val () = print ("Testing the function [palindrome_test] is started.\n") val s1 = "abcdefghijklmnopqrstuvwxyz" val ans1 = palindrome_test (s1) val () = assert (ans1 = false) val s1' = string_implode (list0_reverse (string_explode s1)) val s2 = s1 + s1' val ans1 = palindrome_test (s2) val () = assert (ans1 = true) val () = begin print ("Testing the function [palindrome_test] is finished successfully.\n") end // end of [val] // val () = print ("Testing the function [string_perm_test] is started.\n") val () = assert (string_perm_test ("able", "bale")) val () = assert (~string_perm_test ("able", "label")) val () = begin print ("Testing the function [string_perm_test] is finished successfully.\n") end // end of [val] // val () = print ("Testing the function [piglatin_trans] is started.\n") val () = assert (piglatin_trans "able" = "ableyay") val () = assert (piglatin_trans "stripe" = "ipestray") val () = begin print ("Testing the function [piglatin_trans] is finished successfully.\n") end // end of [val] // testing [play24] var err: int = 0 val ans = play24 (3, 3, 8, 8) val () = case+ ans of | EXPOPTsome e => if ~exp_eval_check (e, 24) then err := err + 1 | EXPOPTnone () => err := err + 1 // end of [val] val () = if err > 0 then (prerr "Error: (3, 3, 8, 8) should be a good quad!\n"; exit (1)) val ans = play24 (5, 5, 7, 11) val () = case+ ans of | EXPOPTsome e => if ~exp_eval_check (e, 24) then err := err + 1 | EXPOPTnone () => err := err + 1 // end of [val] val () = if err > 0 then (prerr "Error: (5, 5, 7, 11) should be a good quad!\n"; exit (1)) val ans = play24 (5, 7, 7, 11) val () = case+ ans of | EXPOPTsome e => if ~exp_eval_check (e, 24) then err := err + 1 | EXPOPTnone () => err := err + 1 // end of [val] val () = if err > 0 then (prerr "Error: (5, 7, 7, 11) should be a good quad!\n"; exit (1)) // end of [val] val ans = play24 (4, 4, 10, 10) val () = case+ ans of | EXPOPTsome e => if ~exp_eval_check (e, 24) then err := err + 1 | EXPOPTnone () => err := err + 1 // end of [val] val () = if err > 0 then (prerr "Error: (4, 4, 10, 10) should be a good quad!\n"; exit (1)) // end of [val] (* testing [play24] *) in // empty end // end of [main] (* ****** ****** *) (* end of [assignment2_test.dats] *)