-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_calculator.py
71 lines (49 loc) · 1.31 KB
/
test_calculator.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# from calculator import square
# def main():
# test_square()
# def test_square():
# if square(2) != 4:
# print("2 squared was not 4")
# if square(3) != 9:
# print("3 squared was not 9")
# if __name__ == "__main__":
# main()
#assert another way of testing code
# from calculator import square
# def main():
# test_square()
# def test_square():
# try:
# assert square(2) == 4
# except AssertionError:
# print("2 squared was ot 4")
# try:
# assert square(3) == 9
# except AssertionError:
# print("3 squared was not 9")
# if __name__ == "__main__":
# main()
#reduce the number of code by catching the error and assert
# use of pytest library
#unit test test for functions that you have written
# from calculator import square
# def test_square():
# assert square(2) == 4
# assert square(3) == 9
# assert square(-2) == 4
# assert square (-3) == 9
# assert square(0) == 0
#break test into different categories
import pytest
from calculator import square
def test_positive():
assert square(2) == 4
assert square(3) == 9
def test_negative():
assert square(-2) == 4
assert square (-3) == 9
def test_zero():
assert square(0) == 0
def test_str():
with pytest.raises(TypeError):
square("cat")