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