diff --git a/insertion_sort01.py b/insertion_sort01.py index 1fbf329..32cdaea 100644 --- a/insertion_sort01.py +++ b/insertion_sort01.py @@ -1,4 +1,7 @@ +# vim:fileencoding=utf-8 + def insertion_sort(a): + """ Θ(n^2) """ for j in range(1, len(a)): key = a[j] i = j - 1 diff --git a/test_insertion_sort01.py b/test_insertion_sort01.py index baff970..a58c225 100644 --- a/test_insertion_sort01.py +++ b/test_insertion_sort01.py @@ -15,7 +15,7 @@ class Test(unittest.TestCase): self.assertEqual(expected, a) - def test_big_example(self): + def test_100_example(self): tmpl = list(range(0, 1000)) a = tmpl[:] random.shuffle(a) @@ -25,8 +25,17 @@ class Test(unittest.TestCase): self.assertEqual(expected, a) - def test_bigger_example(self): - tmpl = list(range(0, 10000)) + def test_reversed_100_example(self): + 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[:] random.shuffle(a) expected = tmpl[:]