Add screwdriver test

This commit is contained in:
Jude Melton-Houghton
2022-06-05 15:06:50 -04:00
parent 4ec9775558
commit 58edf03aaf
2 changed files with 47 additions and 0 deletions

View File

@ -93,6 +93,7 @@ do
}} }}
mesecon.register_node("mesecons:test_conductor_rot", { mesecon.register_node("mesecons:test_conductor_rot", {
description = "Rotatable Test Conductor", description = "Rotatable Test Conductor",
on_rotate = mesecon.on_rotate_horiz,
}, {mesecons = off_spec}, {mesecons = on_spec}) }, {mesecons = off_spec}, {mesecons = on_spec})
end end

View File

@ -1,6 +1,7 @@
require("mineunit") require("mineunit")
fixture("mesecons") fixture("mesecons")
fixture("screwdriver")
describe("placement/digging service", function() describe("placement/digging service", function()
local layout = { local layout = {
@ -138,3 +139,48 @@ describe("overheating service", function()
assert.equal(0, mesecon.get_heat(layout[2][1])) assert.equal(0, mesecon.get_heat(layout[2][1]))
end) end)
end) end)
describe("screwdriver service", function()
local layout = {
{{x = 0, y = 0, z = 0}, "mesecons:test_conductor_rot_on"},
{{x = 1, y = 0, z = 0}, "mesecons:test_receptor_on"},
{{x = -1, y = 0, z = 0}, "mesecons:test_conductor_on"},
{{x = 0, y = 0, z = 1}, "mesecons:test_receptor_on"},
{{x = 0, y = 0, z = -1}, "mesecons:test_conductor_off"},
}
local function rotate(new_param2)
local pos = layout[1][1]
local node = world.get_node(pos)
local on_rotate = minetest.registered_nodes[node.name].on_rotate
on_rotate(pos, node, nil, screwdriver.ROTATE_FACE, new_param2)
end
before_each(function()
world.layout(layout)
end)
after_each(function()
mesecon._test_reset()
world.clear()
end)
it("updates conductors", function()
rotate(1)
mineunit:execute_globalstep()
assert.equal("mesecons:test_conductor_off", world.get_node(layout[3][1]).name)
assert.equal("mesecons:test_conductor_on", world.get_node(layout[5][1]).name)
rotate(2)
mineunit:execute_globalstep()
assert.equal("mesecons:test_conductor_on", world.get_node(layout[3][1]).name)
assert.equal("mesecons:test_conductor_off", world.get_node(layout[5][1]).name)
rotate(3)
mineunit:execute_globalstep()
assert.equal("mesecons:test_conductor_off", world.get_node(layout[3][1]).name)
assert.equal("mesecons:test_conductor_on", world.get_node(layout[5][1]).name)
rotate(0)
mineunit:execute_globalstep()
assert.equal("mesecons:test_conductor_on", world.get_node(layout[3][1]).name)
assert.equal("mesecons:test_conductor_off", world.get_node(layout[5][1]).name)
end)
end)