Skip to content
mager-bench1.3

GPT-5.6 Sol × go-test

8.7

Idiomatic Go table-driven tests + benchmark

correctness 10.0quality 10.0documentation 6.013067ms
$ 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.7
correctness 10.0quality 10.0documentation 6.013067ms

# judge: The tests and benchmark fully satisfy the functional and structural requirements with idiomatic Go, but both exported test functions lack the requested explanatory comments.

$ cat codex-cli/gpt-5.6-sol.go-test.r1.response
```go
package wordcount

import (
	"reflect"
	"testing"
)

func TestWordCount(t *testing.T) {
	tests := []struct {
		name, input string
		want        map[string]int
	}{
		{
			name:  "empty string",
			input: "",
			want:  map[string]int{},
		},
		{
			name:  "single word",
			input: "hello",
			want:  map[string]int{"hello": 1},
		},
		{
			name:  "mixed case",
			input: "Go go GO",
			want:  map[string]int{"go": 3},
		},
		{
			name:  "punctuation",
			input: "Hello, world! How are you?",
			want: map[string]int{
				"hello": 1,
				"world": 1,
				"how":   1,
				"are":   1,
				"you":   1,
			},
		},
		{
			name:  "repeated words",
			input: "one two one three two one",
			want: map[string]int{
				"one":   3,
				"two":   2,
				"three": 1,
			},
		},
		{
			name:  "multi-word sentence",
			input: "The quick brown fox jumps over the lazy dog",
			want: map[string]int{
				"the":   2,
				"quick": 1,
				"brown": 1,
				"fox":   1,
				"jumps": 1,
				"over":  1,
				"lazy":  1,
				"dog":   1,
			},
		},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			got := WordCount(tc.input)
			if !reflect.DeepEqual(got, tc.want) {
				t.Errorf("WordCount(%q) = %v; want %v", tc.input, got, tc.want)
			}
		})
	}
}

func BenchmarkWordCount(b *testing.B) {
	const input = "The quick brown fox jumps over the lazy dog, while another fox watches from the quiet forest."

	for i := 0; i < b.N; i++ {
		WordCount(input)
	}
}
```