From f0e703c695d15690b3d51048fa9546e137f1d0ef Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Mon, 15 Aug 2011 06:47:22 -0400 Subject: [PATCH] adding a test for first example --- insertion_sort01.py | 12 ++++++------ test_insertion_sort01.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 test_insertion_sort01.py diff --git a/insertion_sort01.py b/insertion_sort01.py index 29ab2f1..1fbf329 100644 --- a/insertion_sort01.py +++ b/insertion_sort01.py @@ -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 diff --git a/test_insertion_sort01.py b/test_insertion_sort01.py new file mode 100644 index 0000000..47291ee --- /dev/null +++ b/test_insertion_sort01.py @@ -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()