;; Tests for the parser. ;; You should add at least 2 more. ;; To use this file, run parser.rkt in DrRacket, ;; and then at the prompt below, type: ;; (load "parser-tests.rkt") (reset-tests) (check-expect (parse "def x 42~0 meter") '(def x (uql 42 0 (meter) ())) ) (check-expect (parse "# x") '(eval (norm (uql 1 0 (x) ()))) ) (check-expect (parse "def z y + g - x") '(def z (add (uql 1 0 (y) ()) (sub (uql 1 0 (g) ()) (uql 1 0 (x) ())))) ) (check-expect (parse "def x 3 ~ 1 foot foot / second") '(def x (div (uql 3 1 (foot foot) ()) (uql 1 0 (second) ()))) ) (check-expect (parse "def x 3") '(def x (uql 3 0 () ())) ) (check-expect (parse "def x -2 meter / second") '(def x (div (neg (uql 2 0 (meter) ())) (uql 1 0 (second) ()))) ) (check-expect (parse "def x (y+x)^-2") '(def x (pow (add (uql 1 0 (y) ()) (uql 1 0 (x) ())) -2)) ) (check-expect (parse "def x y+x^2") '(def x (add (uql 1 0 (y) ()) (pow (uql 1 0 (x) ()) 2))) ) (check-expect (parse "def x y+(x^2-(z/y))") '(def x (add (uql 1 0 (y) ()) (sub (pow (uql 1 0 (x) ()) 2) (div (uql 1 0 (z) ()) (uql 1 0 (y) ()))))) ) (check-expect (parse "def x y+(x^2-z/y)") '(def x (add (uql 1 0 (y) ()) (sub (pow (uql 1 0 (x) ()) 2) (div (uql 1 0 (z) ()) (uql 1 0 (y) ()))))) ) (check-expect (parse "def a 35 ~ 2 / mm") '(def a (div (uql 35 2 () ()) (uql 1 0 (mm) ()))) ) (check-expect (parse "mile") '(eval (uql 1 0 (mile) ())) ) (generate-report)