MCPcopy Create free account
hub / github.com/astercloud/aster / TestRunBatchSimple

Function TestRunBatchSimple

pkg/evals/batch_test.go:10–84  ·  view source on GitHub ↗

TestRunBatchSimple 测试简单批量评估

(t *testing.T)

Source from the content-addressed store, hash-verified

8
9// TestRunBatchSimple 测试简单批量评估
10func TestRunBatchSimple(t *testing.T) {
11 mockProvider := &MockProvider{
12 response: `{"score": 0.85, "reason": "测试评分"}`,
13 }
14
15 testCases := []*BatchTestCase{
16 {
17 ID: "case1",
18 Input: &TextEvalInput{
19 Answer: "巴黎是法国的首都。",
20 Context: []string{"法国的首都是巴黎。"},
21 },
22 },
23 {
24 ID: "case2",
25 Input: &TextEvalInput{
26 Answer: "伦敦是英国的首都。",
27 Context: []string{"英国的首都是伦敦。"},
28 },
29 },
30 }
31
32 scorers := []Scorer{
33 NewKeywordCoverageScorer(KeywordCoverageConfig{
34 Keywords: []string{"首都"},
35 CaseInsensitive: true,
36 }),
37 NewLexicalSimilarityScorer(LexicalSimilarityConfig{
38 MinTokenLength: 2,
39 }),
40 NewFaithfulnessScorer(mockProvider),
41 }
42
43 result, err := RunBatchSimple(context.Background(), testCases, scorers)
44 if err != nil {
45 t.Fatalf("RunBatchSimple() error = %v", err)
46 }
47
48 // 验证结果数量
49 if len(result.Results) != 2 {
50 t.Errorf("RunBatchSimple() got %d results, want 2", len(result.Results))
51 }
52
53 // 验证每个测试用例有 3 个 scorer 的结果
54 for i, r := range result.Results {
55 if len(r.Scores) != 3 {
56 t.Errorf("Result[%d] got %d scores, want 3", i, len(r.Scores))
57 }
58 if r.Error != "" {
59 t.Errorf("Result[%d] has error: %s", i, r.Error)
60 }
61 }
62
63 // 验证汇总
64 if result.Summary == nil {
65 t.Fatal("RunBatchSimple() summary is nil")
66 }
67

Callers

nothing calls this directly

Calls 4

NewKeywordCoverageScorerFunction · 0.85
NewFaithfulnessScorerFunction · 0.85
RunBatchSimpleFunction · 0.85

Tested by

no test coverage detected