1package porterstemmer
2
3
4
5import (
6    "testing"
7)
8
9
10
11func TestStep4(t *testing.T) {
12
13	i := 0
14
15	tests := make([]struct {
16		S []rune
17		Expected []rune
18	}, 20)
19
20
21	tests[i].S        = []rune("revival")
22	tests[i].Expected = []rune("reviv")
23	i++
24
25	tests[i].S        = []rune("allowance")
26	tests[i].Expected = []rune("allow")
27	i++
28
29	tests[i].S        = []rune("inference")
30	tests[i].Expected = []rune("infer")
31	i++
32
33	tests[i].S        = []rune("airliner")
34	tests[i].Expected = []rune("airlin")
35	i++
36
37	tests[i].S        = []rune("gyroscopic")
38	tests[i].Expected = []rune("gyroscop")
39	i++
40
41	tests[i].S        = []rune("adjustable")
42	tests[i].Expected = []rune("adjust")
43	i++
44
45	tests[i].S        = []rune("defensible")
46	tests[i].Expected = []rune("defens")
47	i++
48
49	tests[i].S        = []rune("irritant")
50	tests[i].Expected = []rune("irrit")
51	i++
52
53	tests[i].S        = []rune("replacement")
54	tests[i].Expected = []rune("replac")
55	i++
56
57	tests[i].S        = []rune("adjustment")
58	tests[i].Expected = []rune("adjust")
59	i++
60
61	tests[i].S        = []rune("dependent")
62	tests[i].Expected = []rune("depend")
63	i++
64
65	tests[i].S        = []rune("adoption")
66	tests[i].Expected = []rune("adopt")
67	i++
68
69	tests[i].S        = []rune("homologou")
70	tests[i].Expected = []rune("homolog")
71	i++
72
73	tests[i].S        = []rune("communism")
74	tests[i].Expected = []rune("commun")
75	i++
76
77	tests[i].S        = []rune("activate")
78	tests[i].Expected = []rune("activ")
79	i++
80
81	tests[i].S        = []rune("angulariti")
82	tests[i].Expected = []rune("angular")
83	i++
84
85	tests[i].S        = []rune("homologous")
86	tests[i].Expected = []rune("homolog")
87	i++
88
89	tests[i].S        = []rune("effective")
90	tests[i].Expected = []rune("effect")
91	i++
92
93	tests[i].S        = []rune("bowdlerize")
94	tests[i].Expected = []rune("bowdler")
95	i++
96
97
98	for _,datum := range tests {
99
100		actual := make([]rune, len(datum.S))
101		copy(actual, datum.S)
102
103		actual = step4(actual)
104
105		lenActual   := len(actual)
106		lenExpected := len(datum.Expected)
107
108		equal := true
109		if 0 == lenActual && 0 == lenExpected {
110			equal = true
111		} else if lenActual != lenExpected {
112			equal = false
113		} else if actual[0] != datum.Expected[0]  {
114			equal = false
115		} else if actual[lenActual-1] != datum.Expected[lenExpected-1]  {
116			equal = false
117		} else {
118			for j := 0 ; j < lenActual ; j++ {
119
120				if actual[j] != datum.Expected[j]  {
121					equal = false
122				}
123			}
124		}
125
126		if !equal {
127			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))
128		}
129	}
130}
131