aboutsummaryrefslogtreecommitdiff
path: root/internal/game/map_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-11 19:24:25 -0400
committerhistoria <[not public]>2026-06-11 19:24:25 -0400
commit6b2b4bf470b655f01c5a21c5f558a6102402c214 (patch)
tree10970b523999b87ea09c63486906f0c5314f3542 /internal/game/map_test.go
parent1b9e2da3b3c438d8dc53d3489725dd5ba0022777 (diff)
downloadthehouseoficarus-6b2b4bf470b655f01c5a21c5f558a6102402c214.tar.gz
feat: map implemented with BFS
Diffstat (limited to 'internal/game/map_test.go')
-rw-r--r--internal/game/map_test.go94
1 files changed, 94 insertions, 0 deletions
diff --git a/internal/game/map_test.go b/internal/game/map_test.go
new file mode 100644
index 0000000..a50c2c2
--- /dev/null
+++ b/internal/game/map_test.go
@@ -0,0 +1,94 @@
+package game
+
+import (
+ "strings"
+ "testing"
+
+ "thirdcollapse/internal/world"
+)
+
+func TestBuildTinyMap(t *testing.T) {
+ g := &Game{
+ World: world.New("../../data"),
+ MapWidth: 70,
+ }
+
+ tests := []struct {
+ name string
+ roomID int
+ want []string // expected lines, or nil to just check count
+ }{
+ {
+ name: "room 1 has east exit",
+ roomID: 1,
+ },
+ {
+ name: "room 2 has west/north/east",
+ roomID: 2,
+ },
+ {
+ name: "room 4 has west/north/east",
+ roomID: 4,
+ },
+ {
+ name: "room 21 has west only",
+ roomID: 21,
+ },
+ {
+ name: "room 22 west of town square",
+ roomID: 22,
+ },
+ {
+ name: "room 25 east of south of west",
+ roomID: 25,
+ },
+ {
+ name: "room 8 hacking lab",
+ roomID: 8,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ lines := buildTinyMap(g, tt.roomID)
+ if len(lines) != 7 {
+ t.Fatalf("expected 7 lines, got %d", len(lines))
+ }
+ if lines[0] != "╔═════╗" {
+ t.Errorf("line 0: want ╔═════╗, got %s", lines[0])
+ }
+ if lines[6] != "╚═════╝" {
+ t.Errorf("line 6: want ╚═════╝, got %s", lines[6])
+ }
+ for i := 1; i <= 5; i++ {
+ if !strings.HasPrefix(lines[i], "║") || !strings.HasSuffix(lines[i], "║") {
+ t.Errorf("line %d: should have ║ borders, got %s", i, lines[i])
+ }
+ if len([]rune(lines[i])) != 7 {
+ t.Errorf("line %d: expected 7 runes, got %d in %q", i, len([]rune(lines[i])), lines[i])
+ }
+ }
+ t.Logf("Room %d map:\n%s", tt.roomID, strings.Join(lines, "\n"))
+ })
+ }
+}
+
+func TestWrapText(t *testing.T) {
+ tests := []struct {
+ text string
+ width int
+ want int // expected number of lines
+ }{
+ {"hello world", 70, 1},
+ {"hello world", 5, 2},
+ {"", 70, 0},
+ {"a b c d e f g h i j", 5, 4},
+ }
+
+ for _, tt := range tests {
+ result := wrapText(tt.text, tt.width)
+ if len(result) != tt.want {
+ t.Errorf("wrapText(%q, %d) = %d lines, want %d: %v", tt.text, tt.width, len(result), tt.want, result)
+ }
+ }
+}