-
Notifications
You must be signed in to change notification settings - Fork 0
/
function_test.go
73 lines (59 loc) · 1.37 KB
/
function_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
package algorithms
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestMakeArray(t *testing.T) {
n := 10
nm := MakeArray(n)
assert.Equal(t, n, len(nm))
}
func TestRandomFillArray(t *testing.T) {
value := false
nm := MakeArray(10)
RandomFillArray(nm, 100)
if nm[0] != nm[1] {
value = true
}
assert.True(t, value)
}
func TestBinarySearch(t *testing.T) {
index := 3
value := 555
arr := RandomFillArray(MakeArray(100), 100)
arr[index] = value
position := BinarySearch(arr, value)
assert.Equal(t, value, arr[position])
}
func TestFact(t *testing.T) {
assert.Equal(t, 5040, Fact(7))
}
func TestMinMax(t *testing.T) {
aaa := []float64{4.0, 34, -28883, 25, 32, 324, -23, 2, -333, 0, 99, 88888}
min, max := MinMax(aaa)
assert.Equal(t, min, aaa[2])
assert.Equal(t, max, aaa[11])
}
func TestSelectorSort(t *testing.T) {
a := []int{13, 45, 889, 98, 56, 78, 8}
sortArray := []int{8, 13, 45, 56, 78, 98, 889}
resultArray := SelectorSort(a)
assert.Equal(t, sortArray, resultArray)
}
func TestRecursive(t *testing.T) {
assert.Equal(t, 0, Recursive(10))
}
func TestQuickSort(t *testing.T) {
a := []int{13, 45, 889, 98, 56, 78, 8}
sortArray := []int{8, 13, 45, 56, 78, 98, 889}
resultArray := QuickSort(a)
assert.Equal(t, sortArray, resultArray)
}
func BenchmarkDecode(b *testing.B) {
var x int
for i := 0; i < b.N; i++ {
x = i
}
fmt.Println(x)
}