File: porterstemmer_step4_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 (124 lines) | stat: -rw-r--r-- 2,408 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
package porterstemmer

import (
	"testing"
)

func TestStep4(t *testing.T) {

	i := 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	for _, datum := range tests {

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

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