test.bats 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 "Multiplication priority over addition" {
  15. result="$(echo '1+2*3=' | ./eval.out)"
  16. [ "$result" = "7" ]
  17. }
  18. @test "Parenthesis priority" {
  19. result="$(echo '(1+2)*3=' | ./eval.out)"
  20. [ "$result" = "9" ]
  21. }
  22. @test "Three operands with addition" {
  23. result="$(echo '1+2+3=' | ./eval.out)"
  24. [ "$result" = "6" ]
  25. }
  26. @test "Two parenthesis blocks" {
  27. result="$(echo '(1 - 1) + (2 - 2) =' | ./eval.out)"
  28. [ "$result" = "0" ]
  29. }
  30. @test "Addition, substraction and multiplication" {
  31. result="$(echo '1 + 7 - 4 * 2 =' | ./eval.out)"
  32. [ "$result" = "0" ]
  33. }
  34. @test "Negative result" {
  35. result="$(echo '6 - 14=' | ./eval.out)"
  36. [ "$result" = "-8" ]
  37. }
  38. @test "Minus unary operand" {
  39. result="$(echo '-4=' | ./eval.out)"
  40. [ "$result" = "-4" ]
  41. }
  42. @test "Basic division" {
  43. result="$(echo '42 / 7 =' | ./eval.out)"
  44. [ "$result" = "6" ]
  45. }
  46. @test "Basic truncated division" {
  47. result="$(echo '16 / 3 =' | ./eval.out)"
  48. [ "$result" = "5" ]
  49. }