Modularize tests
Signed-off-by: Rahix <rahix@rahix.de>
This commit is contained in:
parent
da6c36922b
commit
c6bbdcf984
2 changed files with 60 additions and 58 deletions
|
|
@ -1,12 +1,10 @@
|
||||||
require("lunit")
|
require("lunit")
|
||||||
|
|
||||||
local network = require("network")
|
|
||||||
local serialization = require("serialization")
|
local serialization = require("serialization")
|
||||||
local BaseControl = require("bc")
|
local BaseControl = require("bc")
|
||||||
|
|
||||||
module("bc-tests", package.seeall, lunit.testcase)
|
module("local", package.seeall, lunit.testcase)
|
||||||
|
|
||||||
-- Local {{{
|
|
||||||
function test_construct()
|
function test_construct()
|
||||||
local function is_a_bc(bc)
|
local function is_a_bc(bc)
|
||||||
assert_true(bc.local_nouns ~= nil)
|
assert_true(bc.local_nouns ~= nil)
|
||||||
|
|
@ -172,58 +170,3 @@ function test_iter_empty()
|
||||||
assert_equal(0, #bc:nouns(), "nouns found in empty network")
|
assert_equal(0, #bc:nouns(), "nouns found in empty network")
|
||||||
assert_equal(0, #bc:verbs(), "verbs found in empty network")
|
assert_equal(0, #bc:verbs(), "verbs found in empty network")
|
||||||
end
|
end
|
||||||
-- }}}
|
|
||||||
|
|
||||||
-- Network {{{
|
|
||||||
function test_multinode()
|
|
||||||
local bc1 = BaseControl:finalize()
|
|
||||||
local bc2 = BaseControl:new()
|
|
||||||
bc2:register("multinode1", 123)
|
|
||||||
bc2:register("multinode2v", function() end)
|
|
||||||
bc2:finalize()
|
|
||||||
local bc3 = BaseControl:finalize()
|
|
||||||
|
|
||||||
assert_true(bc1:has_noun("multinode1"), "d1: remote noun missing")
|
|
||||||
assert_true(bc1:has_verb("multinode2v"), "d1: remote verb missing")
|
|
||||||
assert_true(bc3:has_noun("multinode1"), "d2: remote noun missing")
|
|
||||||
assert_true(bc3:has_verb("multinode2v"), "d2: remote verb missing")
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_multinode_iters()
|
|
||||||
local bc1 = BaseControl:new(
|
|
||||||
BaseControl.Network(121233)
|
|
||||||
)
|
|
||||||
bc1:register("miter1", 123)
|
|
||||||
bc1:register("miter2v", function() end)
|
|
||||||
bc1:finalize()
|
|
||||||
|
|
||||||
local bc2 = BaseControl:new(
|
|
||||||
BaseControl.Network(121233)
|
|
||||||
)
|
|
||||||
bc2:register("miter3", 321)
|
|
||||||
bc2:register("miter4v", function() end)
|
|
||||||
bc2:finalize()
|
|
||||||
|
|
||||||
local nouns = bc2:nouns()
|
|
||||||
table.sort(nouns)
|
|
||||||
assert_equal(2, #nouns, "noun-list incorrect")
|
|
||||||
assert_equal("miter1", nouns[1], "noun-list incorrect")
|
|
||||||
assert_equal("miter3", nouns[2], "noun-list incorrect")
|
|
||||||
|
|
||||||
local verbs = bc2:verbs()
|
|
||||||
table.sort(verbs)
|
|
||||||
assert_equal(2, #verbs, "verb-list incorrect")
|
|
||||||
assert_equal("miter2v", verbs[1], "verb-list incorrect")
|
|
||||||
assert_equal("miter4v", verbs[2], "verb-list incorrect")
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_get_network()
|
|
||||||
local bc1 = BaseControl:new()
|
|
||||||
bc1:register("getnw1", 123)
|
|
||||||
bc1:finalize()
|
|
||||||
|
|
||||||
local bc2 = BaseControl:new()
|
|
||||||
|
|
||||||
assert_equal(123, bc2:get("getnw1"), "wrong value")
|
|
||||||
end
|
|
||||||
-- }}}
|
|
||||||
59
tests/network.lua
Normal file
59
tests/network.lua
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
require("lunit")
|
||||||
|
|
||||||
|
local network = require("network")
|
||||||
|
local serialization = require("serialization")
|
||||||
|
local BaseControl = require("bc")
|
||||||
|
|
||||||
|
module("network", package.seeall, lunit.testcase)
|
||||||
|
|
||||||
|
function test_multinode()
|
||||||
|
local bc1 = BaseControl:finalize()
|
||||||
|
local bc2 = BaseControl:new()
|
||||||
|
bc2:register("multinode1", 123)
|
||||||
|
bc2:register("multinode2v", function() end)
|
||||||
|
bc2:finalize()
|
||||||
|
local bc3 = BaseControl:finalize()
|
||||||
|
|
||||||
|
assert_true(bc1:has_noun("multinode1"), "d1: remote noun missing")
|
||||||
|
assert_true(bc1:has_verb("multinode2v"), "d1: remote verb missing")
|
||||||
|
assert_true(bc3:has_noun("multinode1"), "d2: remote noun missing")
|
||||||
|
assert_true(bc3:has_verb("multinode2v"), "d2: remote verb missing")
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_multinode_iters()
|
||||||
|
local bc1 = BaseControl:new(
|
||||||
|
BaseControl.Network(121233)
|
||||||
|
)
|
||||||
|
bc1:register("miter1", 123)
|
||||||
|
bc1:register("miter2v", function() end)
|
||||||
|
bc1:finalize()
|
||||||
|
|
||||||
|
local bc2 = BaseControl:new(
|
||||||
|
BaseControl.Network(121233)
|
||||||
|
)
|
||||||
|
bc2:register("miter3", 321)
|
||||||
|
bc2:register("miter4v", function() end)
|
||||||
|
bc2:finalize()
|
||||||
|
|
||||||
|
local nouns = bc2:nouns()
|
||||||
|
table.sort(nouns)
|
||||||
|
assert_equal(2, #nouns, "noun-list incorrect")
|
||||||
|
assert_equal("miter1", nouns[1], "noun-list incorrect")
|
||||||
|
assert_equal("miter3", nouns[2], "noun-list incorrect")
|
||||||
|
|
||||||
|
local verbs = bc2:verbs()
|
||||||
|
table.sort(verbs)
|
||||||
|
assert_equal(2, #verbs, "verb-list incorrect")
|
||||||
|
assert_equal("miter2v", verbs[1], "verb-list incorrect")
|
||||||
|
assert_equal("miter4v", verbs[2], "verb-list incorrect")
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_get_network()
|
||||||
|
local bc1 = BaseControl:new()
|
||||||
|
bc1:register("getnw1", 123)
|
||||||
|
bc1:finalize()
|
||||||
|
|
||||||
|
local bc2 = BaseControl:new()
|
||||||
|
|
||||||
|
assert_equal(123, bc2:get("getnw1"), "wrong value")
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue