GPT-OSS 120B × go-test
8.7Idiomatic Go table-driven tests + benchmark
correctness 9.0quality 8.0documentation 9.01740ms
$ cat go-test.prompt — what the model was asked
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
run 1 of 1
8.7correctness 9.0quality 8.0documentation 9.01740ms
# judge: Test cases are logically correct (verified word counts, case-insensitivity, punctuation stripping) and use reflect.DeepEqual properly, but the map literal isn't gofmt-aligned, an unnecessary b.ResetTimer() is added with no setup work, and a non-standard unicode hyphen appears in a test name.
$ cat gpt-oss-120b.go-test.r1.response
**`wordcount_test.go`**
```go
package wordcount
import (
"reflect"
"testing"
)
// TestWordCount verifies the behaviour of WordCount using a table‑driven approach.
func TestWordCount(t *testing.T) {
tests := []struct {
name string
input string
want map[string]int
}{
{
name: "empty string",
input: "",
want: map[string]int{},
},
{
name: "single word",
input: "gopher",
want: map[string]int{"gopher": 1},
},
{
name: "mixed case",
input: "Go gO GO go",
want: map[string]int{"go": 4},
},
{
name: "punctuation stripped",
input: "Hello, world! Hello... world?",
want: map[string]int{"hello": 2, "world": 2},
},
{
name: "repeated words",
input: "test test TEST Test tESt",
want: map[string]int{"test": 5},
},
{
name: "multi‑word sentence",
input: "The quick brown fox jumps over the lazy dog. The dog barked.",
want: map[string]int{
"the": 3,
"quick": 1,
"brown": 1,
"fox": 1,
"jumps": 1,
"over": 1,
"lazy": 1,
"dog": 2,
"barked": 1,
},
},
}
for _, tc := range tests {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
got := WordCount(tc.input)
if !reflect.DeepEqual(got, tc.want) {
t.Fatalf("WordCount(%q) = %v, want %v", tc.input, got, tc.want)
}
})
}
}
// BenchmarkWordCount measures the performance of WordCount on a realistic
// paragraph. The benchmark input is kept constant across iterations.
func BenchmarkWordCount(b *testing.B) {
const sentence = `Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.`
// Reset the timer so that only the WordCount call is measured.
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = WordCount(sentence)
}
}
```