File: porterstemmer_step2_test.go

package info (click to toggle)
golang-github-blevesearch-go-porterstemmer 1.0.1%2Bgit20141230.9.23a2c8e-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 188 kB
  • sloc: makefile: 2
file content (132 lines) | stat: -rw-r--r-- 2,619 bytes parent folder | download | duplicates (3)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package porterstemmer

import (
	"testing"
)

func TestStep2(t *testing.T) {

	i := 0

	tests := make([]struct {
		S        []rune
		Expected []rune
	}, 22)

	tests[i].S = []rune("relational")
	tests[i].Expected = []rune("relate")
	i++

	tests[i].S = []rune("conditional")
	tests[i].Expected = []rune("condition")
	i++

	tests[i].S = []rune("rational")
	tests[i].Expected = []rune("rational")
	i++

	tests[i].S = []rune("valenci")
	tests[i].Expected = []rune("valence")
	i++

	tests[i].S = []rune("hesitanci")
	tests[i].Expected = []rune("hesitance")
	i++

	tests[i].S = []rune("digitizer")
	tests[i].Expected = []rune("digitize")
	i++

	tests[i].S = []rune("conformabli")
	tests[i].Expected = []rune("conformable")
	i++

	tests[i].S = []rune("radicalli")
	tests[i].Expected = []rune("radical")
	i++

	tests[i].S = []rune("differentli")
	tests[i].Expected = []rune("different")
	i++

	tests[i].S = []rune("vileli")
	tests[i].Expected = []rune("vile")
	i++

	tests[i].S = []rune("analogousli")
	tests[i].Expected = []rune("analogous")
	i++

	tests[i].S = []rune("vietnamization")
	tests[i].Expected = []rune("vietnamize")
	i++

	tests[i].S = []rune("predication")
	tests[i].Expected = []rune("predicate")
	i++

	tests[i].S = []rune("operator")
	tests[i].Expected = []rune("operate")
	i++

	tests[i].S = []rune("feudalism")
	tests[i].Expected = []rune("feudal")
	i++

	tests[i].S = []rune("decisiveness")
	tests[i].Expected = []rune("decisive")
	i++

	tests[i].S = []rune("hopefulness")
	tests[i].Expected = []rune("hopeful")
	i++

	tests[i].S = []rune("callousness")
	tests[i].Expected = []rune("callous")
	i++

	tests[i].S = []rune("formaliti")
	tests[i].Expected = []rune("formal")
	i++

	tests[i].S = []rune("sensitiviti")
	tests[i].Expected = []rune("sensitive")
	i++

	tests[i].S = []rune("sensibiliti")
	tests[i].Expected = []rune("sensible")
	i++

	for _, datum := range tests {

		actual := make([]rune, len(datum.S))
		copy(actual, datum.S)

		actual = step2(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 step2() on [%s]. Expect [%s] but got [%s]", string(datum.S), string(datum.Expected), string(actual))
		}
	}
}