mirror of
https://github.com/lukaszraczylo/llm-testbench.git
synced 2026-10-12 00:45:19 +00:00
Add 9 tests to research/web, research/whitepapers, and research/codebase, bringing each subcategory from 1 test to 10. Web tests extract data from inline HTML, headers, and URLs, and answer protocol scenarios for HTTP status codes, CORS, DNS, and canonicalization. Every fixture stays inline; no test makes a live web call. Whitepaper tests each pair a 120 to 180 word, technically accurate excerpt with numeric or JSON extraction questions. Topics cover product quantization, Bloom filters, TF-IDF, recall@k, LSM-tree write amplification, Raft quorum sizing, B-tree capacity, the CAP theorem, and attention scaling. Every derived constant carries a ground-truth comment and a unit test that recomputes the value with an independent formula. Codebase tests trace a Python function and a TypeScript function to exact output, then reason over an inline diff, a data race, dead code, Big-O complexity, an import cycle, a generic return type, and a git-bisect scenario. The Python trace test runs the same source through python3 when available and skips otherwise; the TypeScript trace test cross-checks its hand-derivation against an equivalent Go function. New package-level helpers use a wp or code prefix to avoid name collisions with sibling category authors sharing this package. Test IDs keep the paper, web, and code prefixes already established by the existing catalog entries. New tests omit MaxTokens so the runner falls back to its default, per the catalog's authoring rules. catalog_test.go's exact-map assertion now fails as expected, since it still lists only the original 17-test catalog; that assertion is owned centrally and is not touched here.
174 lines
4.8 KiB
Go
174 lines
4.8 KiB
Go
package tests
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestCodeBugLineDiffTest_Eval(t *testing.T) {
|
|
tc := codeBugLineDiffTest()
|
|
|
|
tests := []struct {
|
|
name string
|
|
response string
|
|
want float64
|
|
}{
|
|
{"correct: root-cause line", `{"line":8}`, 1},
|
|
{"wrong: points at the panic site instead of the root cause", `{"line":10}`, 0},
|
|
{"wrong line entirely", `{"line":6}`, 0},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := tc.Eval.Evaluate(context.Background(), tt.response)
|
|
if got.Value != tt.want {
|
|
t.Errorf("Eval.Evaluate(%q) = %v, want %v (detail: %s)", tt.response, got.Value, tt.want, got.Detail)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCodeRaceVariableTest_Eval(t *testing.T) {
|
|
tc := codeRaceVariableTest()
|
|
|
|
tests := []struct {
|
|
name string
|
|
response string
|
|
want float64
|
|
}{
|
|
{"correct", `{"variable":"total"}`, 1},
|
|
{"correct different case", `{"variable":"Total"}`, 1},
|
|
{"wrong: loop variable, not the shared counter", `{"variable":"i"}`, 0},
|
|
{"wrong: function parameter, not the shared counter", `{"variable":"n"}`, 0},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := tc.Eval.Evaluate(context.Background(), tt.response)
|
|
if got.Value != tt.want {
|
|
t.Errorf("Eval.Evaluate(%q) = %v, want %v (detail: %s)", tt.response, got.Value, tt.want, got.Detail)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCodeDeadFunctionsTest_Eval(t *testing.T) {
|
|
tc := codeDeadFunctionsTest()
|
|
|
|
tests := []struct {
|
|
name string
|
|
response string
|
|
want float64
|
|
}{
|
|
{"correct set", `["helperC","helperD"]`, 1},
|
|
{"correct set, different order", `["helperD","helperC"]`, 1},
|
|
{"missing one dead function", `["helperD"]`, 0.5},
|
|
{"wrongly includes a live function", `["helperC","helperD","helperB"]`, 2.0 / 3.0},
|
|
{"wrong: says nothing is dead", `[]`, 0},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := tc.Eval.Evaluate(context.Background(), tt.response)
|
|
if got.Value != tt.want {
|
|
t.Errorf("Eval.Evaluate(%q) = %v, want %v (detail: %s)", tt.response, got.Value, tt.want, got.Detail)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCodeBigODedupTest_Eval(t *testing.T) {
|
|
tc := codeBigODedupTest()
|
|
|
|
tests := []struct {
|
|
name string
|
|
response string
|
|
want float64
|
|
}{
|
|
{"caret form", "O(n^2)", 1},
|
|
{"double-star form", "O(n**2)", 1},
|
|
{"unicode superscript form", "O(n²)", 1},
|
|
{"n*n form", "O(n*n)", 1},
|
|
{"lowercase o", "o(n^2)", 1},
|
|
{"wrong: linear", "O(n)", 0},
|
|
{"wrong: linearithmic", "O(n log n)", 0},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := tc.Eval.Evaluate(context.Background(), tt.response)
|
|
if got.Value != tt.want {
|
|
t.Errorf("Eval.Evaluate(%q) = %v, want %v (detail: %s)", tt.response, got.Value, tt.want, got.Detail)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCodeImportCycleTest_Eval(t *testing.T) {
|
|
tc := codeImportCycleTest()
|
|
|
|
tests := []struct {
|
|
name string
|
|
response string
|
|
want float64
|
|
}{
|
|
{"correct set", `["a","b","c"]`, 1},
|
|
{"correct set, different order", `["c","a","b"]`, 1},
|
|
{"wrongly includes non-cyclic d", `["a","b","c","d"]`, 0.75},
|
|
{"missing one cycle member", `["a","b"]`, 2.0 / 3.0},
|
|
{"wrong: only d, which has no imports at all", `["d"]`, 0},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := tc.Eval.Evaluate(context.Background(), tt.response)
|
|
if got.Value != tt.want {
|
|
t.Errorf("Eval.Evaluate(%q) = %v, want %v (detail: %s)", tt.response, got.Value, tt.want, got.Detail)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCodeGenericReturnTypeTest_Eval(t *testing.T) {
|
|
tc := codeGenericReturnTypeTest()
|
|
|
|
tests := []struct {
|
|
name string
|
|
response string
|
|
want float64
|
|
}{
|
|
{"correct", "string", 1},
|
|
{"correct capitalized", "String", 1},
|
|
{"correct quoted", "`string`", 1},
|
|
{"wrong: the slice element pointer type", "*string", 0},
|
|
{"wrong: the generic parameter name itself, not its instantiation", "T", 0},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := tc.Eval.Evaluate(context.Background(), tt.response)
|
|
if got.Value != tt.want {
|
|
t.Errorf("Eval.Evaluate(%q) = %v, want %v (detail: %s)", tt.response, got.Value, tt.want, got.Detail)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCodeCommitBisectTest_Eval(t *testing.T) {
|
|
tc := codeCommitBisectTest()
|
|
|
|
tests := []struct {
|
|
name string
|
|
response string
|
|
want float64
|
|
}{
|
|
{"correct", "c3c3c3c", 1},
|
|
{"correct with trailing period", "c3c3c3c.", 1},
|
|
{"wrong: the initial commit, predates the cache entirely", "c1a1a1a", 0},
|
|
{"wrong: only a logging change, no behavior change", "c4d4d4d", 0},
|
|
{"wrong: the docs-only commit", "c5e5e5e", 0},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := tc.Eval.Evaluate(context.Background(), tt.response)
|
|
if got.Value != tt.want {
|
|
t.Errorf("Eval.Evaluate(%q) = %v, want %v (detail: %s)", tt.response, got.Value, tt.want, got.Detail)
|
|
}
|
|
})
|
|
}
|
|
}
|