diff options
| author | historia <[not public]> | 2026-06-29 04:03:38 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-29 04:03:38 -0400 |
| commit | ba34490aaed5f7c242c2b0453130fefc07d0d5d0 (patch) | |
| tree | db5818757d5080221494cead1c7e61a576d1cb65 /internal/model/model_test.go | |
| parent | b1e252c996a6332d391f96624a7d6f149eb097c4 (diff) | |
| download | tui-ascii-mapper-main.tar.gz | |
Diffstat (limited to 'internal/model/model_test.go')
| -rw-r--r-- | internal/model/model_test.go | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/internal/model/model_test.go b/internal/model/model_test.go new file mode 100644 index 0000000..8e4ee63 --- /dev/null +++ b/internal/model/model_test.go @@ -0,0 +1,99 @@ +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") + } +} |
