2012-03-27 23:38:20 +02:00
|
|
|
--
|
|
|
|
-- Minimal Development Test
|
|
|
|
-- Mod: test
|
|
|
|
--
|
|
|
|
|
|
|
|
-- Try out PseudoRandom
|
|
|
|
pseudo = PseudoRandom(13)
|
|
|
|
assert(pseudo:next() == 22290)
|
|
|
|
assert(pseudo:next() == 13854)
|
|
|
|
|
|
|
|
|
2018-03-28 17:05:18 +02:00
|
|
|
--
|
|
|
|
-- HP Change Reasons
|
|
|
|
--
|
|
|
|
local expect = nil
|
2018-04-06 10:52:29 +02:00
|
|
|
local function run_hpchangereason_tests(player)
|
2018-03-28 17:05:18 +02:00
|
|
|
expect = { type = "set_hp", from = "mod" }
|
|
|
|
player:set_hp(3)
|
|
|
|
assert(expect == nil)
|
|
|
|
|
|
|
|
expect = { a = 234, type = "set_hp", from = "mod" }
|
2019-05-03 14:44:05 +02:00
|
|
|
player:set_hp(7, { a= 234 })
|
2018-03-28 17:05:18 +02:00
|
|
|
assert(expect == nil)
|
|
|
|
|
|
|
|
expect = { df = 3458973454, type = "fall", from = "mod" }
|
|
|
|
player:set_hp(10, { type = "fall", df = 3458973454 })
|
|
|
|
assert(expect == nil)
|
2018-04-06 10:52:29 +02:00
|
|
|
end
|
2018-03-28 17:05:18 +02:00
|
|
|
minetest.register_on_player_hpchange(function(player, hp, reason)
|
2018-05-16 19:36:30 +02:00
|
|
|
if not expect then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-03-28 17:05:18 +02:00
|
|
|
for key, value in pairs(reason) do
|
|
|
|
assert(expect[key] == value)
|
|
|
|
end
|
|
|
|
|
|
|
|
for key, value in pairs(expect) do
|
|
|
|
assert(reason[key] == value)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect = nil
|
|
|
|
end)
|
2018-04-06 10:52:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function run_player_meta_tests(player)
|
|
|
|
local meta = player:get_meta()
|
|
|
|
meta:set_string("foo", "bar")
|
2018-04-30 18:42:51 +02:00
|
|
|
assert(meta:contains("foo"))
|
2018-04-06 10:52:29 +02:00
|
|
|
assert(meta:get_string("foo") == "bar")
|
2018-04-30 18:42:51 +02:00
|
|
|
assert(meta:get("foo") == "bar")
|
2018-04-06 10:52:29 +02:00
|
|
|
|
|
|
|
local meta2 = player:get_meta()
|
|
|
|
assert(meta2:get_string("foo") == "bar")
|
2018-04-30 18:42:51 +02:00
|
|
|
assert(meta2:get("foo") == "bar")
|
2018-04-06 10:52:29 +02:00
|
|
|
assert(meta:equals(meta2))
|
|
|
|
assert(player:get_attribute("foo") == "bar")
|
|
|
|
|
|
|
|
meta:set_string("bob", "dillan")
|
|
|
|
assert(meta:get_string("foo") == "bar")
|
|
|
|
assert(meta:get_string("bob") == "dillan")
|
2018-04-30 18:42:51 +02:00
|
|
|
assert(meta:get("bob") == "dillan")
|
2018-04-06 10:52:29 +02:00
|
|
|
assert(meta2:get_string("foo") == "bar")
|
|
|
|
assert(meta2:get_string("bob") == "dillan")
|
2018-04-30 18:42:51 +02:00
|
|
|
assert(meta2:get("bob") == "dillan")
|
2018-04-06 10:52:29 +02:00
|
|
|
assert(meta:equals(meta2))
|
|
|
|
assert(player:get_attribute("foo") == "bar")
|
|
|
|
assert(player:get_attribute("bob") == "dillan")
|
2018-04-30 18:42:51 +02:00
|
|
|
|
|
|
|
meta:set_string("foo", "")
|
|
|
|
assert(not meta:contains("foo"))
|
|
|
|
assert(meta:get("foo") == nil)
|
|
|
|
assert(meta:get_string("foo") == "")
|
|
|
|
assert(meta:equals(meta2))
|
2018-04-06 10:52:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function run_player_tests(player)
|
|
|
|
run_hpchangereason_tests(player)
|
|
|
|
run_player_meta_tests(player)
|
|
|
|
minetest.chat_send_all("All tests pass!")
|
|
|
|
end
|
|
|
|
minetest.register_on_joinplayer(run_player_tests)
|