-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyunit.py
58 lines (42 loc) · 1.76 KB
/
pyunit.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
#-------------------------------------------------------------------------------
# Name: pyunit.py
# Purpose: This file contains the sample unittest cases
#
# Author: Konrad Roeder
# Notes: http://pyunit.sourceforge
# runs under python 3.3.4
#
# Created: 03/14/2014
# Licence: CC0 1.0 Universal
#-------------------------------------------------------------------------------
import unittest #use built-in unittest library
from math_unit import add #use only the add and multiply methods
from math_unit import multiply #from the library math_unit.py
# Setup, teardown and test cases
class AddTest(unittest.TestCase):
def setUp(self):
'''Verify environment is setup properly''' # Printed if setup fails
pass
def tearDown(self):
'''Verify environment is torn down properly''' # Printed if teardown fails
pass
def test_positive_add(self):
'''Verify that adding positive numbers works''' # Printed if test fails
self.assertEqual(add(10,23,22), 55)
self.assertEqual(add(11,23), 34)
self.assertEqual(add(1,1,17), 19)
def test_negative_add(self):
'''Verify that adding negative numbers works''' # Printed if test fails
self.assertEqual(add(-12,23), 11)
def test_negative_add_skip(self):
self.skipTest
'''Verify that skipping tests works''' # Printed if test fails
self.assertEqual(add(-12,23), 11)
def test_positive_multiply(self):
'''Verify that multiplying numbers works''' # Printed if test fails
self.assertEqual(multiply(4,6), 24)
def test_divide(self):
'''Verify that dividing numbers works''' # Printed if test fails
self.assertEqual(divide(4,6), 24)
if __name__=='__main__':
unittest.main()