forked from jonycse/pythonSampleCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunitTestSample.py
More file actions
58 lines (45 loc) · 1.16 KB
/
unitTestSample.py
File metadata and controls
58 lines (45 loc) · 1.16 KB
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
import random
import unittest
def insert(A,i):
value = A[i]
j = i
while j != 0 and A[j-1]>value:
A[j] = A[j-1]
j = j - 1
A[j] = value
def insertion_sort(A):
for i in range(len(A)):
insert(A, i)
class TestInsertionSort(unittest.TestCase):
def setUp(self):
print "Setup ..."
def testSortRange(self):
print "TestSortRange .... \n"
n = 10
a = range(n)
random.shuffle(a)
insertion_sort(a)
self.assertEqual(a, range(n))
n = 1
a = range(n)
random.shuffle(a)
insertion_sort(a)
self.assertEqual(a, range(n))
n = 77
a = range(n)
random.shuffle(a)
insertion_sort(a)
self.assertEqual(a, range(n))
def testSortData(self):
print "TestSortData .... \n"
a = []
r = []
insertion_sort(a)
self.assertEqual(a, r)
a = [3, 1, 2]
r = [1, 2, 3]
insertion_sort(a)
self.assertEqual(a, r)
if __name__=="__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestInsertionSort)
unittest.TextTestRunner(verbosity=2).run(suite)