12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #!/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 "Substraction with left priority" {
- result="$(echo '8 - 2 - 1 =' | ./eval.out)"
- [ "$result" = "5" ]
- }
- @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" {
- skip "Feature not implemented"
- 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" ]
- }
- @test "Division with left priority" {
- result="$(echo '8 / 4 / 2 =' | ./eval.out)"
- [ "$result" = "1" ]
- }
- @test "Division by zero" {
- # To improve
- result="$(echo '42 / 0 =' | ./eval.out)"
- [ "$result" = "42" ]
- }
- @test "Complex division" {
- result="$(echo '192 / 3 / 16 =' | ./eval.out)"
- [ "$result" = "4" ]
- }
- @test "Complex truncated division" {
- result="$(echo '182 / 3 / 15 =' | ./eval.out)"
- [ "$result" = "4" ]
- }
- @test "Mixed operation with * + / -" {
- result="$(echo '15 * (1 + 1 + 1 + 4 - 2*2) / 3 / 15 =' | ./eval.out)"
- [ "$result" = "1" ]
- }
|