Skip to content

Commit 0fe8e40

Browse files
committed
test lookup functions, removed testing library
1 parent 52d20ab commit 0fe8e40

File tree

5 files changed

+112
-9
lines changed

5 files changed

+112
-9
lines changed

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module github.com/antonbaumann/german-go-stemmer
22

33
go 1.13
4-
5-
require github.com/stretchr/testify v1.3.0
File renamed without changes.

internal/lookup/lookup_test.go

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package lookup
2+
3+
import "testing"
4+
5+
func TestIsVowelPositive(t *testing.T) {
6+
vowels := "aeiouyAOV"
7+
for _, v := range vowels {
8+
if !IsVowel(uint8(v)) {
9+
t.Errorf("`%c` should be a vowel", v)
10+
}
11+
}
12+
}
13+
14+
func TestIsVowelNegative(t *testing.T) {
15+
consonants := "bcdfghjklmnpqrstvwxz"
16+
for _, v := range consonants {
17+
if IsVowel(uint8(v)) {
18+
t.Errorf("`%c` should not be a vowel", v)
19+
}
20+
}
21+
}
22+
23+
func TestIsStopWordPositive(t *testing.T) {
24+
stopWords := []string {
25+
"damit", "dann", "der", "derselbe", "manche",
26+
}
27+
for _, word := range stopWords {
28+
if !IsStopWord(word) {
29+
t.Errorf("`%s` should be a stop word", word)
30+
}
31+
}
32+
}
33+
34+
func TestIsStopWordNegative(t *testing.T) {
35+
stopWords := []string {
36+
"weithin", "wachsam", "umfassender",
37+
}
38+
for _, word := range stopWords {
39+
if IsStopWord(word) {
40+
t.Errorf("`%s` should not be a stop word", word)
41+
}
42+
}
43+
}
44+
45+
func TestIsSEndingPositive(t *testing.T) {
46+
sEndings := "bdfghklmnrt"
47+
for _, v := range sEndings {
48+
if !IsSEnding(uint8(v)) {
49+
t.Errorf("`%c` should be a s-ending", v)
50+
}
51+
}
52+
}
53+
54+
func TestIsSEndingNegative(t *testing.T) {
55+
sEndings := "aceijopqsuvwxyz"
56+
for _, v := range sEndings {
57+
if IsSEnding(uint8(v)) {
58+
t.Errorf("`%c` should not be a s-ending", v)
59+
}
60+
}
61+
}
62+
63+
func TestIsStEndingPositive(t *testing.T) {
64+
sEndings := "bdfghklmnt"
65+
for _, v := range sEndings {
66+
if !IsStEnding(uint8(v)) {
67+
t.Errorf("`%c` should be a st-ending", v)
68+
}
69+
}
70+
}
71+
72+
func TestIsStEndingNegative(t *testing.T) {
73+
sEndings := "aceijopqrsuvwxyz"
74+
for _, v := range sEndings {
75+
if IsStEnding(uint8(v)) {
76+
t.Errorf("`%c` should not be a s-ending", v)
77+
}
78+
}
79+
}

stemmer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package stemmer
22

33
import (
4-
"github.com/antonbaumann/german-go-stemmer/lookup"
4+
"github.com/antonbaumann/german-go-stemmer/internal/lookup"
55
"regexp"
66
"strings"
77
)

stemmer_test.go

+32-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package stemmer
22

33
import (
44
"bufio"
5-
"github.com/stretchr/testify/assert"
65
"os"
6+
"strings"
77
"testing"
88
)
99

@@ -14,8 +14,12 @@ type testSet struct {
1414

1515
func TestStemQuery(t *testing.T) {
1616
query := "wie wird das wetter \t morgen in \nmünchen"
17+
expected := "wett morg munch"
1718
result := Stem(query)
18-
assert.Equal(t, "wett morg munch", result)
19+
20+
if !strings.EqualFold(expected, result) {
21+
t.Errorf("test failed.\nexpected:\t %v\ngot:\t\t %v", expected, result)
22+
}
1923
}
2024

2125
func TestStemWords(t *testing.T) {
@@ -36,7 +40,11 @@ func TestStemWords(t *testing.T) {
3640
t.Fail()
3741
}
3842

39-
assert.Equal(t, expected, StemWords(words))
43+
result := StemWords(words)
44+
45+
if !slicesEqual(expected, result) {
46+
t.Errorf("test failed.\nexpected:\t %v\ngot:\t\t %v", expected, result)
47+
}
4048
}
4149

4250
func TestStemWord(t *testing.T) {
@@ -64,7 +72,9 @@ func TestStemWord(t *testing.T) {
6472

6573
for _, test := range tests {
6674
result := stem(test.value)
67-
assert.Equal(t, test.expected, result)
75+
if !strings.EqualFold(test.expected, result) {
76+
t.Errorf("test failed.\nexpected:\t %v\ngot:\t\t %v", test.expected, result)
77+
}
6878
}
6979
}
7080

@@ -78,7 +88,9 @@ func TestStep1(t *testing.T) {
7888
for _, test := range tests {
7989
r1, _ := getRegions(test.value)
8090
result := step1(test.value, r1)
81-
assert.Equal(t, test.expected, result)
91+
if !strings.EqualFold(test.expected, result) {
92+
t.Errorf("test failed.\nexpected:\t %v\ngot:\t\t %v", test.expected, result)
93+
}
8294
}
8395
}
8496

@@ -89,7 +101,9 @@ func TestStep2(t *testing.T) {
89101
for _, test := range tests {
90102
r1, _ := getRegions(test.value)
91103
result := step2(test.value, r1)
92-
assert.Equal(t, test.expected, result)
104+
if !strings.EqualFold(test.expected, result) {
105+
t.Errorf("test failed.\nexpected:\t %v\ngot:\t\t %v", test.expected, result)
106+
}
93107
}
94108
}
95109

@@ -109,3 +123,15 @@ func readWordList(filePath string) ([]string, error) {
109123

110124
return words, nil
111125
}
126+
127+
func slicesEqual(a, b []string) bool {
128+
if len(a) != len(b) {
129+
return false
130+
}
131+
for i, v := range a {
132+
if !strings.EqualFold(v, b[i]) {
133+
return false
134+
}
135+
}
136+
return true
137+
}

0 commit comments

Comments
 (0)