package model import "testing" func TestNewMap(t *testing.T) { m := NewMap("test", 10, 5, nil) if m.Width != 10 || m.Height != 5 { t.Fatalf("NewMap size: got %dx%d", m.Width, m.Height) } if m.Grid[0][0].Terrain != -1 { t.Fatal("NewMap: grid not initialized to -1") } if len(m.Grid) != 5 || len(m.Grid[0]) != 10 { t.Fatal("NewMap: grid dimensions wrong") } } func TestClone(t *testing.T) { m := NewMap("test", 10, 5, nil) m2 := m.Clone() m2.Grid[0][0].Terrain = 0 if m.Grid[0][0].Terrain != -1 { t.Fatal("Clone shares data") } } func TestInBounds(t *testing.T) { m := NewMap("test", 10, 5, nil) if !m.InBounds(Point{X: 0, Y: 0}) { t.Fatal("InBounds(0,0) should be true") } if m.InBounds(Point{X: -1, Y: 0}) { t.Fatal("InBounds(-1,0) should be false") } if m.InBounds(Point{X: 0, Y: 5}) { t.Fatal("InBounds(0,5) should be false") } if m.InBounds(Point{X: 10, Y: 0}) { t.Fatal("InBounds(10,0) should be false") } } func TestSetGetCell(t *testing.T) { m := NewMap("test", 10, 5, nil) m.SetCell(Point{X: 1, Y: 2}, 5, "red") c := m.CellAt(Point{X: 1, Y: 2}) if c.Terrain != 5 || c.Color != "red" { t.Fatalf("SetCell/GetCell: got %d,%s", c.Terrain, c.Color) } } func TestUndoStack(t *testing.T) { u := &UndoStack{} m := NewMap("test", 3, 3, nil) u.Push(m) m.SetCell(Point{X: 1, Y: 1}, 2, "green") u.Push(m) m.SetCell(Point{X: 2, Y: 2}, 3, "blue") if entry := u.Undo(); entry != nil { *entry.Target = *entry.State } if m.CellAt(Point{X: 2, Y: 2}).Terrain != -1 { t.Fatal("Undo failed") } } func TestClamp(t *testing.T) { if Clamp(5, 0, 10) != 5 { t.Fatal("Clamp middle") } if Clamp(-1, 0, 10) != 0 { t.Fatal("Clamp low") } if Clamp(11, 0, 10) != 10 { t.Fatal("Clamp high") } } func TestPickColor(t *testing.T) { tc := Terrain{Colors: []TerrainColor{{Color: "22", Weight: 100}}} if tc.PickColor() != "22" { t.Fatal("PickColor single failed") } tc2 := Terrain{} if tc2.PickColor() != "0" { t.Fatal("PickColor empty failed") } } func TestTerrainSymbol(t *testing.T) { tr := Terrain{Symbol: "X", ASCII: "x"} if tr.GetSymbol(true) != "X" { t.Fatal("Unicode symbol") } if tr.GetSymbol(false) != "x" { t.Fatal("ASCII symbol") } }