(* Auto-tester for compose function. *) use "tester.sml"; (* common utility functions *) (* Avoid "unbound variable or constructor" errors. *) exception Negative of int; fun compose _ _ _ = raise Undefined; (* Load file. *) print "\n--> Loading file \"compose.sml\"\n"; use "../compose.sml" handle _ => (); (* Run test cases. *) ( print "\n--> Beginning test cases for function 'compose'...\n"; print "--> For these tests, 'compose f (n,x)' = 'compose n f x'.\n"; runtests total grade (fn (n,r:real) => compose n (fn x => 1.0 / (x + 1.0)) r handle Negative x => real(x)) "compose (fn x => 1.0 / (x + 1.0))" (fn (n,r) => ("(" ^ int2string n ^ "," ^ real2string r ^ ")")) real2string real_eq [ ((0,0.0), 0.0, "(* base case *)", 0.5), ((1,0.0), 1.0, "(* small n *)", 0.5), ((2,1.0), 2.0 / 3.0, "(* small n *)", 0.5), ((11,0.0), 89.0 / 144.0, "(* large n *)", 0.5), ((20,~2.0), 0.618034055728, "(* larger n *)", 0.5), ((~1,0.0), ~1.0, "(* negative n *)", 0.5) ]; runtests total grade (fn (n,s) => compose n (fn x => x ^ (string_rev x)) s handle Negative x => int2string x) "compose (fn x => x ^ (string_rev x))" (fn (n,s) => ("(" ^ int2string n ^ ",\"" ^ s ^ "\")")) string2string (op =) [ ((0,"hi"), "hi", "(* base case *)", 0.5), ((1,"hi"), "hiih", "(* small n *)", 0.5), ((2,"a"), "aaaa", "(* small n *)", 0.5), ((4,"hi"), "hiihhiihhiihhiihhiihhiihhiihhiih", "(* large n *)", 0.5), ((31,""), "", "(* larger n *)", 0.5), ((~1,"hi"), "~1", "(* negative n *)", 0.5) ] ); (* Print total grade. *) print ("\n--> Grade = " ^ real2string (!grade) ^ " / " ^ real2string (!total) ^ "\n\n"); (* Quit the SML interpreter. *) exit 0;