42.20 and Towtrucks
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
local failures = 0
|
||||
|
||||
local function expect(condition, message)
|
||||
if not condition then
|
||||
failures = failures + 1
|
||||
io.stderr:write("FAIL: " .. message .. "\n")
|
||||
end
|
||||
end
|
||||
|
||||
package.preload["TimedActions/ISBaseTimedAction"] = function() return true end
|
||||
ISBaseTimedAction = {}
|
||||
function ISBaseTimedAction:derive()
|
||||
local derived = {}
|
||||
setmetatable(derived, { __index = self })
|
||||
return derived
|
||||
end
|
||||
function ISBaseTimedAction.new(class, character)
|
||||
local action = { character = character }
|
||||
setmetatable(action, { __index = class })
|
||||
return action
|
||||
end
|
||||
function ISBaseTimedAction.perform(action)
|
||||
action.completed = true
|
||||
end
|
||||
function ISBaseTimedAction.stop(action)
|
||||
action.stopped = true
|
||||
end
|
||||
|
||||
dofile("42.20/media/lua/client/TowBar/WreckerTimedAction.lua")
|
||||
|
||||
local sent = 0
|
||||
local valid = true
|
||||
local function validate() return valid end
|
||||
local function perform() sent = sent + 1 end
|
||||
|
||||
local attach = WreckerTimedAction:new({}, 300, validate, perform, {}, {})
|
||||
expect(attach.maxTime == 300, "attach duration must be 300 action units")
|
||||
expect(sent == 0, "constructing an action must not send a command")
|
||||
attach:perform()
|
||||
expect(sent == 1 and attach.completed, "valid attach must send once after its timer completes")
|
||||
|
||||
local detach = WreckerTimedAction:new({}, 200, validate, perform, {}, {})
|
||||
expect(detach.maxTime == 200, "detach duration must be 200 action units")
|
||||
valid = false
|
||||
detach:perform()
|
||||
expect(sent == 1, "an invalidated timed action must not send its command")
|
||||
|
||||
valid = true
|
||||
local cancelled = WreckerTimedAction:new({}, 300, validate, perform, {}, {})
|
||||
cancelled:stop()
|
||||
expect(cancelled.stopped and sent == 1, "cancelling an action must not send its command")
|
||||
|
||||
if failures > 0 then os.exit(1) end
|
||||
print("PASS: wrecker timed action behavior")
|
||||
Reference in New Issue
Block a user