From 80789508b9655d25629223b9dcc84b4cfb77ce45 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 29 Jun 2020 15:29:03 -0400 Subject: Updates for mdoc Also more tests --- spec/test5_spec.lua | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 spec/test5_spec.lua (limited to 'spec/test5_spec.lua') diff --git a/spec/test5_spec.lua b/spec/test5_spec.lua new file mode 100644 index 0000000..b4b9333 --- /dev/null +++ b/spec/test5_spec.lua @@ -0,0 +1,108 @@ +--[[ +physics things +]] +package.path = "./spec/?.lua;" .. package.path +_G.assert = assert +local common = require("common") + +local spawn_1_box = [[ +GAME.crashy() +local box = phys.newphysbox({8,8,8}, {0,0,0}, 0) +GAME.exit() +]] + +local spawn_several_boxes = [[ +GAME.crashy() +for i = 1,100 do + phys.newphysbox({8,8,8}, {0,10 * i,0}, 0) +end +GAME.exit() +]] + +describe("physics",function() + it("should be able to spawn a physics box on the client",function() + common.writegame(spawn_1_box) + common.assert_game_runs() + end) + it("should be able to spawn several physics boxes on the client", function() + common.writegame(spawn_several_boxes) + common.assert_game_runs() + end) + +end) + +local getpos_exists = [[ +GAME.crashy() +local box = phys.newphysbox({8,8,8}, {0,0,0}, 0) +local pos = box:getpos() +for i = 1,3 do + assert(pos[i] == 0, "Position is not 0") +end +GAME.exit() +]] +local getpos_works = [[ +GAME.crashy() +local box = phys.newphysbox({8,8,8}, {10,20,30}, 0) +local pos = box:getpos() +assert(pos[1] == 10) +assert(pos[2] == 20) +assert(pos[3] == 30) +GAME.exit() +]] +local setpos_exists = [[ +GAME.crashy() +local box = phys.newphysbox({8,8,8}, {10,20,30}, 0) +box:setpos({0,0,0}) +local pos = box:getpos() +for i = 1,3 do + assert(pos[i] == 0) +end +GAME.exit() +]] +local setpos_works = [[ +GAME.crashy() +local box = phys.newphysbox({8,8,8}, {0,0,0}, 0) +box:setpos({10,20,30}) +local pos = box:getpos() +assert(pos[1] == 10) +assert(pos[2] == 20) +assert(pos[3] == 30) +GAME.exit() +]] +local falls = [[ +GAME.crashy() +local box = phys.newphysbox({8,8,8}, {0,10,0}, 1) +local ticks = 0 +GAME.tick = function() + print("Tick running...") + if box:getpos()[2] < 0 then + print("Getpos[2] is less, it is ", box:getpos()[2]) + GAME.exit() + end + ticks = ticks + 1 + assert(ticks < 1) +end +]] +describe("physics box", function() + it("should have a .getpos() function",function() + common.writegame(getpos_exists) + common.assert_game_runs() + end) + it("should have a .getpos() function that returns the box's position",function() + common.writegame(getpos_works) + common.assert_game_runs() + end) + it("should have a .setpos() function",function() + common.writegame(setpos_exists) + common.assert_game_runs() + end) + it("should have a .setpos() function that sets the box's position",function() + common.writegame(setpos_works) + common.assert_game_runs() + end) + it("should fall when given mass",function() + --print("About to write should fall when given mass...") + common.writegame(falls) + common.assert_game_runs() + end) +end) -- cgit v1.2.3-70-g09d2