1package porterstemmer
2
3
4
5import (
6    "testing"
7)
8
9
10
11func TestStep3(t *testing.T) {
12
13	i := 0
14
15	tests := make([]struct {
16		S []rune
17		Expected []rune
18	}, 22)
19
20
21	tests[i].S        = []rune("triplicate")
22	tests[i].Expected = []rune("triplic")
23	i++
24
25	tests[i].S        = []rune("formative")
26	tests[i].Expected = []rune("form")
27	i++
28
29	tests[i].S        = []rune("formalize")
30	tests[i].Expected = []rune("formal")
31	i++
32
33	tests[i].S        = []rune("electriciti")
34	tests[i].Expected = []rune("electric")
35	i++
36
37	tests[i].S        = []rune("electrical")
38	tests[i].Expected = []rune("electric")
39	i++
40
41	tests[i].S        = []rune("hopeful")
42	tests[i].Expected = []rune("hope")
43	i++
44
45	tests[i].S        = []rune("goodness")
46	tests[i].Expected = []rune("good")
47	i++
48
49
50	for _,datum := range tests {
51
52		actual := make([]rune, len(datum.S))
53		copy(actual, datum.S)
54
55		actual = step3(actual)
56
57		lenActual   := len(actual)
58		lenExpected := len(datum.Expected)
59
60		equal := true
61		if 0 == lenActual && 0 == lenExpected {
62			equal = true
63		} else if lenActual != lenExpected {
64			equal = false
65		} else if actual[0] != datum.Expected[0]  {
66			equal = false
67		} else if actual[lenActual-1] != datum.Expected[lenExpected-1]  {
68			equal = false
69		} else {
70			for j := 0 ; j < lenActual ; j++ {
71
72				if actual[j] != datum.Expected[j]  {
73					equal = false
74				}
75			}
76		}
77
78		if !equal {
79			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))
80		}
81	}
82}
83