-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestadder.py
More file actions
27 lines (19 loc) · 846 Bytes
/
testadder.py
File metadata and controls
27 lines (19 loc) · 846 Bytes
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
"""
Demonstrates the fundamentals of unittest.
adder() is a function that lets you 'add' integers, strings, and lists.
"""
from adder import adder # keep the tested code separate from the tests
import unittest
class TestAdder(unittest.TestCase):
def test_numbers(self):
self.assertEqual(adder(3,4), 7, "3 + 4 should be 7")
def test_strings(self):
self.assertEqual(adder('x','y'), 'xy', "x + y should be xy")
def test_lists(self):
self.assertEqual(adder([1,2],[3,4]), [1,2,3,4], "[1,2] + [3,4] should be [1,2,3,4]")
def test_number_and_string(self):
self.assertEqual(adder(1, 'two'), '1two', "1 + two should be 1two")
def test_numbers_and_list(self):
self.assertEqual(adder(4,[1,2,3]), [1,2,3,4], "4 + [1,2,3] should be [1,2,3,4]")
if __name__ == "__main__":
unittest.main()