1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/usr/bin/bats
- @test "Print one number" {
- result="$(echo '42=' | ./eval.out)"
- [ "$result" = "42" ]
- }
- @test "Basic addition" {
- result="$(echo '1+2=' | ./eval.out)"
- [ "$result" = "3" ]
- }
- @test "Basic substraction" {
- result="$(echo '1-2=' | ./eval.out)"
- [ "$result" = "-1" ]
- }
- @test "Multiplication priority over addition" {
- result="$(echo '1+2*3=' | ./eval.out)"
- [ "$result" = "7" ]
- }
- @test "Parenthesis priority" {
- result="$(echo '(1+2)*3=' | ./eval.out)"
- [ "$result" = "9" ]
- }
- @test "Three operands with addition" {
- result="$(echo '1+2+3=' | ./eval.out)"
- [ "$result" = "6" ]
- }
- @test "Two parenthesis blocks" {
- result="$(echo '(1 - 1) + (2 - 2) =' | ./eval.out)"
- [ "$result" = "0" ]
- }
- @test "Addition, substraction and multiplication" {
- result="$(echo '1 + 7 - 4 * 2 =' | ./eval.out)"
- [ "$result" = "0" ]
- }
- @test "Negative result" {
- result="$(echo '6 - 14=' | ./eval.out)"
- [ "$result" = "-8" ]
- }
- @test "Minus unary operand" {
- result="$(echo '-4=' | ./eval.out)"
- [ "$result" = "-4" ]
- }
- @test "Basic division" {
- result="$(echo '42 / 7 =' | ./eval.out)"
- [ "$result" = "6" ]
- }
- @test "Basic truncated division" {
- result="$(echo '16 / 3 =' | ./eval.out)"
- [ "$result" = "5" ]
- }
|