1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package tools
import (
"fmt"
"testing"
"tui-ascii-mapper/internal/model"
)
func TestDemotools(t *testing.T) {
m := model.NewMap("test", 10, 10, nil)
Brush(m, model.Point{X: 5, Y: 5}, 0, 3, nil)
if m.Grid[5][5].Terrain != 0 {
t.Fatal("Brush failed")
}
pts := BresenhamLine(model.Point{X: 0, Y: 0}, model.Point{X: 3, Y: 0})
if len(pts) != 4 || pts[0] != (model.Point{X: 0, Y: 0}) || pts[3] != (model.Point{X: 3, Y: 0}) {
t.Fatalf("Line failed: %v", pts)
}
if IntSqrt(25) != 5 || IntSqrt(26) != 5 || IntSqrt(0) != 0 {
t.Fatal("IntSqrt failed")
}
t2 := model.Terrain{Colors: []model.TerrainColor{{Color: "22", Weight: 100}}}
if t2.PickColor() != "22" {
t.Fatal("PickColor failed")
}
PlaceTextLabel(m, model.Point{X: 2, Y: 2}, "ABC", "")
if m.Grid[2][2].Text != "A" || m.Grid[2][3].Text != "B" {
t.Fatalf("TextLabel: %s,%s", m.Grid[2][2].Text, m.Grid[2][3].Text)
}
RemoveTextLabel(m, model.Point{X: 2, Y: 2})
if m.Grid[2][2].Text != "" {
t.Fatal("TextLabel remove failed")
}
fmt.Println("tools: ok")
}
|