Skip to content

Commit 559193a

Browse files
authored
tests: add tests for sorts (#199)
1 parent ba9a33f commit 559193a

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

test/sorts.jl

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
using TheAlgorithms.Sorts
22

33
@testset "Sorts" begin
4-
sorts = [
5-
bogo_sort!
6-
bubble_sort!
7-
bucket_sort!
8-
counting_sort!
9-
exchange_sort!
10-
heap_sort!
11-
insertion_sort!
12-
merge_sort!
13-
quick_sort!
14-
selection_sort!
15-
]
4+
@testset "bogo_sort" begin
5+
x = [3, 1, 4, 2]
6+
bogo_sort!(x)
7+
@test x == [1, 2, 3, 4]
8+
end
9+
10+
@testset "deterministic sorts" begin
11+
sorts = [
12+
bubble_sort!
13+
bucket_sort!
14+
counting_sort!
15+
exchange_sort!
16+
heap_sort!
17+
insertion_sort!
18+
merge_sort!
19+
quick_sort!
20+
selection_sort!
21+
]
22+
23+
for f in sorts
24+
x = [3, 5, 1, 4, 2]
25+
f(x)
26+
@test x == [1, 2, 3, 4, 5]
1627

17-
for f in sorts
18-
x = [3, 5, 1, 4, 2]
19-
f(x)
20-
@test x == [1, 2, 3, 4, 5]
28+
y = [5, 2, 2, 2, 1, 5, 2, 34, 6, 4, 3, 2, 1, 2, 3, 4, 10, 1]
29+
f(y)
30+
@test y == [1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 10, 34]
31+
end
2132
end
2233
end

0 commit comments

Comments
 (0)