forked from uwhpsc-2016/example-python-homework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_example_homework.py
65 lines (45 loc) · 1.73 KB
/
test_example_homework.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
"""Example unit tests for `example_homework`
Important
=========
Do not modify the way in which the functions `square` and `cube` are imported.
This will be exactly the way we import your code for use in grading. You are
encouraged to add as many additional tests as you like.
"""
import unittest
# code should be importable
from example_homework.squaring import square
from example_homework.cubing import cube
class TestSquare(unittest.TestCase):
"""Test the `square` function defined in `example_homework.square`.
Test the basic properties of the `square` function. In particular, how it
behaves on the numbers zero and one as well as some example numbers, both
positive and negative.
"""
def test_zero(self):
self.assertEqual(square(0), 0)
def test_one(self):
self.assertEqual(square(1), 1)
def test_two_three_four(self):
self.assertEqual(square(2), 4)
self.assertEqual(square(3), 9)
self.assertEqual(square(4), 16)
def test_negative(self):
self.assertEqual(square(-1), 1)
class TestCube(unittest.TestCase):
"""Test the `cube` function defined in `example_homework.cube`.
Test the basic properties of the `cube` function. In particular, how it
behaves on the numbers zero and one as well as some example numbers, both
positive and negative.
"""
def test_zero(self):
self.assertEqual(cube(0), 0)
def test_one(self):
self.assertEqual(cube(1), 1)
def test_two_three_four(self):
self.assertEqual(cube(2), 8)
self.assertEqual(cube(3), 27)
self.assertEqual(cube(4), 64)
def test_negative(self):
self.assertEqual(cube(-1), -1)
if __name__ == '__main__':
unittest.main(verbosity=2)