Golang Excercise No:60, "Word Count" has bug

Even the latest correct code (from 1y back, saying passed latest test) is not passing in my current online editor. I raised a issue from editor, but didn’t receive any update.
Error Prints : "

# wordcount [wordcount.test]
./word_count_test.go:15:18: tt.output undefined (type struct{description string; input string; expected Frequency} has no field or method output)
FAIL	wordcount [build failed]
'/usr/local/go/bin/go test --short --json .' returned exit code 1: exit status 1

"

the code thats commented is what I wrote (still learning pls don’t judge :grimacing:)
the one that on top not commented is community recommended latest correct answer which doesn’t pass.

package wordcount

import (
	"regexp"
	"strings"
)

type Frequency map[string]int

func WordCount(phrase string) Frequency {
	re := regexp.MustCompile(`\w+('\w+)?`)
	count := make(Frequency)
	for _, w := range re.FindAllString(strings.ToLower(phrase), -1) {
		count[w]++
	}
	return count
}
// import "unicode"
    
// type Frequency map[string]int

// func WordCount(phrase string) Frequency {
//     currW := ""
//     isInsideWrd := false
//     words := make(Frequency)
// 	for _, c:= range phrase{
//         if unicode.IsLetter(c) || unicode.IsDigit(c){
//             isInsideWrd = true
//             currW += string(unicode.ToLower(c))
//         }else if c == '\u0027' && isInsideWrd{
//         	currW += string(c)
//         }else if isInsideWrd{
//             isInsideWrd = false
//             words[currW]++
//             currW = ""
//         }
//     }
// 	if isInsideWrd{
//         words[currW]++
//     }
// 	return words 
// }

If the test cases are correct and not buggy, please guide me why neither the recommended code nor my kind-of right code didn’t work. NB: my code did work in Golang playground too, although I had to make some changes to make it work without test cases.

That’s strange. I just copied the solution from your comment:

package wordcount

import (
	"regexp"
	"strings"
)

type Frequency map[string]int

func WordCount(phrase string) Frequency {
	re := regexp.MustCompile(`\w+('\w+)?`)
	count := make(Frequency)
	for _, w := range re.FindAllString(strings.ToLower(phrase), -1) {
		count[w]++
	}
	return count
}

and it does pass all 14 tests.

Could you please check one thing? If you go to https://exercism.org/tracks/go/exercises/word-count, is there a banner at the top of the page with a text “This exercise has been updated.”? If yes, please click it, update the exercise, and submit your solution again.

1 Like

I feel dumb for not knowing that I have to click it to update… :man_facepalming:t4:

Thank you guys for the support :innocent: