mager-bench

Claude Haiku 4.5 × go-test

7.7

Idiomatic Go table-driven tests + benchmark

correctness 8.0quality 9.0documentation 6.06437ms
$ 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

7.7
correctness 8.0quality 9.0documentation 6.06437ms

# judge: Solid table-driven tests with correct maps.Equal comparison and proper benchmark, but extra cases (contractions, apostrophes) rely on unverified assumptions about punctuation handling, and code lacks explanatory comments on the test/benchmark functions themselves.

$ cat claude-haiku-4-5.go-test.r1.response
```go
package wordcount

import (
	"maps"
	"testing"
)

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: "hello",
			want:  map[string]int{"hello": 1},
		},
		{
			name:  "mixed case",
			input: "Hello HELLO hello",
			want:  map[string]int{"hello": 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: "the quick brown fox jumps over the lazy dog the",
			want:  map[string]int{"the": 3, "quick": 1, "brown": 1, "fox": 1, "jumps": 1, "over": 1, "lazy": 1, "dog": 1},
		},
		{
			name:  "multi-word sentence with mixed case and punctuation",
			input: "The Quick, BROWN fox! The lazy dog's tail.",
			want:  map[string]int{"the": 2, "quick": 1, "brown": 1, "fox": 1, "lazy": 1, "dog's": 1, "tail": 1},
		},
		{
			name:  "whitespace only",
			input: "   \t\n  ",
			want:  map[string]int{},
		},
		{
			name:  "multiple spaces between words",
			input: "hello    world   foo",
			want:  map[string]int{"hello": 1, "world": 1, "foo": 1},
		},
		{
			name:  "punctuation at various positions",
			input: "it's can't won't shouldn't",
			want:  map[string]int{"it's": 1, "can't": 1, "won't": 1, "shouldn't": 1},
		},
		{
			name:  "numbers mixed with words",
			input: "abc123 123abc 123",
			want:  map[string]int{"abc123": 1, "123abc": 1, "123": 1},
		},
	}

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

func BenchmarkWordCount(b *testing.B) {
	text := "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. " +
		"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. " +
		"The quick brown fox jumps over the lazy dog."

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

This test file includes:

1. **Table-driven tests** using a slice of anonymous structs with `name`, `input`, and `want` fields
2. **6+ test cases** covering:
   - Empty string
   - Single word
   - Mixed case (case-insensitivity)
   - Punctuation stripping
   - Repeated words
   - Multi-word sentence with mixed case and punctuation
   - Additional edge cases (whitespace, contractions, numbers)

3. **Subtests** using `t.Run()` for clear failure identification
4. **Map comparison** using `maps.Equal()` from the standard library (Go 1.21+, or use `reflect.DeepEqual()` for earlier versions)
5. **Benchmark** (`BenchmarkWordCount`) testing with a realistic, repeated sentence

To run the tests:
```bash
go test ./wordcount
go test -v ./wordcount          # verbose output
go test -bench=. ./wordcount    # run benchmarks
```