Why is one test failing?

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 http://snowball.tartarus.org/algorithms/danish/stemmer.html

Here is my test

Here is the implementation

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?

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.