This repository was archived by the owner on Nov 10, 2024. It is now read-only.
forked from bloominstituteoftechnology/Sorting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_iterative.py
More file actions
42 lines (34 loc) · 1.48 KB
/
test_iterative.py
File metadata and controls
42 lines (34 loc) · 1.48 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
import unittest
import random
from iterative_sorting import *
class IterativeSortingTest(unittest.TestCase):
def test_selection_sort(self):
arr1 = [1, 5, 8, 4, 2, 9, 6, 0, 3, 7]
arr2 = []
arr3 = [0, 1, 2, 3, 4, 5]
arr4 = random.sample(range(200), 50)
self.assertEqual(selection_sort(arr1), [0,1,2,3,4,5,6,7,8,9])
self.assertEqual(selection_sort(arr2), [])
self.assertEqual(selection_sort(arr3), [0,1,2,3,4,5])
self.assertEqual(selection_sort(arr4), sorted(arr4))
def test_bubble_sort(self):
arr1 = [1, 5, 8, 4, 2, 9, 6, 0, 3, 7]
arr2 = []
arr3 = [0, 1, 2, 3, 4, 5]
arr4 = random.sample(range(200), 50)
self.assertEqual(bubble_sort(arr1), [0,1,2,3,4,5,6,7,8,9])
self.assertEqual(bubble_sort(arr2), [])
self.assertEqual(bubble_sort(arr3), [0,1,2,3,4,5])
self.assertEqual(bubble_sort(arr4), sorted(arr4))
# Uncomment this test to test your count_sort implementation
# def test_counting_sort(self):
# arr1 = [1, 5, 8, 4, 2, 9, 6, 0, 3, 7]
# arr2 = []
# arr3 = [1, 5, -2, 4, 3]
# arr4 = random.sample(range(200), 50)
# self.assertEqual(count_sort(arr1), [0,1,2,3,4,5,6,7,8,9])
# self.assertEqual(count_sort(arr2), [])
# self.assertEqual(count_sort(arr3), "Error, negative numbers not allowed in Count Sort")
# self.assertEqual(count_sort(arr4), sorted(arr4))
if __name__ == '__main__':
unittest.main()