(* Auto-tester for search function. *) use "tester.sml"; (* Avoid "unbound variable or constructor" errors. *) datatype strBST = Leaf | Node of string ref * strBST ref * strBST ref; fun search _ _ = 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 val my_strBST2string = strBST2str " " " " 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 (Node(ref "s", ref Leaf, ref Leaf)))); (* Run test cases. *) ( print "\n--> Beginning test cases for function 'search'...\n"; runtests total grade (fn (T,x) => search T x) "search" (fn (T,x) => "for \"" ^ x ^ "\" in\n" ^ my_strBST2string T) bool2string (op =) [ ((T0,""), false, "", 0.2), ((T0,"m"), false, "", 0.2), ((T1,""), false, "", 0.1), ((T1,"g"), false, "", 0.2), ((T1,"m"), true, "", 0.3), ((T1,"s"), false, "", 0.2), ((T2,""), false, "", 0.1), ((T2,"d"), false, "", 0.2), ((T2,"g"), true, "", 0.3), ((T2,"j"), false, "", 0.2), ((T2,"m"), true, "", 0.3), ((T2,"p"), false, "", 0.2), ((T2,"s"), true, "", 0.3), ((T2,"v"), false, "", 0.2) ] ); (* Print total grade. *) print ("\n--> Grade = " ^ real2string (!grade) ^ " / " ^ real2string (!total) ^ "\n\n"); (* Quit the SML interpreter. *) exit 0;