-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_sort.py
More file actions
50 lines (34 loc) · 1.14 KB
/
test_sort.py
File metadata and controls
50 lines (34 loc) · 1.14 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
import random
from algorithm.sort import *
class TestSort:
def gene_list(self):
for i in range(11):
yield [random.randint(0, 2**i) for _ in range(2**i)]
def sort_t(self, sort_func):
g = self.gene_list()
res = []
for l in g:
lt = l[:]
lt.sort()
res.append(lt == sort_func(l))
return all(res)
def test_bubble_sort(self):
assert self.sort_t(bubble_sort)
def test_bubble_sort_flag(self):
assert self.sort_t(bubble_sort_flag)
def test_count_sort(self):
assert self.sort_t(count_sort)
def test_shell_sort(self):
assert self.sort_t(shell_sort)
def test_seletion_sort(self):
assert self.sort_t(selection_sort)
def test_marge_sort(self):
assert self.sort_t(merge_sort)
def test_quick_sort(self):
assert self.sort_t(quick_sort)
def test_quick_sort_cookbook(self):
assert self.sort_t(quick_sort_cookbook)
def test_insert_sort(self):
assert self.sort_t(insert_sort)
def test_heap_sort(self):
assert self.sort_t(heap_sort)