-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgolem_test.go
62 lines (55 loc) · 1.21 KB
/
golem_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
package golem
import (
"strings"
"testing"
)
//TestDict is a pretend LanguagePack for testing purposes
type TestDict struct {
}
//GetResource shows the expected dictionary format.
// 1 line per base form, with additional forms to the right. Tab separated
func (t *TestDict) GetResource() ([]byte, error) {
return []byte(`word wordy wordis wordlike
thing thingy thingies thingimagics`), nil
}
func (t *TestDict) GetLocale() string {
return "test"
}
func TestTestDict(t *testing.T) {
dict := &TestDict{}
lem, err := New(dict)
if err != nil {
t.Fatal(err)
}
b, _ := dict.GetResource()
for _, line := range strings.Split(string(b), "\n") {
words := strings.Split(line, "\t")
base := words[0]
for _, word := range words {
lemma := lem.Lemma(word)
if lemma != base {
t.Errorf("Expected %v, but got %v for %v", base, lemma, word)
}
}
}
}
func BenchmarkLookup(b *testing.B) {
l, err := New(&TestDict{})
if err != nil {
b.Error(err)
}
b.ResetTimer()
for i := 0; i < b.N/2; i++ {
l.Lemma("Thingimagics")
}
}
func BenchmarkLookupLower(b *testing.B) {
l, err := New(&TestDict{})
if err != nil {
b.Error(err)
}
b.ResetTimer()
for i := 0; i < b.N/2; i++ {
l.LemmaLower("thingimagics")
}
}