I found the problem
TL;DR
The problem was in the order I executed the functions
Just for the fun of it, I began implementing a word stemmer based on Danish stemming algorithm
Here is my test
https://github.com/kristiannissen/sturdy-tribble/blob/main/stemmer_test.go
Here is the implementation
https://github.com/kristiannissen/sturdy-tribble/blob/main/stemmer.go
When running the test, the undouble function fails, but not constantly, only partially which I don’t get.
Example:
Got undertrykk, want undertryk, test undertrykkelse
So I added a log inside the undouble function to check if the double character is found and turned into a single character. And it does take care of all the cases
func undouble(word string) string {
chars := str.Split(word, "")
if chars[len(chars)-2] == chars[len(chars)-1] {
word = str.TrimSuffix(word, chars[len(chars)-1])
log.Println(word) // Log added
}
return word
}
Output when test is run
2021/03/18 07:00:55 indtræf
2021/03/18 07:00:55 indtræf
2021/03/18 07:00:55 undersåt
2021/03/18 07:00:55 undersåt
2021/03/18 07:00:55 undertryk
2021/03/18 07:00:55 undertryk
2021/03/18 07:00:55 undertryk
2021/03/18 07:00:55 undertryk
2021/03/18 07:00:55 undertryk
2021/03/18 07:00:55 undertryk
2021/03/18 07:00:55 undertryk
All tests are handled.
So why is my test still failing?