1
1
import unittest
2
2
import random
3
3
4
- from pygorithm .sorting import (bubble_sort ,
5
- insertion_sort ,
6
- selection_sort ,
7
- merge_sort ,
8
- quick_sort ,
9
- counting_sort ,
10
- bucket_sort ,
11
- shell_sort ,
12
- heap_sort )
13
-
14
- class SortingAlgorithmTests (unittest .TestCase ):
4
+ from pygorithm .sorting import (
5
+ bubble_sort ,
6
+ insertion_sort ,
7
+ selection_sort ,
8
+ merge_sort ,
9
+ quick_sort ,
10
+ counting_sort ,
11
+ bucket_sort ,
12
+ shell_sort ,
13
+ heap_sort )
14
+
15
+
16
+ class TestSortingAlgorithm (unittest .TestCase ):
15
17
def setUp (self ):
16
18
# to test numeric numbers
17
19
self .array = list (range (15 ))
@@ -24,69 +26,78 @@ def setUp(self):
24
26
random .shuffle (self .alphaArray )
25
27
self .sorted_alpha_array = sorted (string )
26
28
27
- class BubbleSortTest (SortingAlgorithmTests ):
29
+
30
+ class TestBubbleSortTest (TestSortingAlgorithm ):
28
31
def test_bubble_sort (self ):
29
32
self .result = bubble_sort .sort (self .array )
30
33
self .assertEqual (self .result , self .sorted_array )
31
34
32
35
self .alphaResult = bubble_sort .sort (self .alphaArray )
33
36
self .assertEqual (self .alphaResult , self .sorted_alpha_array )
34
37
35
- class InsertionSortTest (SortingAlgorithmTests ):
38
+
39
+ class TestInsertionSortTest (TestSortingAlgorithm ):
36
40
def test_insertion_sort (self ):
37
41
self .result = insertion_sort .sort (self .array )
38
42
self .assertEqual (self .result , self .sorted_array )
39
43
40
44
self .alphaResult = insertion_sort .sort (self .alphaArray )
41
45
self .assertEqual (self .alphaResult , self .sorted_alpha_array )
42
46
43
- class SelectionSortTest (SortingAlgorithmTests ):
47
+
48
+ class TestSelectionSortTest (TestSortingAlgorithm ):
44
49
def test_selection_sort (self ):
45
50
self .result = selection_sort .sort (self .array )
46
51
self .assertEqual (self .result , self .sorted_array )
47
52
48
53
self .alphaResult = selection_sort .sort (self .alphaArray )
49
54
self .assertEqual (self .alphaResult , self .sorted_alpha_array )
50
55
51
- class MergeSortTest (SortingAlgorithmTests ):
56
+
57
+ class TestMergeSortTest (TestSortingAlgorithm ):
52
58
def test_merge_sort (self ):
53
59
self .result = merge_sort .sort (self .array )
54
60
self .assertEqual (self .result , self .sorted_array )
55
61
56
62
self .alphaResult = merge_sort .sort (self .alphaArray )
57
63
self .assertEqual (self .alphaResult , self .sorted_alpha_array )
58
64
59
- class QuickSortTest (SortingAlgorithmTests ):
65
+
66
+ class TestQuickSortTest (TestSortingAlgorithm ):
60
67
def test_quick_sort (self ):
61
68
self .result = quick_sort .sort (self .array )
62
69
self .assertEqual (self .result , self .sorted_array )
63
70
64
71
self .alphaResult = quick_sort .sort (self .alphaArray )
65
72
self .assertEqual (self .alphaResult , self .sorted_alpha_array )
66
73
67
- class CountingSortTest (SortingAlgorithmTests ):
74
+
75
+ class TestCountingSortTest (TestSortingAlgorithm ):
68
76
def test_counting_sort (self ):
69
77
# counting sort is an integer based sort
70
78
self .result = counting_sort .sort (self .array )
71
79
self .assertEqual (self .result , self .sorted_array )
72
80
73
- class BucketSortTest (SortingAlgorithmTests ):
81
+
82
+ class TestBucketSortTest (TestSortingAlgorithm ):
74
83
def test_bucket_sort (self ):
75
84
self .result = bucket_sort .sort (self .array )
76
85
self .assertEqual (self .result , self .sorted_array )
77
86
78
87
self .alphaResult = bucket_sort .sort (self .alphaArray )
79
88
self .assertEqual (self .alphaResult , self .sorted_alpha_array )
80
89
81
- class ShellSortTest (SortingAlgorithmTests ):
90
+
91
+ class TestShellSortTest (TestSortingAlgorithm ):
82
92
def test_shell_sort (self ):
83
93
self .result = shell_sort .sort (self .array )
84
94
self .assertEqual (self .result , self .sorted_array )
85
95
86
96
self .alphaResult = shell_sort .sort (self .alphaArray )
87
97
self .assertEqual (self .alphaResult , self .sorted_alpha_array )
88
98
89
- class HeapSortTest (SortingAlgorithmTests ):
99
+
100
+ class TestHeapSortTest (TestSortingAlgorithm ):
90
101
def test_heap_sort (self ):
91
102
self .result = heap_sort .sort (self .array )
92
103
self .assertEqual (self .result , self .sorted_array )
0 commit comments