initial: actor-test v0.1.0 — 8 assertions
Phase-A.5 test-lib for lib-core.actor. Covers create-validation (missing/zero movement_speed loud-errors + valid spec), position (initial x/y), move ((0,0) no-op + additive delta), movement_speed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
85
init.lua
Normal file
85
init.lua
Normal file
@@ -0,0 +1,85 @@
|
||||
-- lib-core.actor-test — Phase A.5
|
||||
-- 8 assertions: 3 create-validation + 2 position + 2 move + 1 movement_speed.
|
||||
-- Pattern follows P.2.4 Test-Module-Pattern; TAP output via engine.test.*
|
||||
|
||||
local actor = require("lib-core.actor")
|
||||
local composition = require("lib-core.composition")
|
||||
local T = engine.test
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.run_tests(ctx)
|
||||
-- Caller-side: define a template once. Actor doesn't auto-define.
|
||||
composition.define_template{
|
||||
id = "test_actor",
|
||||
properties = {
|
||||
position = {x = 0, y = 0},
|
||||
movement_speed = 100,
|
||||
},
|
||||
tags = {"renderable"},
|
||||
}
|
||||
|
||||
-- ----------------------------------------------------------------
|
||||
-- create-validation (3)
|
||||
-- ----------------------------------------------------------------
|
||||
|
||||
-- Loud-error on missing movement_speed
|
||||
local ok_missing_ms = pcall(actor.create, {
|
||||
template = "test_actor",
|
||||
properties = { position = {x = 0, y = 0} },
|
||||
})
|
||||
T.assert(not ok_missing_ms,
|
||||
"actor.create loud-errors when properties.movement_speed missing")
|
||||
|
||||
-- Loud-error on non-positive movement_speed
|
||||
local ok_zero_ms = pcall(actor.create, {
|
||||
template = "test_actor",
|
||||
properties = { position = {x = 0, y = 0}, movement_speed = 0 },
|
||||
})
|
||||
T.assert(not ok_zero_ms,
|
||||
"actor.create loud-errors when movement_speed is 0")
|
||||
|
||||
-- Happy path: valid spec returns a handle
|
||||
local a1 = actor.create{
|
||||
template = "test_actor",
|
||||
properties = {
|
||||
position = {x = 100, y = 200},
|
||||
movement_speed = 150,
|
||||
},
|
||||
}
|
||||
T.assert(a1 ~= nil, "actor.create returns non-nil handle on valid spec")
|
||||
|
||||
-- ----------------------------------------------------------------
|
||||
-- position (2)
|
||||
-- ----------------------------------------------------------------
|
||||
|
||||
-- position returns initial values
|
||||
local x, y = actor.position(a1)
|
||||
T.equals(x, 100, "actor.position returns initial x")
|
||||
T.equals(y, 200, "actor.position returns initial y")
|
||||
|
||||
-- ----------------------------------------------------------------
|
||||
-- move (2)
|
||||
-- ----------------------------------------------------------------
|
||||
|
||||
-- move(0, 0) is no-op
|
||||
actor.move(a1, 0, 0)
|
||||
local x0, y0 = actor.position(a1)
|
||||
T.assert(x0 == 100 and y0 == 200,
|
||||
"actor.move(0,0) preserves position")
|
||||
|
||||
-- move(dx, dy) updates position additively
|
||||
actor.move(a1, 50, -25)
|
||||
local x1, y1 = actor.position(a1)
|
||||
T.assert(x1 == 150 and y1 == 175,
|
||||
"actor.move(50,-25) shifts position to (150, 175)")
|
||||
|
||||
-- ----------------------------------------------------------------
|
||||
-- movement_speed (1)
|
||||
-- ----------------------------------------------------------------
|
||||
|
||||
T.equals(actor.movement_speed(a1), 150,
|
||||
"actor.movement_speed returns the override value (150)")
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user