Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. fv tests
  2.  
  3. --fvTest :: String -> [String] -> IO ()
  4. makefvTest inp vars
  5. = TestCase (assertEqual ("for (fvs "++inp++")") (fvs inp) (sort vars))
  6.  
  7. -- test expr. expected result
  8. testfv1 = makefvTest "x" ["x"]
  9. testfv2 = makefvTest "let x = y in (+ x y)" ["y"]
  10. testfv3 = makefvTest "((fn x => (+ x y)) y)" ["y"]
  11. testfv4 = makefvTest fv4 ["x","p"]
  12. testfv5 = makefvTest fv5 []
  13. --own tests
  14. testfv6 = makefvTest fv6 ["x"]
  15. testfv7 = makefvTest fv7 ["y"]
  16. testfv8 = makefvTest fv8 []
  17.  
  18. fv4 = "((fn p => (p x)) (fn x => (+ x p)))"
  19. fv5 = "let c = fn x => fn p => (p (* x x)) in "
  20. ++ " (let inc = fn x => (+ 1 x) in (c 4 inc))"
  21. fv6 = "let y = (+ y 3) in (+ x y)"
  22. fv7 = "let x = (+ x y) in (let y = (+ y 1) in (let x = (+ 3 x) in (+ x y)))"
  23. fv8 = "fn f => f (g x)"
  24.  
  25.  
  26. -- the printed output of the follow looks horrible inside of emacs
  27. runFvAll = runTestTT $ TestList [ "Test 1" ~: testfv1
  28. , "Test 2" ~: testfv2
  29. , "Test 3" ~: testfv3
  30. , "Test 4" ~: testfv4
  31. , "Test 5" ~: testfv5
  32. , "Test 6" ~: testfv6 -- y is bound because it's named, but x isn't
  33. , "Test 7" ~: testfv7 -- x is bound to a definition, but y isn't
  34. , "Test 8" ~: testfv8] -- none of the variables are bound to a definition
  35.  
  36. subst tests
  37.  
  38. st14 = runSubst "let x = (* 7 4) in (- y 1)" "y" "(* 7 4)"
  39. -- result: let a = (* 7 4) in (- (+ z 3) 1)
  40. -- Substituting "y" for "(* 7 4)" in "let x = (* 7 4) in (- y 1)" yields
  41. -- the given answer
  42. st15 = runSubst "(y (x z))" "z" "fn z => (+ z 1)"
  43. -- result: (y (x (fn z => (+ z 1))))
  44. -- Substituting "fn z => (+ z 1)" for the variable "z" in "(y (x z))"
  45. -- just means plugging the former into the latter
  46. st16 = runSubst "fn x => (* x y)" "y" "x"
  47. -- result: (fn a => (* x x))
  48. -- Substituting "x" for "y" requires a new name for the function
  49. -- to be determined with fresh, 'a'
  50. -- e p x
  51. -- e x p
  52.  
  53. runSubAll = do { st1; st2; st3; st4; st5; st6; st7; st8; st9; st10;
  54. st11; st12; st13; st14; st15; st16
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement