forked from jenkins-docs/simple-python-pyinstaller-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_calc.py
48 lines (41 loc) · 1.38 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
import unittest
import calc
class TestCalc(unittest.TestCase):
"""
Test the add function from the calc library
"""
def test_add_integers(self):
"""
Test that the addition of two integers returns the correct total
"""
result = calc.add2(1, 2)
self.assertEqual(result, 3)
def test_add_floats(self):
"""
Test that the addition of two floats returns the correct result
"""
result = calc.add2('10.5', 2)
self.assertEqual(result, 12.5)
def test_add_strings(self):
"""
Test the addition of two strings returns the two strings as one
concatenated string
"""
result = calc.add2('abc', 'def')
self.assertEqual(result, 'abcdef')
def test_add_string_and_integer(self):
"""
Test the addition of a string and an integer returns them as one
concatenated string (in which the integer is converted to a string)
"""
result = calc.add2('abc', 3)
self.assertEqual(result, 'abc3')
def test_add_string_and_number(self):
"""
Test the addition of a string and a float returns them as one
concatenated string (in which the float is converted to a string)
"""
result = calc.add2('abc', '5.5')
self.assertEqual(result, 'abc5.5')
if __name__ == '__main__':
unittest.main()