adding a test for first example

cat-town
Dan Buch 13 years ago
parent d5f68eaef2
commit f0e703c695

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

@ -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()
Loading…
Cancel
Save