-
Notifications
You must be signed in to change notification settings - Fork 4
/
functional_test.go
94 lines (82 loc) · 2.31 KB
/
functional_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
package main
import (
"fmt"
"log"
"math"
"math/rand"
"sort"
"testing"
"github.com/BenJoyenConseil/rmi/index"
"github.com/BenJoyenConseil/rmi/search"
"github.com/stretchr/testify/assert"
)
func TestIsoFunctional(t *testing.T) {
// given the titanic.csv dataset
ageCol := extractColumn("./data/titanic.csv", "age")
li := index.New(ageCol)
log.Println(li.MaxErrBound, li.MinErrBound)
//ci := NewCubic(ageCol)
// when Lookup using bsearch, learnedindex, etc..
for i := 0.; i <= 100; i++ {
resultFS, errFS := search.FullScanLookup(i, li.ST)
resultLI, errLI := li.Lookup(i)
//resultCI, errCI := ci.Lookup(i)
// then forearch key result should be the same
assert.ElementsMatch(t, resultFS, resultLI, i)
//assert.ElementsMatch(t, resultBS, resultCI)
assert.Equal(t, errFS, errLI, i)
//assert.Equal(t, errBS, errCI)
}
}
var min, max = 0., 100.
var random = func() float64 { return math.Round(min + rand.Float64()*(max-min)) }
func BenchmarkLearnedIndex(b *testing.B) {
file := "./data/titanic.csv"
// load the age column and parse values into float64 values
ageColumn := extractColumn(file, "age")
// create an index over the age column
idx := index.New(ageColumn)
keyFound := map[float64][]int{}
keyNotFound := map[float64][]error{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
k := random()
offsets, err := idx.Lookup(k)
if err != nil {
keyNotFound[k] = append(keyNotFound[k], err)
} else {
keyFound[k] = offsets
}
}
log.Println("keys found:", len(keyFound), "| keys not found:", len(keyNotFound))
//log.Println(keyNotFound)
}
func BenchmarkBinarySearch(b *testing.B) {
file := "./data/titanic.csv"
// load the age column and parse values into float64 values
ageColumn := extractColumn(file, "age")
sort.Float64s(ageColumn)
keyFound := map[float64][]int{}
keyNotFound := map[float64][]error{}
b.ResetTimer()
o := 0
for i := 0; i < b.N; i++ {
k := random()
o = sort.SearchFloat64s(ageColumn, k)
if o >= len(ageColumn) {
keyNotFound[k] = append(keyNotFound[k], fmt.Errorf("%f not found", k))
} else {
offsets := []int{}
for o < len(ageColumn) {
if ageColumn[o] != k {
break
}
offsets = append(offsets, o)
o++
}
keyFound[k] = offsets
}
}
log.Println("keys found:", len(keyFound), "| keys not found:", len(keyNotFound))
//log.Println(keyNotFound)
}