This repository has been archived by the owner on Mar 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_shellsort.py
79 lines (60 loc) · 2.38 KB
/
test_shellsort.py
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
from shellsort import shell_sort
import unittest
class TestsShellSort(unittest.TestCase):
def test_ok(self):
data = [5, 6, 4, 3, 8, 9, 10, 234, 123, 543, 234, 654]
self.assertEquals(shell_sort(data), sorted(data))
def test_list_1_element(self):
data = [1]
self.assertEquals(shell_sort(data), sorted(data))
def test_list_2_elements(self):
data = [4, 1]
self.assertEquals(shell_sort(data), sorted(data))
def test_list_only_zeroes(self):
data = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
self.assertEquals(shell_sort(data), sorted(data))
def test_list_same_values(self):
data = [5, 5, 5, 5, 5, 5, 5, 5, 5]
self.assertEquals(shell_sort(data), sorted(data))
def test_sorted_list(self):
data = [1, 2, 3, 4]
self.assertEquals(shell_sort(data), sorted(data))
def test_empty_list_raise_error(self):
data = []
with self.assertRaises(ValueError):
shell_sort(data)
def test_list_of_empty_lists_raise_error(self):
data = [[], [], [], []]
with self.assertRaises(TypeError):
shell_sort(data)
def test_list_of_non_empty_lists_raise_error(self):
data = [[1, 2, 3, 4], [1, 2, 3, 4], [5, 6, 7, 8], [7, 4, 6, 3]]
with self.assertRaises(TypeError):
shell_sort(data)
def test_list_of_strings_raise_error(self):
data = ['4', '3', '1', '2'],
with self.assertRaises(TypeError):
shell_sort(data)
def test_list_of_ints_and_strings_raise_error(self):
data = [1, 2, 3, 'e'],
with self.assertRaises(TypeError):
shell_sort(data)
def test_string_raise_error(self):
data = '5,4,3,2,1'
with self.assertRaises(TypeError):
shell_sort(data)
def test_tuple_raise_error(self):
data = (1, 2, 3, 4, 5, 2, 4, 1, 3),
with self.assertRaises(TypeError):
shell_sort(data)
def test_dict_raise_error(self):
data = {1: 2, 3: 4, 5: 6, 7: 8}
with self.assertRaises(TypeError):
shell_sort(data)
def test_set_raise_error(self):
data = {5, 4, 3, 2, 6}
with self.assertRaises(TypeError):
shell_sort(data)
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestsShellSort)
unittest.TextTestRunner(verbosity=2).run(suite)