futzing mostly

This commit is contained in:
Dan Buch 2011-08-15 21:59:50 -04:00
parent 59465b1152
commit 828a0287fd
2 changed files with 15 additions and 3 deletions

View File

@ -1,4 +1,7 @@
# vim:fileencoding=utf-8
def insertion_sort(a): def insertion_sort(a):
""" Θ(n^2) """
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

View File

@ -15,7 +15,7 @@ class Test(unittest.TestCase):
self.assertEqual(expected, a) self.assertEqual(expected, a)
def test_big_example(self): def test_100_example(self):
tmpl = list(range(0, 1000)) tmpl = list(range(0, 1000))
a = tmpl[:] a = tmpl[:]
random.shuffle(a) random.shuffle(a)
@ -25,8 +25,17 @@ class Test(unittest.TestCase):
self.assertEqual(expected, a) self.assertEqual(expected, a)
def test_bigger_example(self): def test_reversed_100_example(self):
tmpl = list(range(0, 10000)) tmpl = list(range(0, 1000))
a = list(reversed(tmpl[:]))
expected = tmpl[:]
insertion_sort01.insertion_sort(a)
self.assertEqual(expected, a)
def test_1000_example(self):
tmpl = list(range(0, 1000))
a = tmpl[:] a = tmpl[:]
random.shuffle(a) random.shuffle(a)
expected = tmpl[:] expected = tmpl[:]