prog.tst 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. % Some interpreted tests of PROG for MAIN9
  2. (Dashed "Expect 1 printed")
  3. (shouldbe "Prog Value" (PROG NIL (print 1)) NIL)
  4. (Dashed "Expect 1 and 2 printed")
  5. (shouldbe "Prog value" (PROG NIL (print 1) (print 2) (return 3)) 3)
  6. (Dashed "Test 1 var PROG binding")
  7. (ShouldBe "Before PROG, x=" (setq x 2) 2)
  8. (Shouldbe "Prog value"
  9. (PROG (X)
  10. (ShouldBe "Inside prog, x=" x NIL)
  11. (setq x 3)
  12. (ShouldBe "After setq, x=" x 3)
  13. )
  14. NIL)
  15. (ShouldBe "after exit, x=" x 2)
  16. (Dashed "Test 2 var PROG binding")
  17. (ShouldBe "Before PROG, x=" (setq x 2) 2)
  18. (ShouldBe "Before PROG, y=" (setq y 20) 20)
  19. (Shouldbe "Prog value"
  20. (PROG (X Y)
  21. (ShouldBe "Inside prog, x=" x NIL)
  22. (ShouldBe "Inside prog, y=" y NIL)
  23. (setq x 3)
  24. (setq y 30)
  25. (ShouldBe "After setq, x=" x 3)
  26. (ShouldBe "After setq, y=" y 30)
  27. )
  28. NIL)
  29. (ShouldBe "after exit, x=" x 2)
  30. (ShouldBe "after exit, y=" y 20)
  31. (dashed "Test simple loop in prog")
  32. (shouldbe "Return 0 after 5 loops"
  33. (prog (x)
  34. (setq x 6)
  35. (prin2t "Expect x to decrease from 5 to 1")
  36. L (setq x (sub1 x))
  37. (prin2 " In loop x=")(prin2T x)
  38. (cond ((greaterp x 1) (go L)))
  39. (return 0))
  40. 0)
  41. (shouldbe "Return 1 after 5 loops"
  42. (prog (x)
  43. (setq x 5)
  44. (prin2T "Expect x to decrease from 5 to 1")
  45. L (cond ((lessp x 1) (return 1)))
  46. (prin2 " In loop, x=") (Prin2t x)
  47. (setq x (sub1 x))
  48. (go L))
  49. 1)