-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_calc.py
49 lines (35 loc) · 1.24 KB
/
test_calc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from calculator import Calc
def test_successful_calculation():
test_value = Calc('11+11+11+11+11+11+11+11+11+11+11+11').calculate()
assert type(test_value) is int
assert 132 == test_value
test_value = Calc('1*10-5000000+200').output()
assert type(test_value) is int
assert -4999790 == test_value
test_value = Calc('1*2+3*4-5*6+7*8-9*10+123*456').calculate()
assert type(test_value) is int
assert 56038 == test_value
test_value = Calc('0').calculate()
assert type(test_value) is int
assert 0 == test_value
test_value = Calc('100-10-20-30').calculate()
assert type(test_value) is int
assert 40 == test_value
def test_type_error_validate():
try:
Calc(345).validate()
except Exception as e:
assert type(e) is TypeError
else:
assert False, 'No error raised when was expected to.'
def test_syntax_error_validate():
try:
Calc('1**2').validate()
except Exception as e:
assert type(e) is SyntaxError
else:
assert False, 'No error raised when was expected to.'
def test_type_error_output():
assert 'Wrong input type.' == Calc(123).output()
def test_syntax_error_output():
assert 'Invalid input syntax.' == Calc('1**2').output()