(* Auto-tester for strBST2string function. *) use "tester.sml"; (* Avoid "unbound variable or constructor" errors. *) datatype strBST = Leaf | Node of string ref * strBST ref * strBST ref; fun strBST2string _ _ = raise Undefined; (* Load file. *) print "\n--> Loading file \"strBST.sml\"\n"; use "strBST.sml" handle _ => (); (* Utility functions for testing. *) local fun strBST2str indent margin (ref Leaf) = "" | strBST2str indent margin (ref (Node(ref s,left,right))) = strBST2str indent (margin ^ indent) right ^ margin ^ s ^ "\n" ^ strBST2str indent (margin ^ indent) left in fun my_strBST2string indent root = strBST2str indent "" root end; (* Test inputs. *) val T0 = ref Leaf; val T1 = ref (Node(ref "m", ref Leaf, ref Leaf)); val T2 = ref (Node(ref "m", ref (Node(ref "g", ref Leaf, ref Leaf)), ref Leaf)); val T3 = ref (Node(ref "m", ref (Node(ref "g", ref Leaf, ref Leaf)), ref (Node(ref "s", ref Leaf, ref Leaf)))); val T4 = ref (Node(ref "m", ref Leaf, ref (Node(ref "s", ref Leaf, ref Leaf)))); val T5 = ref (Node(ref "m", ref (Node(ref "g", ref (Node(ref "d", ref Leaf, ref Leaf)), ref (Node(ref "j", ref Leaf, ref Leaf)))), ref Leaf)); val T6 = ref (Node(ref "m", ref (Node(ref "g", ref (Node(ref "d", ref Leaf, ref Leaf)), ref (Node(ref "j", ref Leaf, ref Leaf)))), ref (Node(ref "s", ref Leaf, ref Leaf)))); val T7 = ref (Node(ref "m", ref (Node(ref "g", ref (Node(ref "d", ref Leaf, ref Leaf)), ref (Node(ref "j", ref Leaf, ref Leaf)))), ref (Node(ref "s", ref (Node(ref "p", ref Leaf, ref Leaf)), ref (Node(ref "v", ref Leaf, ref Leaf)))))); val T8 = ref (Node(ref "m", ref (Node(ref "g", ref Leaf, ref Leaf)), ref (Node(ref "s", ref (Node(ref "p", ref Leaf, ref Leaf)), ref (Node(ref "v", ref Leaf, ref Leaf)))))); val T9 = ref (Node(ref "m", ref Leaf, ref (Node(ref "s", ref (Node(ref "p", ref Leaf, ref Leaf)), ref (Node(ref "v", ref Leaf, ref Leaf)))))); (* Run test cases. *) ( print "\n--> Beginning test cases for function 'strBST2string'...\n"; runtests total grade (fn (i,T) => strBST2string i T) "strBST2string" (fn (i,T) => string2string i ^ "\n" ^ my_strBST2string " " T) (fn x => "\n" ^ x) (op =) [ (("",T0), my_strBST2string "" T0, "", 0.1), (("",T1), my_strBST2string "" T1, "", 0.1), (("",T2), my_strBST2string "" T2, "", 0.1), (("",T3), my_strBST2string "" T3, "", 0.1), (("",T4), my_strBST2string "" T4, "", 0.1), (("",T5), my_strBST2string "" T5, "", 0.1), (("",T6), my_strBST2string "" T6, "", 0.1), (("",T7), my_strBST2string "" T7, "", 0.1), (("",T8), my_strBST2string "" T8, "", 0.1), (("",T9), my_strBST2string "" T9, "", 0.1), ((" ",T0), my_strBST2string " " T0, "", 0.1), ((" ",T1), my_strBST2string " " T1, "", 0.1), ((" ",T2), my_strBST2string " " T2, "", 0.1), ((" ",T3), my_strBST2string " " T3, "", 0.1), ((" ",T4), my_strBST2string " " T4, "", 0.1), ((" ",T5), my_strBST2string " " T5, "", 0.1), ((" ",T6), my_strBST2string " " T6, "", 0.1), ((" ",T7), my_strBST2string " " T7, "", 0.1), ((" ",T8), my_strBST2string " " T8, "", 0.1), ((" ",T9), my_strBST2string " " T9, "", 0.1), ((" ",T0), my_strBST2string " " T0, "", 0.1), ((" ",T1), my_strBST2string " " T1, "", 0.1), ((" ",T2), my_strBST2string " " T2, "", 0.1), ((" ",T3), my_strBST2string " " T3, "", 0.1), ((" ",T4), my_strBST2string " " T4, "", 0.1), ((" ",T5), my_strBST2string " " T5, "", 0.1), ((" ",T6), my_strBST2string " " T6, "", 0.1), ((" ",T7), my_strBST2string " " T7, "", 0.1), ((" ",T8), my_strBST2string " " T8, "", 0.1), ((" ",T9), my_strBST2string " " T9, "", 0.1) ] ); (* Print total grade. *) print ("\n--> Grade = " ^ real2string (!grade) ^ " / " ^ real2string (!total) ^ "\n\n"); (* Quit the SML interpreter. *) exit 0;