#use "lexer.ml" #use "parser.ml" #use "eval.ml" #use "oUnit.ml" (* You should have this stuff in eval.ml * type value = VNum of int | VList of value list | VBool of bool | VPrim of string | ... (* add your own types here *) ;; *) (* need to define function string_of_value: value -> string *) let algolCheck = fun output input -> assert_equal output (string_of_value (eval_string input));; let tests = "assign4xctest" >::: [ "numberP" >:: (fun _ -> algolCheck "number?" "number?" ); "mathOp" >:: (fun _ -> algolCheck "30" "2 * 3 + 12" ); "parseException" >:: (fun _ -> try algolCheck "haha" " 1 +" with | ParserError(x) -> () ); "evalException" >:: (fun _ -> try algolCheck "mojo" "1 + number?" with | EvalError(x) -> () ); "append" >:: (fun _ -> algolCheck "(1 2 3 1 2 3)" "let Y := map f to let g := map x to f(map z1,z2 to (x(x))(z1,z2)); in g(g); APPEND := map ap to map x,y to if x = null then y else cons(first(x), ap(rest(x), y)); l := cons(1,cons(2,cons(3,null))); in (Y(APPEND))(l,l)" ); "letRec" >:: (fun _ -> algolCheck "(1 2 3 1 2 3)" "let append := map x,y to if x = null then y else cons(first(x), append(rest(x), y)); l := cons(1,cons(2,cons(3,null))); in append(l,l)" ); "emptyBlock" >:: (fun _ -> try algolCheck "0" "{ }" with | ParserError(x) -> () ); "block" >:: (fun _ -> algolCheck "1" "{3; 2; 1}" ); "dupVar" >:: (fun _ -> try algolCheck "ha!" "let x:=3; x:=4; in x" with | SyntaxError(x) -> () ); "swap" >:: (fun _ -> algolCheck "2500" " let ref x := 20; ref y := 5; z := 10; swap := map ref x, ref y to let z := x; in {x <- y; y <- z}; in { x <- x + y; swap(x,y); swap(x,z); x * y * z} " ); ] let _ = run_test_tt ~verbose:true tests