test.bats 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/bats
  2. @test "Print one number" {
  3. result="$(echo '42=' | ./eval.out)"
  4. [ "$result" = "42" ]
  5. }
  6. @test "Basic addition" {
  7. result="$(echo '1+2=' | ./eval.out)"
  8. [ "$result" = "3" ]
  9. }
  10. @test "Basic substraction" {
  11. result="$(echo '1-2=' | ./eval.out)"
  12. [ "$result" = "-1" ]
  13. }
  14. @test "Substraction with left priority" {
  15. result="$(echo '8 - 2 - 1 =' | ./eval.out)"
  16. [ "$result" = "5" ]
  17. }
  18. @test "Multiplication priority over addition" {
  19. result="$(echo '1+2*3=' | ./eval.out)"
  20. [ "$result" = "7" ]
  21. }
  22. @test "Parenthesis priority" {
  23. result="$(echo '(1+2)*3=' | ./eval.out)"
  24. [ "$result" = "9" ]
  25. }
  26. @test "Three operands with addition" {
  27. result="$(echo '1+2+3=' | ./eval.out)"
  28. [ "$result" = "6" ]
  29. }
  30. @test "Two parenthesis blocks" {
  31. result="$(echo '(1 - 1) + (2 - 2) =' | ./eval.out)"
  32. [ "$result" = "0" ]
  33. }
  34. @test "Addition, substraction and multiplication" {
  35. result="$(echo '1 + 7 - 4 * 2 =' | ./eval.out)"
  36. [ "$result" = "0" ]
  37. }
  38. @test "Negative result" {
  39. result="$(echo '6 - 14=' | ./eval.out)"
  40. [ "$result" = "-8" ]
  41. }
  42. @test "Minus unary operand" {
  43. skip "Feature not implemented"
  44. result="$(echo '-4=' | ./eval.out)"
  45. [ "$result" = "-4" ]
  46. }
  47. @test "Basic division" {
  48. result="$(echo '42 / 7 =' | ./eval.out)"
  49. [ "$result" = "6" ]
  50. }
  51. @test "Basic truncated division" {
  52. result="$(echo '16 / 3 =' | ./eval.out)"
  53. [ "$result" = "5" ]
  54. }
  55. @test "Division with left priority" {
  56. result="$(echo '8 / 4 / 2 =' | ./eval.out)"
  57. [ "$result" = "1" ]
  58. }
  59. @test "Division by zero" {
  60. # To improve
  61. result="$(echo '42 / 0 =' | ./eval.out)"
  62. [ "$result" = "42" ]
  63. }
  64. @test "Complex division" {
  65. result="$(echo '192 / 3 / 16 =' | ./eval.out)"
  66. [ "$result" = "4" ]
  67. }
  68. @test "Complex truncated division" {
  69. result="$(echo '182 / 3 / 15 =' | ./eval.out)"
  70. [ "$result" = "4" ]
  71. }
  72. @test "Mixed operation with * + / -" {
  73. result="$(echo '15 * (1 + 1 + 1 + 4 - 2*2) / 3 / 15 =' | ./eval.out)"
  74. [ "$result" = "1" ]
  75. }