Skip to content

Commit a86fddb

Browse files
committed
Basic api tests
1 parent 5ddeed7 commit a86fddb

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

.github/workflows/python-app.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ jobs:
3737
- name: Test with doctest
3838
run: |
3939
python -m doctest -v calculator/api/calculator.py
40-
# - name: Test with pytest
41-
# run: |
42-
# pytest
40+
- name: Test with pytest
41+
run: |
42+
pytest

tests/api_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
from calculator.api import *
3+
4+
@pytest.mark.parametrize("test_input,expected", [
5+
([1], "1"),
6+
(["1"], "1"),
7+
([1, Operator.ADD, 1], "1 + 1"),
8+
(["1", Operator.ADD, "1"], "1 + 1"),
9+
([1, Operator.SUBTRACT], "1 -"),
10+
([1, Operator.DIVIDE], "1 /"),
11+
([1, Operator.MULTIPLY], "1 x"),
12+
([2.6, Operator.ADD, 1.4], "2.6 + 1.4")
13+
])
14+
def test_get_set_equation(test_input, expected):
15+
calc = Calculator()
16+
calc.set_equation(*test_input)
17+
assert calc.get_equation() == expected
18+
19+
@pytest.mark.parametrize("test_input,expected", [
20+
([1, Operator.ADD, 1], "2"),
21+
([1, Operator.SUBTRACT, 2], "-1"),
22+
([1, Operator.DIVIDE, 2], "0.5"),
23+
([2, Operator.MULTIPLY, 4], "8")
24+
])
25+
def test_solve_equation(test_input, expected):
26+
calc = Calculator()
27+
calc.set_equation(*test_input)
28+
calc.solve()
29+
assert calc.get_equation() == expected
30+
31+
@pytest.mark.parametrize("test_input,expected", [
32+
(1, "-1"),
33+
(-1, "1"),
34+
("1", "-1"),
35+
("-1", "1")
36+
])
37+
def test_flip_sign(test_input, expected):
38+
calc = Calculator()
39+
calc.set_equation(test_input)
40+
calc.flip_sign()
41+
assert calc.get_equation() == expected

0 commit comments

Comments
 (0)