summaryrefslogtreecommitdiff
path: root/sort/sort_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'sort/sort_test.go')
-rw-r--r--sort/sort_test.go27
1 files changed, 24 insertions, 3 deletions
diff --git a/sort/sort_test.go b/sort/sort_test.go
index 3cfbc77..fb8870b 100644
--- a/sort/sort_test.go
+++ b/sort/sort_test.go
@@ -20,6 +20,14 @@ var arrayListCache map[string]ds.ArrayList[int]
type sortAlgorithm[V ds.Number] func(ds.ArrayList[V]) ds.ArrayList[V]
type sortAlgorithmInt func([]int) []int
+func TestSleepSort(t *testing.T) {
+ a := ds.NewRandomArrayList[int](10, 10)
+ a = Sleep(a)
+ if !a.Sorted() {
+ t.Errorf("Array not sorted: %v", a)
+ }
+}
+
func TestSelectionSort(t *testing.T) {
for i := minLength; i <= maxSlowLength; i *= factor {
test(Selection[int], i, t)
@@ -79,11 +87,24 @@ func TestQuick3WaySort(t *testing.T) {
func TestShuffleSort(t *testing.T) {
for i := 10; i <= maxLength; i *= factor {
- testShuffle(Shuffle[int], i, t)
+ testShuffleSort(Shuffle[int], i, t)
}
}
-func benchmarknsertionSort(b *testing.B) {
+func BenchmarkSleepSort(b *testing.B) {
+ a := ds.NewRandomArrayList[int](10, 10)
+ aux := ds.NewArrayList[int](10)
+
+ b.Run(fmt.Sprintf("random(%d)", 10), func(b *testing.B) {
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ copy(aux, a)
+ benchResult = Sleep(aux)
+ }
+ })
+}
+
+func BenchmarkInsertionSort(b *testing.B) {
for i := minLength; i <= maxSlowLength; i *= factor {
benchmark(Insertion[int], i, b)
}
@@ -157,7 +178,7 @@ func test[V ds.Number](sort sortAlgorithm[V], l int, t *testing.T) {
t.Run(fmt.Sprintf("%d", l), cb)
}
-func testShuffle[V ds.Number](sort sortAlgorithm[V], l int, t *testing.T) {
+func testShuffleSort[V ds.Number](sort sortAlgorithm[V], l int, t *testing.T) {
cb := func(t *testing.T) {
t.Parallel()
a := sort(ds.NewAscendingArrayList[V](l))