@@ -8,18 +8,24 @@ def bubble_sort(collection):
8
8
Examples:
9
9
>>> bubble_sort([0, 5, 2, 3, 2])
10
10
[0, 2, 2, 3, 5]
11
-
12
- >>> bubble_sort([])
13
- []
14
-
15
- >>> bubble_sort([-2, -45, -5])
16
- [-45, -5, -2]
17
-
18
- >>> bubble_sort([-23, 0, 6, -4, 34])
19
- [-23, -4, 0, 6, 34]
20
-
11
+ >>> bubble_sort([0, 5, 2, 3, 2]) == sorted([0, 5, 2, 3, 2])
12
+ True
13
+ >>> bubble_sort([]) == sorted([])
14
+ True
15
+ >>> bubble_sort([-2, -45, -5]) == sorted([-2, -45, -5])
16
+ True
21
17
>>> bubble_sort([-23, 0, 6, -4, 34]) == sorted([-23, 0, 6, -4, 34])
22
18
True
19
+ >>> bubble_sort(['d', 'a', 'b', 'e', 'c']) == sorted(['d', 'a', 'b', 'e', 'c'])
20
+ True
21
+ >>> import random
22
+ >>> collection = random.sample(range(-50, 50), 100)
23
+ >>> bubble_sort(collection) == sorted(collection)
24
+ True
25
+ >>> import string
26
+ >>> collection = random.choices(string.ascii_letters + string.digits, k=100)
27
+ >>> bubble_sort(collection) == sorted(collection)
28
+ True
23
29
"""
24
30
length = len (collection )
25
31
for i in range (length - 1 ):
@@ -34,8 +40,11 @@ def bubble_sort(collection):
34
40
35
41
36
42
if __name__ == "__main__" :
43
+ import doctest
37
44
import time
38
45
46
+ doctest .testmod ()
47
+
39
48
user_input = input ("Enter numbers separated by a comma:" ).strip ()
40
49
unsorted = [int (item ) for item in user_input .split ("," )]
41
50
start = time .process_time ()
0 commit comments