clone

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

main
puzzletea / games / takuzu / print_adapter_test.go
print_adapter_test.go 2.9K
1package takuzu23import (4 "testing"56 "github.com/FelineStateMachine/puzzletea/export/pdf"7)89func TestTakuzuGivenFontSize(t *testing.T) {10 tests := []struct {11 name string12 cellSize float6413 size int14 wantMin float6415 wantMax float6416 }{17 {18 name: "small cell keeps readable minimum",19 cellSize: 3.0,20 size: 14,21 wantMin: 8.2,22 wantMax: 8.2,23 },24 {25 name: "12x12 remains comfortably readable",26 cellSize: 10.0,27 size: 12,28 wantMin: 9.5,29 wantMax: 9.6,30 },31 {32 name: "14x14 remains comfortably readable",33 cellSize: 9.0,34 size: 14,35 wantMin: 8.5,36 wantMax: 8.6,37 },38 }3940 for _, tt := range tests {41 t.Run(tt.name, func(t *testing.T) {42 got := takuzuGivenFontSize(tt.cellSize, tt.size)43 if got < tt.wantMin || got > tt.wantMax {44 t.Fatalf("font size = %.3f, want %.3f..%.3f", got, tt.wantMin, tt.wantMax)45 }46 })47 }48}4950func TestTakuzuRelationSizing_FontSize(t *testing.T) {51 tests := []struct {52 name string53 cellSize float6454 size int55 wantMin float6456 wantMax float6457 }{58 {59 name: "14x14 scales below the old 9 point floor",60 cellSize: 8.0,61 size: 14,62 wantMin: 6.2,63 wantMax: 6.2,64 },65 {66 name: "12x12 scales below the old 9 point floor",67 cellSize: 11.0,68 size: 12,69 wantMin: 6.2,70 wantMax: 6.2,71 },72 {73 name: "larger cells still respect the new cap",74 cellSize: 16.0,75 size: 6,76 wantMin: 7.6,77 wantMax: 7.7,78 },79 }8081 for _, tt := range tests {82 t.Run(tt.name, func(t *testing.T) {83 got := takuzuRelationSizingFor(tt.cellSize, tt.size)84 if got.fontSize < tt.wantMin || got.fontSize > tt.wantMax {85 t.Fatalf("font size = %.3f, want %.3f..%.3f", got.fontSize, tt.wantMin, tt.wantMax)86 }87 })88 }89}9091func TestTakuzuRelationSizing_BackdropSize(t *testing.T) {92 tests := []struct {93 name string94 cellSize float6495 size int96 wantMin float6497 wantMax float6498 }{99 {100 name: "caps the knockout on denser 12x12 boards",101 cellSize: 11.0,102 size: 12,103 wantMin: 6.3,104 wantMax: 6.4,105 },106 {107 name: "allows slightly larger knockouts when space is available",108 cellSize: 16.0,109 size: 6,110 wantMin: 8.2,111 wantMax: 8.4,112 },113 }114115 for _, tt := range tests {116 t.Run(tt.name, func(t *testing.T) {117 got := takuzuRelationSizingFor(tt.cellSize, tt.size)118 if got.backdropSize < tt.wantMin || got.backdropSize > tt.wantMax {119 t.Fatalf("backdrop size = %.3f, want %.3f..%.3f", got.backdropSize, tt.wantMin, tt.wantMax)120 }121 })122 }123}124125func TestTakuzuRelationSizing_BackdropStaysWithin12x12Cap(t *testing.T) {126 area := pdfexport.PuzzleBoardRect(139.7, 215.9, 2, 3)127 cellSize := pdfexport.FitCompactCellSize(12, 12, area)128 if cellSize <= 0 {129 t.Fatal("expected positive cell size")130 }131132 got := takuzuRelationSizingFor(cellSize, 12)133 if got.backdropSize > cellSize*0.58+0.001 {134 t.Fatalf("backdrop size = %.3f, want <= %.3f", got.backdropSize, cellSize*0.58)135 }136}