-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtestfunctions.py
34 lines (26 loc) · 964 Bytes
/
testfunctions.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
__author__ = 'ijstokes'
# 1. Import the module we want to test
import functions
# 2. Import unittest
import unittest
# 3. Create a class that subclasses TestCase to encapsulate a set of tests
class TestFunctions(unittest.TestCase):
# 4. Create methods whose names are prefixed with "test_"
def test_adder(self):
# 5. Exercise the function under test
result = functions.adder(2,3)
# 6. Assert some expected condition or result
self.assertEqual(result, 5)
def test_lambda(self):
result = functions.adder_lambda(10, 20)
self.assertEqual(result, 30)
def test_class(self):
" a test case for the Class-based function "
pass
def test_partial(self):
result = functions.add10(7)
self.assertEqual(result, 17)
# 7. (optional) for convenience, make the testing module "runnable", to run
# all the tests in this module.
if __name__ == '__main__':
unittest.main()