forked from OmkarPathak/pygorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting_tests.py
More file actions
98 lines (77 loc) · 3.58 KB
/
Copy pathsorting_tests.py
File metadata and controls
98 lines (77 loc) · 3.58 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
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 SortingAlgorithmTests(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 BubbleSortTest(SortingAlgorithmTests):
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 InsertionSortTest(SortingAlgorithmTests):
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 SelectionSortTest(SortingAlgorithmTests):
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 MergeSortTest(SortingAlgorithmTests):
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 QuickSortTest(SortingAlgorithmTests):
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 CountingSortTest(SortingAlgorithmTests):
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 BucketSortTest(SortingAlgorithmTests):
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 ShellSortTest(SortingAlgorithmTests):
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 HeapSortTest(SortingAlgorithmTests):
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()