mager-bench
← all challenges

go-test

Write idiomatic Go table-driven tests — tests knowledge of Go testing conventions

the prompt

$ cat go-test.prompt
Write a Go test file for the following function:

```go
// WordCount returns a map of each unique word in s to the number
// of times it appears. Words are case-insensitive and separated by
// whitespace. Punctuation attached to words is stripped.
func WordCount(s string) map[string]int
```

Requirements:
- Package: `wordcount` (test file: `wordcount_test.go`)
- Use Go's standard `testing` package — no third-party libraries
- Use a table-driven test with a `[]struct{ name, input string; want map[string]int }` slice
- Include at least 6 test cases: empty string, single word, mixed case, punctuation, repeated words, multi-word sentence
- Use `t.Run(tc.name, ...)` for subtests so failures are identifiable
- Use `reflect.DeepEqual` or `maps.Equal` to compare maps
- Add a benchmark `BenchmarkWordCount` that runs on a realistic sentence

rubric

correctness

Do the 6+ test cases cover empty input, case-insensitivity, punctuation stripping, and repeated words with correct expected counts? Is the map comparison correct (not == on maps)? Does the benchmark compile and follow Go benchmark conventions (b.N loop)?

quality

Is the table-driven pattern used correctly (slice of structs, not parallel variables)? Are subtests used with t.Run? Is the test file in the right package (wordcount or wordcount_test)? Is the code idiomatic Go (no unnecessary imports, proper error handling)?

documentation

Are test case names descriptive ('empty string', 'mixed case punctuation')? Is there a comment on the test function explaining what it covers? Is the benchmark named and commented correctly?

results

Claude Haiku 4.5

7.7
correctness 8.0quality 9.0documentation 6.07056ms

# Comprehensive table-driven tests with correct map comparison via maps.Equal and a proper benchmark loop, but lacks a doc comment on TestWordCount and makes some debatable assumptions about punctuation/apostrophe handling.

inspect full trace →

Claude Sonnet 4.6

5.3
correctness 4.0quality 5.0documentation 7.018838ms

# Test cases and benchmark are well-designed and exceed the requirement, but the file incorrectly declares package wordcount_test and reimplements a stub WordCount that always returns nil, meaning the delivered file will fail most subtests unless manually edited to remove the stub and fix the package, contradicting the stated 'package: wordcount' requirement.

inspect full trace →

Llama 3.3 70B

4.7
correctness 3.0quality 6.0documentation 5.01397ms

# Test logic and case coverage are solid and benchmark is correct, but the code contains a fatal compile error (`t *test.T` instead of `*testing.T`) that would prevent the file from building; also lacks a dedicated comment on TestWordCount explaining its coverage.

inspect full trace →

Gemini 2.5 Flash

3.3
correctness 2.0quality 3.0documentation 5.021503ms

# The test file will not compile because 'reflect' is imported but never actually referenced (only mentioned in a comment), causing a Go compile error; additionally the apostrophe-handling test case ('It's') mismatches the model's own regex-based implementation output, meaning even after fixing the import the test would fail — despite good table-driven structure, many descriptive test names, and a solid benchmark.

inspect full trace →