-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotama_test.go
111 lines (92 loc) · 2.3 KB
/
otama_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
109
110
111
package otama
import (
"bytes"
"fmt"
"os"
"regexp"
"testing"
"path/filepath"
)
func setup() (*Otama) {
os.Mkdir("examples/data", 0755)
os.Chdir("examples")
return new(Otama)
}
func TestLibOtamaVersion(t *testing.T) {
r, _ := regexp.Compile("([0-9]+).([0-9]+)*([0-9]+)")
if r.MatchString(LIBOTAMA_VERSION) != true {
t.Errorf("fail")
}
}
func TestOtamaOpen(t *testing.T) {
o := setup()
o.Open("test.conf")
}
func TestOtamaClose(t *testing.T) {
o := setup()
o.Open("test.conf")
o.Close()
}
func TestOtamaCreateDatabase(t *testing.T) {
o := setup()
o.Open("test.conf")
o.CreateDatabase()
}
func TestOtamaDropDatabase(t *testing.T) {
o := setup()
o.Open("test.conf")
o.CreateDatabase()
o.DropDatabase()
}
func create_dataset(t *testing.T, o *Otama, pwd string) (ids []map[string]string) {
buf := bytes.NewBufferString(pwd)
buf.WriteString("/image")
// create database
filepath.Walk(buf.String(), func (path string, info os.FileInfo, err error) error {
if info == nil || info.IsDir() {
return nil
}
id, err := o.Insert(path)
if err != nil {
t.Error(err)
}
ids = append(ids, map[string]string{"id": id, "filename": path})
return nil
})
err := o.Pull()
if err != nil {
t.Error(err)
return nil
}
return ids
}
func TestOtamaInsertAndSearch(t *testing.T) {
o := setup()
o.Open("test.conf")
o.CreateDatabase()
pwd, _ := os.Getwd()
var _ []map[string]string = create_dataset(t, o, pwd)
buf := bytes.NewBufferString(pwd)
buf.WriteString("/image/lena.jpg")
results, err := o.Search(10, buf.String())
if err != nil {
t.Error(err)
}
if len(results) == 0 {
t.Errorf("result not found")
}
for result := range results {
fmt.Println(fmt.Sprintf("key=%s, sim=%0.3f", results[result].Id, results[result].Similarity))
}
}
func TestOtamaExists(t *testing.T) {
o := setup()
o.Open("test.conf")
o.CreateDatabase()
pwd, _ := os.Getwd()
var _ []map[string]string = create_dataset(t, o, pwd)
ret, _ := o.Exists("3444d453367af67e18dd20f99cdb4d90397a1fa9") // lena.jpg
if ret != true {
t.Errorf("not exist")
}
}