-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine_test.go
More file actions
82 lines (74 loc) · 1.84 KB
/
Copy pathengine_test.go
File metadata and controls
82 lines (74 loc) · 1.84 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import "testing"
// TestNewEngine verifies engine initialization
// logic including fallback conditions.
func TestNewEngine(t *testing.T) {
theme := getTheme("Classic")
t.Run("Dimensions", func(t *testing.T) {
e := NewEngine(80, 24, theme, false)
if e.Width != 80 || e.Height != 24 {
t.Errorf("expected 80x24, got %dx%d", e.Width, e.Height)
}
if len(e.Grid) != 80*24 {
t.Errorf("expected grid length %d, got %d", 80*24, len(e.Grid))
}
})
t.Run("ASCIIFallback", func(t *testing.T) {
t.Setenv("TERM", "dumb")
e2 := NewEngine(80, 24, theme, false)
if !e2.ASCIIOnly {
t.Errorf("expected ASCII fallback for dumb terminal")
}
})
}
// TestClampSpeed verifies speed constraints against boundary values.
func TestClampSpeed(t *testing.T) {
maxSpd := len(SpeedDelays)
cases := []struct {
input int
expected int
}{
{0, MinSpeed},
{maxSpd + 1, maxSpd},
{5, 5},
}
for _, tc := range cases {
if got := clampSpeed(tc.input); got != tc.expected {
t.Errorf("clampSpeed(%d) = %d; want %d", tc.input, got, tc.expected)
}
}
}
// TestStarCountBounds verifies star count clamping.
func TestStarCountBounds(t *testing.T) {
e := &Engine{StarCount: 7}
e.IncrementStarCount(20)
if e.StarCount != 8 {
t.Errorf("expected 8, got %d", e.StarCount)
}
e.StarCount = 20
e.IncrementStarCount(20)
if e.StarCount != 20 {
t.Errorf("expected 20, got %d", e.StarCount)
}
e.StarCount = 2
e.DecrementStarCount(1)
if e.StarCount != 1 {
t.Errorf("expected 1, got %d", e.StarCount)
}
e.DecrementStarCount(1)
if e.StarCount != 1 {
t.Errorf("expected 1, got %d", e.StarCount)
}
}
// TestToggleModes verifies toggling logic.
func TestToggleModes(t *testing.T) {
e := &Engine{}
e.ToggleStarMode()
if !e.StarMode {
t.Error("expected StarMode true")
}
e.ToggleCRTMode()
if !e.CRTMode {
t.Error("expected CRTMode true")
}
}