summaryrefslogtreecommitdiff
path: root/llm/perplexity_test.go
diff options
context:
space:
mode:
authorJonas Knobloch <jonas.knobloch@t-online.de>2026-03-17 20:16:39 +0100
committerJonas Knobloch <jonas.knobloch@t-online.de>2026-03-17 20:16:39 +0100
commit57fb765bdc5819f8a367ad75c731a50da68b8d85 (patch)
tree730647fc08847624c138a83f3e8329b6f4755ea6 /llm/perplexity_test.go
parent035eef3308edd4ec581061440337aaa10a37f573 (diff)
Update perplexity evaluator
* Introduce results channel * Introduce jobs channel * Generalize evaluation via callback
Diffstat (limited to 'llm/perplexity_test.go')
-rw-r--r--llm/perplexity_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/llm/perplexity_test.go b/llm/perplexity_test.go
new file mode 100644
index 0000000..81f10af
--- /dev/null
+++ b/llm/perplexity_test.go
@@ -0,0 +1,45 @@
+package llm
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestEvaluator_estimateJobs(t *testing.T) {
+ type gold struct {
+ tokens int
+ window int
+ stride int
+ expected int
+ }
+
+ tests := []gold{
+ {tokens: 20, window: 10, stride: 3, expected: 4},
+ {tokens: 20, window: 10, stride: 4, expected: 3},
+ {tokens: 20, window: 10, stride: 5, expected: 3},
+
+ {tokens: 0, window: 1, stride: 1, expected: 0},
+ {tokens: 1, window: 1, stride: 1, expected: 1},
+
+ {tokens: 0, window: 1024, stride: 1, expected: 0},
+ {tokens: 1, window: 1, stride: 1024, expected: 1},
+ }
+
+ e := NewEvaluator[any]()
+
+ for _, tt := range tests {
+ t.Run(
+ fmt.Sprintf("tokens%d_window%d_stride%d", tt.tokens, tt.window, tt.stride),
+
+ func(t *testing.T) {
+ tokens := make([]int64, tt.tokens)
+
+ got := e.estimateJobs(tokens, tt.window, tt.stride)
+
+ if got != tt.expected {
+ t.Errorf("expected %d but got (%d, %d, %d) = %d", tt.expected, tt.tokens, tt.window, tt.stride, got)
+ }
+ },
+ )
+ }
+}