box-o-sand/PracticingAlgorithms/test_sorting.py
Dan Buch eacc351b17 Add 'PracticingAlgorithms/' from commit '0b723f2ae0a20ab8c90c33db8c1d9d9acd76a86f'
git-subtree-dir: PracticingAlgorithms
git-subtree-mainline: 0a9428093c
git-subtree-split: 0b723f2ae0
2013-01-09 23:58:26 -05:00

91 lines
1.9 KiB
Python

import random
import unittest
import sorting
class TestInsertionSort(unittest.TestCase):
def test_example(self):
tmpl = [8, 2, 4, 9, 3, 6]
a = tmpl[:]
expected = [2, 3, 4, 6, 8, 9]
sorting.insertion_sort(a)
self.assertEqual(expected, a)
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)
def test_reversed_100_example(self):
tmpl = list(range(0, 1000))
a = list(reversed(tmpl[:]))
expected = tmpl[:]
sorting.insertion_sort(a)
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)
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)
if __name__ == '__main__':
unittest.main()