-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTests.lua
More file actions
209 lines (183 loc) · 7.12 KB
/
Copy pathTests.lua
File metadata and controls
209 lines (183 loc) · 7.12 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
local NoPoizen = _G.NoPoizen
if not NoPoizen then
return
end
NoPoizen.tests = NoPoizen.tests or {}
local function Fail(message)
error(message or "test failed", 2)
end
local function AssertEquals(actual, expected, context)
if actual ~= expected then
Fail(string.format("%s (expected=%s actual=%s)", context or "assert", tostring(expected), tostring(actual)))
end
end
local function AssertTrue(value, context)
if not value then
Fail((context or "assert") .. " (expected true)")
end
end
local function FindRowByCategory(rows, category)
for _, row in ipairs(rows or {}) do
if row.category == category then
return row
end
end
return nil
end
function NoPoizen:RegisterTest(name, fn)
if type(name) ~= "string" or name == "" or type(fn) ~= "function" then
return false
end
self.tests[name] = fn
return true
end
function NoPoizen:RunTests()
local names = {}
for name in pairs(self.tests) do
table.insert(names, name)
end
table.sort(names)
local passed = 0
for _, name in ipairs(names) do
self.tests[name]()
passed = passed + 1
end
self:Print(string.format("Tests complete: %d passed, 0 failed", passed))
return true
end
NoPoizen:RegisterTest("required counts baseline", function()
local counts = NoPoizen.Testables.ResolveRequiredCounts(false)
AssertEquals(counts.lethal, 1, "baseline lethal required")
AssertEquals(counts.nonLethal, 1, "baseline nonLethal required")
end)
NoPoizen:RegisterTest("required counts dragon tempered blades", function()
local counts = NoPoizen.Testables.ResolveRequiredCounts(true)
AssertEquals(counts.lethal, 2, "dtb lethal required")
AssertEquals(counts.nonLethal, 2, "dtb nonLethal required")
end)
NoPoizen:RegisterTest("missing counts computed from active and required", function()
local missing = NoPoizen.Testables.CalculateMissingCounts({
lethal = 2,
nonLethal = 1,
}, {
lethal = 1,
nonLethal = 1,
})
AssertEquals(missing.lethal, 1, "missing lethal")
AssertEquals(missing.nonLethal, 0, "missing nonLethal")
AssertEquals(missing.total, 1, "missing total")
end)
NoPoizen:RegisterTest("audio does not play when disabled", function()
local shouldPlay = NoPoizen.Testables.ShouldPlayAudio(false, true, false, 1.0)
AssertEquals(shouldPlay, false, "audio disabled should not play")
end)
NoPoizen:RegisterTest("audio does not play when volume is zero", function()
local shouldPlay = NoPoizen.Testables.ShouldPlayAudio(false, true, true, 0)
AssertEquals(shouldPlay, false, "zero volume should not play")
end)
NoPoizen:RegisterTest("audio plays only on missing state transition", function()
local first = NoPoizen.Testables.ShouldPlayAudio(false, true, true, 1.0)
local second = NoPoizen.Testables.ShouldPlayAudio(true, true, true, 1.0)
local recovered = NoPoizen.Testables.ShouldPlayAudio(true, false, true, 1.0)
AssertTrue(first == true, "first transition should play")
AssertTrue(second == false, "steady missing should not play")
AssertTrue(recovered == false, "resolved state should not play")
end)
NoPoizen:RegisterTest("satisfied audio plays only on missing to satisfied transition", function()
local fromMissing = NoPoizen.Testables.ShouldPlaySatisfiedAudio(true, true, true, 1.0)
local steadySatisfied = NoPoizen.Testables.ShouldPlaySatisfiedAudio(false, true, true, 1.0)
local stillMissing = NoPoizen.Testables.ShouldPlaySatisfiedAudio(true, false, true, 1.0)
local disabled = NoPoizen.Testables.ShouldPlaySatisfiedAudio(true, true, false, 1.0)
local muted = NoPoizen.Testables.ShouldPlaySatisfiedAudio(true, true, true, 0)
AssertTrue(fromMissing == true, "transition from missing should play satisfied audio")
AssertTrue(steadySatisfied == false, "steady satisfied should not replay")
AssertTrue(stillMissing == false, "missing state should not play satisfied audio")
AssertTrue(disabled == false, "disabled satisfied audio should not play")
AssertTrue(muted == false, "muted satisfied audio should not play")
end)
NoPoizen:RegisterTest("audio arming suppresses playback before arm time", function()
local isArmed, suppress = NoPoizen.Testables.ResolveAudioArmingState(false, 12.0, 11.9)
AssertTrue(isArmed == false, "should remain unarmed before arm time")
AssertTrue(suppress == true, "should suppress playback before arm time")
end)
NoPoizen:RegisterTest("audio arming seeds state at arm time without playback", function()
local isArmed, suppress = NoPoizen.Testables.ResolveAudioArmingState(false, 12.0, 12.0)
AssertTrue(isArmed == true, "should arm at arm time")
AssertTrue(suppress == true, "first armed tick should still suppress playback")
end)
NoPoizen:RegisterTest("audio arming allows playback once armed", function()
local isArmed, suppress = NoPoizen.Testables.ResolveAudioArmingState(true, 12.0, 99.0)
AssertTrue(isArmed == true, "should stay armed")
AssertTrue(suppress == false, "armed state should allow playback")
end)
NoPoizen:RegisterTest("indicator rows include both categories when both are missing", function()
local rows = NoPoizen.Testables.BuildIndicatorRows(
{
lethal = {
{ spellID = 1, name = "L1", icon = 1 },
{ spellID = 2, name = "L2", icon = 2 },
},
nonLethal = {
{ spellID = 3, name = "N1", icon = 3 },
{ spellID = 4, name = "N2", icon = 4 },
},
},
{
counts = { lethal = 0, nonLethal = 0 },
spellIDs = { lethal = {}, nonLethal = {} },
names = { lethal = {}, nonLethal = {} },
},
{ lethal = 1, nonLethal = 1 }
)
AssertEquals(#rows, 2, "should contain two rows")
AssertEquals(rows[1].category, "lethal", "first row should be lethal")
AssertEquals(rows[2].category, "nonLethal", "second row should be nonLethal")
AssertEquals(#rows[1].icons, 2, "lethal icons")
AssertEquals(#rows[2].icons, 2, "nonLethal icons")
end)
NoPoizen:RegisterTest("row disappears when category is fully applied", function()
local rows = NoPoizen.Testables.BuildIndicatorRows(
{
lethal = {
{ spellID = 1, name = "L1", icon = 1 },
},
nonLethal = {
{ spellID = 2, name = "N1", icon = 2 },
{ spellID = 3, name = "N2", icon = 3 },
},
},
{
counts = { lethal = 1, nonLethal = 0 },
spellIDs = { lethal = { [1] = true }, nonLethal = {} },
names = { lethal = { l1 = true }, nonLethal = {} },
},
{ lethal = 1, nonLethal = 1 }
)
AssertEquals(#rows, 1, "only one row should remain")
AssertEquals(rows[1].category, "nonLethal", "remaining row should be nonLethal")
end)
NoPoizen:RegisterTest("active poison icon is removed from category row", function()
local rows = NoPoizen.Testables.BuildIndicatorRows(
{
lethal = {
{ spellID = 1, name = "L1", icon = 1 },
{ spellID = 2, name = "L2", icon = 2 },
{ spellID = 3, name = "L3", icon = 3 },
},
nonLethal = {
{ spellID = 9, name = "N1", icon = 9 },
},
},
{
counts = { lethal = 1, nonLethal = 0 },
spellIDs = { lethal = { [2] = true }, nonLethal = {} },
names = { lethal = { l2 = true }, nonLethal = {} },
},
{ lethal = 2, nonLethal = 1 }
)
local lethalRow = FindRowByCategory(rows, "lethal")
AssertTrue(lethalRow ~= nil, "lethal row should exist")
AssertEquals(#lethalRow.icons, 2, "active lethal icon should be removed")
AssertEquals(lethalRow.icons[1].spellID, 1, "first lethal icon")
AssertEquals(lethalRow.icons[2].spellID, 3, "second lethal icon")
end)