aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/spec
diff options
context:
space:
mode:
authorY. Wang <yw05@forksworld.de>2022-05-06 21:36:21 +0200
committerY. Wang <yw05@forksworld.de>2023-03-23 20:06:02 +0100
commit220563012d2aa2c753c791fa9faa38346f1355a5 (patch)
tree7f372b3b3ba28b7e235c87a6a5000e1233fdf6e2 /advtrains_interlocking/spec
parent9d5205e7e2a9ad5ed28e84776a5ab1186963a855 (diff)
downloadadvtrains-220563012d2aa2c753c791fa9faa38346f1355a5.tar.gz
advtrains-220563012d2aa2c753c791fa9faa38346f1355a5.tar.bz2
advtrains-220563012d2aa2c753c791fa9faa38346f1355a5.zip
Record signal aspect to avoid excessive get_aspect calls; report testing coverage
Diffstat (limited to 'advtrains_interlocking/spec')
l---------advtrains_interlocking/spec/fixtures/advtrains_helpers.lua1
-rw-r--r--advtrains_interlocking/spec/mineunit.conf0
-rw-r--r--advtrains_interlocking/spec/signal_api_spec.lua50
3 files changed, 51 insertions, 0 deletions
diff --git a/advtrains_interlocking/spec/fixtures/advtrains_helpers.lua b/advtrains_interlocking/spec/fixtures/advtrains_helpers.lua
new file mode 120000
index 0000000..9b0ab67
--- /dev/null
+++ b/advtrains_interlocking/spec/fixtures/advtrains_helpers.lua
@@ -0,0 +1 @@
+../../../advtrains/helpers.lua \ No newline at end of file
diff --git a/advtrains_interlocking/spec/mineunit.conf b/advtrains_interlocking/spec/mineunit.conf
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/advtrains_interlocking/spec/mineunit.conf
diff --git a/advtrains_interlocking/spec/signal_api_spec.lua b/advtrains_interlocking/spec/signal_api_spec.lua
new file mode 100644
index 0000000..2659380
--- /dev/null
+++ b/advtrains_interlocking/spec/signal_api_spec.lua
@@ -0,0 +1,50 @@
+require("mineunit")
+
+mineunit("core")
+
+_G.advtrains = {
+ interlocking = {
+ aspects = sourcefile("signal_aspects"),
+ --aspects = fixture("../../signal_aspects"),
+ },
+ ndb = {
+ get_node = minetest.get_node,
+ }
+}
+
+fixture("advtrains_helpers")
+fixture("../../database")
+sourcefile("signal_api")
+
+local stub_aspect_t1 = { main = math.random() }
+local stub_pos_t1 = {x = 1, y = 0, z = 1}
+
+minetest.register_node(":stubsignal_t1", {
+ advtrains = {
+ supported_aspects = {},
+ get_aspect = function () return stub_aspect_t1 end,
+ set_aspect = function () end,
+ },
+ groups = { advtrains_signal = 2 },
+})
+
+world.layout {
+ {stub_pos_t1, "stubsignal_t1"},
+}
+
+describe("API for supposed signal aspects", function()
+ it("should load and save data properly", function()
+ local tbl = {_foo = true}
+ advtrains.interlocking.load_supposed_aspects(tbl)
+ assert.same(tbl, advtrains.interlocking.save_supposed_aspects())
+ end)
+ it("should set and get type 1 signals properly", function ()
+ local pos = stub_pos_t1
+ local asp = stub_aspect_t1
+ local newasp = { dst = math.random() }
+ assert.same(asp, advtrains.interlocking.signal_get_aspect(pos))
+ advtrains.interlocking.signal_set_aspect(pos, newasp)
+ assert.same(newasp, advtrains.interlocking.signal_get_aspect(pos))
+ assert.same(asp, advtrains.interlocking.signal_get_real_aspect(pos))
+ end)
+end)