adding a test for first example

This commit is contained in:
Dan Buch 2011-08-15 06:47:22 -04:00
parent d5f68eaef2
commit f0e703c695
2 changed files with 25 additions and 6 deletions

View File

@ -1,8 +1,8 @@
def insertion_sort(A):
for j in range(1, len(A)):
key = A[j]
def insertion_sort(a):
for j in range(1, len(a)):
key = a[j]
i = j - 1
while i >= 0 and A[i] > key:
A[i + 1] = A[i]
while i >= 0 and a[i] > key:
a[i + 1] = a[i]
i = i - 1
A[i + 1] = key
a[i + 1] = key

19
test_insertion_sort01.py Normal file
View File

@ -0,0 +1,19 @@
import unittest
import insertion_sort01
class Test(unittest.TestCase):
def test_example(self):
tmpl = [8, 2, 4, 9, 3, 6]
a = tmpl[:]
expected = [2, 3, 4, 6, 8, 9]
insertion_sort01.insertion_sort(a)
self.assertEqual(expected, a)
if __name__ == '__main__':
unittest.main()