1package puzzle23import "testing"45func TestNormalizeName(t *testing.T) {6 tests := []struct {7 input string8 want string9 }{10 {input: "Word Search", want: "word search"},11 {input: "lights-out", want: "lights out"},12 {input: "word_search", want: "word search"},13 {input: " Sudoku ", want: "sudoku"},14 {input: "Sudoku RGB", want: "sudoku rgb"},15 }1617 for _, tt := range tests {18 if got := NormalizeName(tt.input); got != tt.want {19 t.Fatalf("NormalizeName(%q) = %q, want %q", tt.input, got, tt.want)20 }21 }22}2324func TestCanonicalIDsUseNormalizedNames(t *testing.T) {25 if got, want := CanonicalGameID(" Sudoku RGB "), GameID("sudoku rgb"); got != want {26 t.Fatalf("CanonicalGameID() = %q, want %q", got, want)27 }28 if got, want := CanonicalModeID("Mini-Hard"), ModeID("mini hard"); got != want {29 t.Fatalf("CanonicalModeID() = %q, want %q", got, want)30 }31}3233func TestNewModeDefAndDefinitionCloneInput(t *testing.T) {34 mode := NewModeDef(ModeSpec{35 Title: "Medium",36 Description: "Balanced board",37 Seeded: true,38 })39 if got, want := mode.ID, ModeID("medium"); got != want {40 t.Fatalf("ModeDef.ID = %q, want %q", got, want)41 }4243 spec := DefinitionSpec{44 Name: "Sudoku",45 Description: "Classic grid logic",46 Aliases: []string{"classic"},47 Modes: []ModeDef{mode},48 DailyModeIDs: []ModeID{mode.ID},49 }50 def := NewDefinition(spec)5152 spec.Aliases[0] = "changed"53 spec.Modes[0].Title = "Changed"54 spec.DailyModeIDs[0] = "changed"5556 if got, want := def.ID, GameID("sudoku"); got != want {57 t.Fatalf("Definition.ID = %q, want %q", got, want)58 }59 if got, want := def.Aliases[0], "classic"; got != want {60 t.Fatalf("Aliases[0] = %q, want %q", got, want)61 }62 if got, want := def.Modes[0].Title, "Medium"; got != want {63 t.Fatalf("Modes[0].Title = %q, want %q", got, want)64 }65 if got, want := def.DailyModeIDs[0], ModeID("medium"); got != want {66 t.Fatalf("DailyModeIDs[0] = %q, want %q", got, want)67 }68}6970func TestSelectModeIDsByIndex(t *testing.T) {71 modes := []ModeDef{72 NewModeDef(ModeSpec{Title: "Beginner"}),73 NewModeDef(ModeSpec{Title: "Medium"}),74 NewModeDef(ModeSpec{Title: "Expert"}),75 }7677 got := SelectModeIDsByIndex(modes, 1, 2, 99, -1)78 if len(got) != 2 {79 t.Fatalf("len(SelectModeIDsByIndex) = %d, want 2", len(got))80 }81 if got[0] != ModeID("medium") || got[1] != ModeID("expert") {82 t.Fatalf("SelectModeIDsByIndex = %v, want [medium expert]", got)83 }84}