mirror of
https://github.com/lukaszraczylo/llm-testbench.git
synced 2026-10-12 00:45:19 +00:00
test(catalog): expand research to 10 tests per subcategory
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.
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWebHTMLProductExtractTest_Eval(t *testing.T) {
|
||||
tc := webHTMLProductExtractTest()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
response string
|
||||
want float64
|
||||
}{
|
||||
{"all correct", `{"name":"Wireless Mechanical Keyboard","price":129.99,"sku":"WBH-2201"}`, 1},
|
||||
{"one field wrong", `{"name":"Wireless Mechanical Keyboard","price":99.99,"sku":"WBH-2201"}`, 2.0 / 3.0},
|
||||
{"all wrong", `{"name":"Wrong Product","price":1,"sku":"XXX"}`, 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 TestWebHreflangReciprocalTest_Eval(t *testing.T) {
|
||||
tc := webHreflangReciprocalTest()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
response string
|
||||
want float64
|
||||
}{
|
||||
{"correct", `{"page_missing_link":"https://example.com/fr/","missing_target":"https://example.com/en/"}`, 1},
|
||||
{"correct page, wrong target", `{"page_missing_link":"https://example.com/fr/","missing_target":"https://example.com/es/"}`, 0.5},
|
||||
{"wrong page entirely", `{"page_missing_link":"https://example.com/es/","missing_target":"https://example.com/en/"}`, 0.5},
|
||||
}
|
||||
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 TestWebParseURL_GroundTruth(t *testing.T) {
|
||||
// Independent re-derivation via net/url.Parse, not hand-derived, per
|
||||
// the ground-truth discipline.
|
||||
u, err := url.Parse(webParseURL)
|
||||
if err != nil {
|
||||
t.Fatalf("url.Parse(%q): %v", webParseURL, err)
|
||||
}
|
||||
|
||||
if got, want := u.Scheme, "https"; got != want {
|
||||
t.Errorf("Scheme = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := u.Hostname(), "api.example.com"; got != want {
|
||||
t.Errorf("Hostname() = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := u.Port(), "8443"; got != want {
|
||||
t.Errorf("Port() = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := u.Path, "/v2/search"; got != want {
|
||||
t.Errorf("Path = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := u.RawQuery, "q=hello+world&sort=desc"; got != want {
|
||||
t.Errorf("RawQuery = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := u.Fragment, "results"; got != want {
|
||||
t.Errorf("Fragment = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebURLParseComponentsTest_Eval(t *testing.T) {
|
||||
tc := webURLParseComponentsTest()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
response string
|
||||
want float64
|
||||
}{
|
||||
{
|
||||
"all correct",
|
||||
`{"scheme":"https","host":"api.example.com","port":8443,"path":"/v2/search","query":"q=hello+world&sort=desc","fragment":"results"}`,
|
||||
1,
|
||||
},
|
||||
{
|
||||
"port included in host field is still wrong for host",
|
||||
`{"scheme":"https","host":"api.example.com:8443","port":8443,"path":"/v2/search","query":"q=hello+world&sort=desc","fragment":"results"}`,
|
||||
5.0 / 6.0,
|
||||
},
|
||||
{
|
||||
"all wrong",
|
||||
`{"scheme":"http","host":"wrong.example.com","port":80,"path":"/","query":"","fragment":""}`,
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user