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