excluded-bonus-math_operators.story 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. Some basic mathematical operations
  2. Narrative:
  3. Our lisp interpreter should be able to
  4. perform basic maths. It will rely on the
  5. methods found in java.lang.Math for functions
  6. like cos, sin, abs, etc.
  7. Scenario: built-in operators
  8. Given a lisp interpreter
  9. When the expression entered is <expression>
  10. Then the result should be <result>
  11. Examples:
  12. |expression |result|
  13. |(+ 1 1) | 2 |
  14. |(+ 1 2 3 4) | 10 |
  15. |(- 5) | -5 |
  16. |(- 1 3) | -2 |
  17. |(* 1 3) | 3 |
  18. |(* 1 3 5 7) |105 |
  19. |(/ 3 2) | 1 |
  20. |(max 2 3) | 3 |
  21. Scenario: Division by zero
  22. Given a lisp interpreter
  23. When the expression entered is (/ 3 0)
  24. Then the result should display the error message Division by zero
  25. Scenario: operands must be evaluated
  26. Given a lisp interpreter
  27. When the expression entered is <expression>
  28. Then the result should be <result>
  29. Examples:
  30. |expression |result|
  31. |(+ (* 2 3) (- 8 5)) | 9 |
  32. |(* (+ 1 (* 2 3) 4) 9) | 99 |
  33. |(- (* 2 3) (* 3 4))| -6|
  34. |(/ (* 2 7) (* 4 5.0))|0.7|
  35. |(if (or (> 4 5) (< 4 5)) (+ 2 3) (- 3 2))| 5 |
  36. |(or (= (+ 2 3) 5 (/ 10 2)) (> 5 0))|#t|
  37. |(and (> (+ 2 3) (- 9 8)) (= (* 3 3) (+ 3 6) (/ 27 3) (- 12 3)))|#t|
  38. |(not (> 26 56))|#t|
  39. Scenario: java.lang.Math functions
  40. Given a lisp interpreter
  41. When the expression entered is <expression>
  42. Then the result should be <result>
  43. Examples:
  44. |expression|result|
  45. |(abs (- 8)) |8 |
  46. |(abs (- 8.0))|8.0 |
  47. |(cbrt 8.0)|2.0|
  48. |(ceil 8.45)|9.0|
  49. |(floor 8.45)|8.0|
  50. |(log10 100)|2.0|
  51. |(cos 0) |1.0 |
  52. |(pow 2 3) |8.0 |
  53. |(min 2 3) |2 |
  54. |(min 2.0 3.0)|2.0|
  55. |(max 2 3) |3 |
  56. |(max 2.0 3.0)|3.0|
  57. |(rint 8.45)|8.0|
  58. |(rint 8.55)|9.0|
  59. |(round 8.45)|8|
  60. |(round 8.55)|9|
  61. |(signum 5.9)|1.0|
  62. |(signum (- 5.9))|-1.0|
  63. |(signum 0.0)|0.0|
  64. Scenario: Wrong number of operands for Math methods poke M. Valembois
  65. Given a lisp interpreter
  66. When the expression entered is <expression>
  67. Then the result should display the error message Invalid number of operands
  68. Examples:
  69. |expression|
  70. |(abs 8 9) |
  71. |(abs)|
  72. |(abs 8.0 9.0)|
  73. |(cbrt 8.0 16.0)|
  74. |(cbrt)|
  75. |(ceil 8.45 9.1)|
  76. |(ceil)|
  77. |(floor 8.45 9.12)|
  78. |(floor)|
  79. |(log10 100 1000)|
  80. |(log10)|
  81. |(cos 0 90)|
  82. |(cos)|
  83. |(pow 2 3 4)|
  84. |(pow)|
  85. |(min 2 3 4) |
  86. |(min)|
  87. |(min 2.0 3.0 4.0)|
  88. |(max 2 3 4) |
  89. |(max)|
  90. |(max 2.0 3.0 4.0)|
  91. |(rint 8.45 9.45)|
  92. |(rint)|
  93. |(round 8.45 9.55)|
  94. |(round)|
  95. |(signum 5.9 (- 7.8))|
  96. |(signum)|