-
Notifications
You must be signed in to change notification settings - Fork 1
/
gosax_test.go
95 lines (81 loc) · 2.32 KB
/
gosax_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
package gosax
import (
"testing"
"math/rand"
)
func TestToLetterRep(t *testing.T) {
arr := []float64{7, 1, 4, 4, 4, 4}
self, _ := NewSax(6, 5, 1e-6)
letters, _ := self.ToLetterRepresentation(arr)
if letters != "eacccc" {
panic("hi")
}
}
func TestToLetterRepWindow(t *testing.T) {
arr := []float64{}
for i := 0; i < 1000; i++ {
arr = append(arr, rand.Float64()*300)
}
t.Log("Array: %v", arr)
for ws := 1; ws < 20; ws ++ {
for i := 3; i < 20; i++ {
self, err := NewSax(ws, i, 1e-6)
if err != nil {
panic(err)
}
//self.set_window_size(i)
letters, _ := self.ToLetterRepresentation(arr)
t.Logf("Letters [%v][%d]: %v", ws, i, letters)
}
}
}
func TestSlidingWindow(t *testing.T) {
arr := []float64{1, 9, 4, 7, 3, 6, 1, 11, 4, 15, 23, 7, 3, 1, 11, 4, 15, 23, 7, 6, 10, 100}
for ws := 1; ws < 20; ws ++ {
for i := 3; i < 20; i++ {
self, err := NewSax(ws, i, 1e-6)
if err != nil {
panic(err)
}
//self.set_window_size(i)
letters, _, _ := self.SlidingWindow(arr, 4, 0.2)
t.Logf("Letters [%v][%d]: %v", ws, i, letters)
}
}
}
func TestLongToLetterRep(t *testing.T) {
long_arr := []float64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, 10, 100}
self, _ := NewSax(6, 5, 1e-6)
letters, _ := self.ToLetterRepresentation(long_arr)
t.Logf("%v == bbbbce", letters)
if letters != "bbbbce" {
panic("2")
}
}
func BenchmarkLongToLetterRep(b *testing.B) {
long_arr := []float64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, 10, 100}
self, _ := NewSax(6, 5, 1e-6)
for i := 0; i < b.N; i++ {
self.ToLetterRepresentation(long_arr)
}
}
func BenchmarkSlidingWindow(b *testing.B) {
long_arr := []float64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, 10, 100}
self, _ := NewSax(6, 5, 1e-6)
for i := 0; i < b.N; i++ {
self.SlidingWindow(long_arr, 4, 0.4)
}
}
func TestCompareStrings(t *testing.T) {
self, _ := NewSax(6, 5, 1e-6)
base_string := "aaabbc"
similar_string := "aabbbc"
dissimilar_string := "ccddbc"
similar_score, _ := self.CompareStrings([]byte(base_string), []byte(similar_string))
dissimilar_score, _ := self.CompareStrings([]byte(base_string), []byte(dissimilar_string))
t.Logf("Similarity score: %v", similar_score)
t.Logf("DisSimilarity score: %v", dissimilar_score)
if similar_score >= dissimilar_score {
panic("3")
}
}