aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.build.yml2
-rw-r--r--advtrains/spec/speed_spec.lua2
-rw-r--r--advtrains_interlocking/spec/ars_spec.lua67
3 files changed, 70 insertions, 1 deletions
diff --git a/.build.yml b/.build.yml
index 89589b9..9627b14 100644
--- a/.build.yml
+++ b/.build.yml
@@ -31,6 +31,8 @@ tasks:
- run_unit_tests : |
cd advtrains/advtrains
busted
+ cd ../advtrains_interlocking
+ busted
- activate_test_env: |
cd advtrains
git merge --no-commit origin/luaatcdebug
diff --git a/advtrains/spec/speed_spec.lua b/advtrains/spec/speed_spec.lua
index 0f0365f..97f8ffa 100644
--- a/advtrains/spec/speed_spec.lua
+++ b/advtrains/spec/speed_spec.lua
@@ -23,7 +23,7 @@ describe("Arithmetic functions on speed restrictions", function()
assert.is_false(speed.lessp(-1, math.random()))
end)
it("should handle nil", function()
- assert.is_false(speed.greaterp(nil, math.random()))
+ assert.is_true(speed.greaterp(nil, math.random()))
end)
it("should handle mixed nil and -1", function()
assert.is_true(speed.equalp(nil, -1))
diff --git a/advtrains_interlocking/spec/ars_spec.lua b/advtrains_interlocking/spec/ars_spec.lua
new file mode 100644
index 0000000..085dbcb
--- /dev/null
+++ b/advtrains_interlocking/spec/ars_spec.lua
@@ -0,0 +1,67 @@
+-- test the serialization function
+
+
+package.path = "../?.lua;" .. package.path
+
+
+
+
+_G.advtrains = {}
+_G.advtrains.interlocking = {}
+
+require("ars")
+
+local arstb = {{ ln="Foo"}, {c="Bar"}, {n=true, rc="Boo"}}
+local arsdef = {{ ln="Foo"}, {c="Bar"}, {rc="Boo"}, default=true}
+local arstr = [[LN Foo
+#Bar
+!RC Boo]]
+local defstr = [[*
+LN Foo
+#Bar
+RC Boo]]
+il = _G.advtrains.interlocking
+
+describe("ars_to_text", function ()
+ it("read table", function ()
+ assert.equals(il.ars_to_text(arstb),arstr)
+ end)
+ it("reads back and forth", function ()
+ assert.equals(il.ars_to_text(il.text_to_ars(arstr)),arstr)
+ end)
+ it("handles default routes properly", function ()
+ assert.equals(il.ars_to_text(arsdef),defstr)
+ end)
+end)
+
+describe("text_to_ars", function ()
+ it("writes table", function()
+ assert.same(il.text_to_ars(arstr),arstb)
+ end)
+ it("handles default routes properly", function ()
+ assert.same(il.text_to_ars(defstr),arsdef)
+ end)
+end)
+
+train1 = {}
+train2 = {}
+train3 = {}
+train1.line = "Foo"
+train1.routingcode = "Boo"
+train2.line= "Bar"
+train2.routingcode = "NotBoo NotBoo"
+train3.routingcode = "Foo Boo Moo Zoo"
+
+describe("check_rule_match", function ()
+ it("matches rules correctly", function()
+ assert.equals(il.ars_check_rule_match(arstb,train1),1)
+ assert.equals(il.ars_check_rule_match(arsdef,train2),nil)
+ end)
+ it("matches negative rules", function()
+ assert.equals(il.ars_check_rule_match(arstb,train2),3)
+ assert.equals(il.ars_check_rule_match(arstb,train3),nil)
+ end)
+ it("matches RC in a list correctly", function()
+ assert.equals(il.ars_check_rule_match(arsdef,train3),3)
+ end)
+end)
" const int ID_soundText1 = 263; const int ID_soundText2 = 264; const int ID_soundExitButton = 265; const int ID_soundSlider = 266; GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, Client* client ): GUIModalMenu(env, parent, id, menumgr) { } GUIVolumeChange::~GUIVolumeChange() { removeChildren(); } void GUIVolumeChange::removeChildren() { { gui::IGUIElement *e = getElementFromId(ID_soundText1); if(e != NULL) e->remove(); } { gui::IGUIElement *e = getElementFromId(ID_soundText2); if(e != NULL) e->remove(); } { gui::IGUIElement *e = getElementFromId(ID_soundExitButton); if(e != NULL) e->remove(); } { gui::IGUIElement *e = getElementFromId(ID_soundSlider); if(e != NULL) e->remove(); } } void GUIVolumeChange::regenerateGui(v2u32 screensize) { /* Remove stuff */ removeChildren(); /* Calculate new sizes and positions */ core::rect<s32> rect( screensize.X/2 - 380/2, screensize.Y/2 - 200/2, screensize.X/2 + 380/2, screensize.Y/2 + 200/2 ); DesiredRect = rect; recalculateAbsolutePosition(false); v2s32 size = rect.getSize(); v2s32 topleft_client(40, 0); int volume=(int)(g_settings->getFloat("sound_volume")*100); /* Add stuff */ { core::rect<s32> rect(0, 0, 120, 20); rect = rect + v2s32(size.X/2-60, size.Y/2-35); const wchar_t *text = wgettext("Sound Volume: "); Environment->addStaticText(text, rect, false, true, this, ID_soundText1); delete[] text; } { core::rect<s32> rect(0, 0, 30, 20); rect = rect + v2s32(size.X/2+40, size.Y/2-35); Environment->addStaticText(core::stringw(volume).c_str(), rect, false, true, this, ID_soundText2); } { core::rect<s32> rect(0, 0, 80, 30); rect = rect + v2s32(size.X/2-80/2, size.Y/2+55); const wchar_t *text = wgettext("Exit"); Environment->addButton(rect, this, ID_soundExitButton, text); delete[] text; } { core::rect<s32> rect(0, 0, 300, 20);