box-o-sand/oldstuff/PracticingAlgorithms/test_sorting.py

91 lines
1.9 KiB
Python
Raw Normal View History

import random
2011-08-15 10:47:22 +00:00
import unittest
import sorting
2011-08-15 10:47:22 +00:00
class TestInsertionSort(unittest.TestCase):
2011-08-15 10:47:22 +00:00
def test_example(self):
tmpl = [8, 2, 4, 9, 3, 6]
a = tmpl[:]
expected = [2, 3, 4, 6, 8, 9]
sorting.insertion_sort(a)
2011-08-15 10:47:22 +00:00
self.assertEqual(expected, a)
2011-08-16 01:59:50 +00:00
def test_100_example(self):
tmpl = list(range(0, 1000))
a = tmpl[:]
random.shuffle(a)
expected = tmpl[:]
sorting.insertion_sort(a)
self.assertEqual(expected, a)
2011-08-16 01:59:50 +00:00
def test_reversed_100_example(self):
tmpl = list(range(0, 1000))
a = list(reversed(tmpl[:]))
expected = tmpl[:]
sorting.insertion_sort(a)
2011-08-16 01:59:50 +00:00
self.assertEqual(expected, a)
def test_1000_example(self):
tmpl = list(range(0, 1000))
a = tmpl[:]
random.shuffle(a)
expected = tmpl[:]
sorting.insertion_sort(a)
self.assertEqual(expected, a)
2011-08-15 10:47:22 +00:00
2011-08-16 02:34:46 +00:00
class TestMergeSort(unittest.TestCase):
def test_example(self):
tmpl = [8, 2, 4, 9, 3, 6]
a = tmpl[:]
expected = [2, 3, 4, 6, 8, 9]
actual = sorting.merge_sort(a)
self.assertEqual(expected, actual)
def test_100_example(self):
tmpl = list(range(0, 1000))
a = tmpl[:]
random.shuffle(a)
expected = tmpl[:]
actual = sorting.merge_sort(a)
self.assertEqual(expected, actual)
def test_reversed_100_example(self):
tmpl = list(range(0, 1000))
a = list(reversed(tmpl[:]))
expected = tmpl[:]
actual = sorting.merge_sort(a)
self.assertEqual(expected, actual)
def test_1000_example(self):
tmpl = list(range(0, 1000))
a = tmpl[:]
random.shuffle(a)
expected = tmpl[:]
actual = sorting.merge_sort(a)
self.assertEqual(expected, actual)
2011-08-15 10:47:22 +00:00
if __name__ == '__main__':
unittest.main()