Skip to content

Commit 4192eba

Browse files
Create test_bubble_sort.py
1 parent d33f9b3 commit 4192eba

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test_algo/test_bubble_sort.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import unittest
2+
import random
3+
from sorts.bubble_sort import bubble_sort
4+
5+
6+
# testing the bubble_sort function
7+
class TestBubbleSort(unittest.TestCase):
8+
# Full test
9+
def test_bubble_sort(self):
10+
self.assertEqual(bubble_sort([0, 5, 2, 3, 2]), [0, 2, 2, 3, 5])
11+
self.assertEqual(bubble_sort([0, 5, 2, 3, 2]), sorted([0, 5, 2, 3, 2]))
12+
self.assertEqual(bubble_sort([]), sorted([]))
13+
self.assertEqual(bubble_sort([-2, -45, -5]), sorted([-2, -45, -5]))
14+
self.assertEqual(bubble_sort([-23, 0, 6, -4, 34]), sorted([-23, 0, 6, -4, 34]))
15+
self.assertEqual(bubble_sort(['d', 'a', 'b', 'e', 'c']), sorted(['d', 'a', 'b', 'e', 'c']))
16+
17+
def test_bubble_sort_random(self):
18+
19+
collection = random.sample(range(-50, 50), 100)
20+
self.assertEqual(bubble_sort(collection), sorted(collection))
21+
22+
def test_bubble_sort_string(self):
23+
import string
24+
collection = random.choices(string.ascii_letters + string.digits, k=100)
25+
self.assertEqual(bubble_sort(collection), sorted(collection))
26+
27+
if __name__ == '__main__':
28+
unittest.main()

0 commit comments

Comments
 (0)