clone

fifteen puzzle games for the terminal, with daily puzzles, weekly ladders and xp, built on bubble tea

main
puzzletea / export / pdf / jsonl_difficulty_test.go
jsonl_difficulty_test.go 2.8K
1package pdfexport23import (4 "encoding/json"5 "path/filepath"6 "testing"7)89func TestParseJSONLFilePrefersDifficultyElo(t *testing.T) {10 path := filepath.Join(t.TempDir(), "pack.jsonl")11 targetElo := 120012 actualElo := 180013 record := JSONLRecord{14 Schema: ExportSchemaV1,15 Pack: JSONLPackMeta{16 Generated: "2026-02-22T10:00:00Z",17 Version: "v-test",18 Category: "Nonogram",19 ModeSelection: "Mini",20 Count: 1,21 },22 Puzzle: JSONLPuzzle{23 Index: 1,24 Name: "ember-newt",25 Game: "Nonogram",26 Mode: "Mini",27 TargetDifficultyElo: &targetElo,28 ActualDifficultyElo: &actualElo,29 DifficultyConfidence: "high",30 Save: json.RawMessage(`{"width":2,"height":2,"row-hints":[[1],[1]],"col-hints":[[1],[1]],"state":" \n "}`),31 },32 }33 writeSingleJSONLRecord(t, path, record)3435 doc, err := ParseJSONLFile(path)36 if err != nil {37 t.Fatal(err)38 }39 puzzle := doc.Puzzles[0]40 if puzzle.TargetDifficultyElo == nil || *puzzle.TargetDifficultyElo != targetElo {41 t.Fatalf("TargetDifficultyElo = %v, want %d", puzzle.TargetDifficultyElo, targetElo)42 }43 if puzzle.ActualDifficultyElo == nil || *puzzle.ActualDifficultyElo != actualElo {44 t.Fatalf("ActualDifficultyElo = %v, want %d", puzzle.ActualDifficultyElo, actualElo)45 }46 if got, want := puzzle.DifficultyScore, 0.6; got != want {47 t.Fatalf("DifficultyScore = %v, want %v", got, want)48 }49 if got, want := puzzle.DifficultyConfidence, DifficultyConfidenceHigh; got != want {50 t.Fatalf("DifficultyConfidence = %q, want %q", got, want)51 }52 if got, want := puzzle.DifficultySource, "actual-elo"; got != want {53 t.Fatalf("DifficultySource = %q, want %q", got, want)54 }55}5657func TestParseJSONLFileFallsBackToTargetDifficultyElo(t *testing.T) {58 path := filepath.Join(t.TempDir(), "pack.jsonl")59 targetElo := 150060 record := JSONLRecord{61 Schema: ExportSchemaV1,62 Pack: JSONLPackMeta{63 Generated: "2026-02-22T10:00:00Z",64 Version: "v-test",65 Category: "Nonogram",66 ModeSelection: "Mini",67 Count: 1,68 },69 Puzzle: JSONLPuzzle{70 Index: 1,71 Name: "ember-newt",72 Game: "Nonogram",73 Mode: "Mini",74 TargetDifficultyElo: &targetElo,75 DifficultyConfidence: "medium",76 Save: json.RawMessage(`{"width":2,"height":2,"row-hints":[[1],[1]],"col-hints":[[1],[1]],"state":" \n "}`),77 },78 }79 writeSingleJSONLRecord(t, path, record)8081 doc, err := ParseJSONLFile(path)82 if err != nil {83 t.Fatal(err)84 }85 puzzle := doc.Puzzles[0]86 if got, want := puzzle.DifficultyScore, 0.5; got != want {87 t.Fatalf("DifficultyScore = %v, want %v", got, want)88 }89 if got, want := puzzle.DifficultySource, "target-elo"; got != want {90 t.Fatalf("DifficultySource = %q, want %q", got, want)91 }92}