-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquicksort_test.go
108 lines (99 loc) · 2.22 KB
/
quicksort_test.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package isort
import (
"fmt"
"math/rand"
"testing"
"time"
assert "github.com/stretchr/testify/assert"
)
func TestSimpleQuickSortNonRecursive(t *testing.T) {
N := 10240000
arr := make([]int, N, N)
r := 10 * N
for i := 0; i < N; i++ {
arr[i] = rand.Intn(r)
}
n := time.Now()
SimpleSort(arr, false, false)
fmt.Print("SimpleQuickSortNonRecursive: ")
fmt.Println(time.Now().Sub(n))
assert.Equal(t, true, IsSorted(arr))
}
func TestSimpleQuickSortRecursive(t *testing.T) {
N := 10240000
arr := make([]int, N, N)
r := 10 * N
for i := 0; i < N; i++ {
arr[i] = rand.Intn(r)
}
n := time.Now()
SimpleSort(arr, true, false)
fmt.Print("SimpleQuickSortRecursive: ")
fmt.Println(time.Now().Sub(n))
assert.Equal(t, true, IsSorted(arr))
}
func TestSimpleQuickSortParallelRecursive(t *testing.T) {
N := 10240000
arr := make([]int, N, N)
r := 10 * N
for i := 0; i < N; i++ {
arr[i] = rand.Intn(r)
}
n := time.Now()
SimpleSort(arr, true, true)
fmt.Print("SimpleQuickSortParallelRecursive: ")
fmt.Println(time.Now().Sub(n))
assert.Equal(t, true, IsSorted(arr))
}
func TestTriWayQuickSort(t *testing.T) {
Debug = false
N := 10240000
arr := make([]int, N, N)
r := 10 * N
for i := 0; i < N; i++ {
arr[i] = rand.Intn(r)
}
//fmt.Println(arr)
n := time.Now()
quickSort3Way(arr, 0, len(arr)-1)
fmt.Print("3 Way-QuickSort: ")
fmt.Println(time.Now().Sub(n))
//fmt.Println(arr)
assert.Equal(t, true, IsSorted(arr))
}
func TestDualPivotQuickSort(t *testing.T) {
N := 10240000
//arr1 := make([]int, N, N)
arr2 := make([]int, N, N)
r := 10 * N
for i := 0; i < N; i++ {
x := rand.Intn(r)
//arr1[i] = x
arr2[i] = x
}
//fmt.Println(arr2)
n := time.Now()
dualPivotQuickSort(arr2, 0, len(arr2)-1, 3)
fmt.Print("Dual Pivot QuickSort: ")
fmt.Println(time.Now().Sub(n))
//fmt.Println(arr2)
assert.Equal(t, true, IsSorted(arr2))
//assert.Equal(t, true, IsSameElements(arr1,arr2))
}
func TestSortIntSlice(t *testing.T) {
g = true
N := 1024000
arr := make([]int, N, N)
r := 10 * N
for i := 0; i < N; i++ {
arr[i] = rand.Intn(r)
}
a := IntSlice(arr[0:])
//fmt.Println(a)
n := time.Now()
Sort(a)
fmt.Print("General 4-Way QuickSort: ")
fmt.Println(time.Now().Sub(n))
//fmt.Println(a)
assert.Equal(t, true, IsSorted(a))
}