forked from OmkarPathak/pygorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sorting.py
More file actions
109 lines (78 loc) · 3.37 KB
/
test_sorting.py
File metadata and controls
109 lines (78 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import unittest
import random
from pygorithm.sorting import (
bubble_sort,
insertion_sort,
selection_sort,
merge_sort,
quick_sort,
counting_sort,
bucket_sort,
shell_sort,
heap_sort)
class TestSortingAlgorithm(unittest.TestCase):
def setUp(self):
# to test numeric numbers
self.array = list(range(15))
random.shuffle(self.array)
self.sorted_array = list(range(15))
# to test alphabets
string = 'pythonisawesome'
self.alphaArray = list(string)
random.shuffle(self.alphaArray)
self.sorted_alpha_array = sorted(string)
class TestBubbleSort(TestSortingAlgorithm):
def test_bubble_sort(self):
self.result = bubble_sort.sort(self.array)
self.assertEqual(self.result, self.sorted_array)
self.alphaResult = bubble_sort.sort(self.alphaArray)
self.assertEqual(self.alphaResult, self.sorted_alpha_array)
class TestInsertionSort(TestSortingAlgorithm):
def test_insertion_sort(self):
self.result = insertion_sort.sort(self.array)
self.assertEqual(self.result, self.sorted_array)
self.alphaResult = insertion_sort.sort(self.alphaArray)
self.assertEqual(self.alphaResult, self.sorted_alpha_array)
class TestSelectionSort(TestSortingAlgorithm):
def test_selection_sort(self):
self.result = selection_sort.sort(self.array)
self.assertEqual(self.result, self.sorted_array)
self.alphaResult = selection_sort.sort(self.alphaArray)
self.assertEqual(self.alphaResult, self.sorted_alpha_array)
class TestMergeSort(TestSortingAlgorithm):
def test_merge_sort(self):
self.result = merge_sort.sort(self.array)
self.assertEqual(self.result, self.sorted_array)
self.alphaResult = merge_sort.sort(self.alphaArray)
self.assertEqual(self.alphaResult, self.sorted_alpha_array)
class TestQuickSort(TestSortingAlgorithm):
def test_quick_sort(self):
self.result = quick_sort.sort(self.array)
self.assertEqual(self.result, self.sorted_array)
self.alphaResult = quick_sort.sort(self.alphaArray)
self.assertEqual(self.alphaResult, self.sorted_alpha_array)
class TestCountingSort(TestSortingAlgorithm):
def test_counting_sort(self):
# counting sort is an integer based sort
self.result = counting_sort.sort(self.array)
self.assertEqual(self.result, self.sorted_array)
class TestBucketSort(TestSortingAlgorithm):
def test_bucket_sort(self):
self.result = bucket_sort.sort(self.array)
self.assertEqual(self.result, self.sorted_array)
self.alphaResult = bucket_sort.sort(self.alphaArray)
self.assertEqual(self.alphaResult, self.sorted_alpha_array)
class TestShellSort(TestSortingAlgorithm):
def test_shell_sort(self):
self.result = shell_sort.sort(self.array)
self.assertEqual(self.result, self.sorted_array)
self.alphaResult = shell_sort.sort(self.alphaArray)
self.assertEqual(self.alphaResult, self.sorted_alpha_array)
class TestHeapSort(TestSortingAlgorithm):
def test_heap_sort(self):
self.result = heap_sort.sort(self.array)
self.assertEqual(self.result, self.sorted_array)
self.alphaResult = heap_sort.sort(self.alphaArray)
self.assertEqual(self.alphaResult, self.sorted_alpha_array)
if __name__ == '__main__':
unittest.main()