mager-bench

Llama 3.3 70B × go-test

4.7

Idiomatic Go table-driven tests + benchmark

correctness 3.0quality 6.0documentation 5.01397ms
$ 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

4.7
correctness 3.0quality 6.0documentation 5.01397ms

# judge: 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.

$ cat llama-3.3-70b.go-test.r1.response
Here's the test file `wordcount_test.go` that tests the `WordCount` function:

```go
// Package wordcount provides a function to count the occurrences of each unique word in a string.
package wordcount

import (
	"reflect"
	"testing"
)

func TestWordCount(t *test.T) {
	tests := []struct {
		name  string
		input string
		want  map[string]int
	}{
		{"empty string", "", map[string]int{}},
		{"single word", "hello", map[string]int{"hello": 1}},
		{"mixed case", "HelLO", map[string]int{"hello": 1}},
		{"punctuation", "hello!", map[string]int{"hello": 1}},
		{"repeated words", "hello hello", map[string]int{"hello": 2}},
		{"multi-word sentence", "hello world, hello", map[string]int{"hello": 2, "world": 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) {
	input := "this is a realistic sentence with some repeated words and punctuation, like this one."
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		WordCount(input)
	}
}
```

In this test file:

*   We define the package as `wordcount`.
*   We import the necessary packages: `reflect` and `testing`.
*   We define a test function `TestWordCount` that uses a table-driven test approach to test various cases, including empty strings, single words, mixed case, punctuation, repeated words, and multi-word sentences.
*   We use `t.Run` to run each test case as a subtest, making it easier to identify failed test cases.
*   We use `reflect.DeepEqual` to compare the expected and actual maps returned by `WordCount`.
*   We define a benchmark function `BenchmarkWordCount` to measure the performance of `WordCount` on a realistic sentence. The benchmark runs `WordCount` repeatedly on the input sentence and reports the average time taken.