-
Notifications
You must be signed in to change notification settings - Fork 45
/
porterstemmer_step3_test.go
82 lines (58 loc) · 1.49 KB
/
porterstemmer_step3_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
package porterstemmer
import (
"testing"
)
func TestStep3(t *testing.T) {
i := 0
tests := make([]struct {
S []rune
Expected []rune
}, 22)
tests[i].S = []rune("triplicate")
tests[i].Expected = []rune("triplic")
i++
tests[i].S = []rune("formative")
tests[i].Expected = []rune("form")
i++
tests[i].S = []rune("formalize")
tests[i].Expected = []rune("formal")
i++
tests[i].S = []rune("electriciti")
tests[i].Expected = []rune("electric")
i++
tests[i].S = []rune("electrical")
tests[i].Expected = []rune("electric")
i++
tests[i].S = []rune("hopeful")
tests[i].Expected = []rune("hope")
i++
tests[i].S = []rune("goodness")
tests[i].Expected = []rune("good")
i++
for _,datum := range tests {
actual := make([]rune, len(datum.S))
copy(actual, datum.S)
actual = step3(actual)
lenActual := len(actual)
lenExpected := len(datum.Expected)
equal := true
if 0 == lenActual && 0 == lenExpected {
equal = true
} else if lenActual != lenExpected {
equal = false
} else if actual[0] != datum.Expected[0] {
equal = false
} else if actual[lenActual-1] != datum.Expected[lenExpected-1] {
equal = false
} else {
for j := 0 ; j < lenActual ; j++ {
if actual[j] != datum.Expected[j] {
equal = false
}
}
}
if !equal {
t.Errorf("Did NOT get what was expected for calling step3() on [%s]. Expect [%s] but got [%s]", string(datum.S), string(datum.Expected), string(actual))
}
}
}