diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/common.lua | 63 | ||||
| -rw-r--r-- | spec/headless/deviceinit.lua | 15 | ||||
| -rw-r--r-- | spec/headless/init.lua | 13 | ||||
| -rw-r--r-- | spec/server/init.lua | 20 | ||||
| -rw-r--r-- | spec/test1_spec.lua | 62 | ||||
| -rw-r--r-- | spec/test2_spec.lua | 297 | ||||
| -rw-r--r-- | spec/test3_spec.lua | 100 | ||||
| -rw-r--r-- | spec/test4_spec.lua | 170 | ||||
| -rw-r--r-- | spec/test5_spec.lua | 108 |
9 files changed, 518 insertions, 330 deletions
diff --git a/spec/common.lua b/spec/common.lua new file mode 100644 index 0000000..4df1a7c --- /dev/null +++ b/spec/common.lua @@ -0,0 +1,63 @@ +local common = {}
+local game_bin = nil
+
+if package.config:sub(1,1) == "/" then -- linux or osx
+ game_bin = "bin/client/bin/brokengine_client"
+ server_bin = "bin/server/bin/brokengine_server"
+else -- windows
+ game_bin = "bin\\client\\bin\\brokengine_client.exe"
+ server_bin = "bin\\server\\bin\\brokengine_server.exe"
+end
+
+function common.rungame()
+ f = io.popen(game_bin .. " spec/headless","r")
+ d = f:read("*all")
+ f:close()
+ --print(d)
+ return d
+end
+
+function common.runboth()
+ --print("Running both")
+ --Do we have a race condition here? (Can client start and send it's message
+ --before the server is ready to accept?
+ f1 = io.popen(server_bin .. " spec/server","r")
+ f2 = io.popen(game_bin .. " spec/headless","r")
+ --print("Both ran...")
+ d1 = f1:read("*all")
+ d2 = f2:read("*all")
+ --print("Both read all")
+ f1:close()
+ f2:close()
+ --print("returning")
+ return d1, d2
+end
+
+function common.writegame(...)
+ f = io.open("spec/headless/init.lua","w")
+ data = {"GAME.crashy()"}
+ for _,v in pairs({...}) do
+ data[#data + 1] = v
+ end
+ data[#data + 1] = "\nGAME.exit()\n"
+ f:write(table.concat(data,"\n"))
+ f:close()
+end
+
+function common.writeserver(...)
+ f = io.open("spec/server/init.lua","w")
+ data = {...}
+ data[#data + 1] = "\nGAME.exit()\n"
+ f:write(table.concat(data,"\n"))
+ f:close()
+end
+
+function common.assert_game_runs()
+ assert.is_not_nil(common.rungame():find("\nGoodbye\n$"))
+end
+function common.assert_both_run()
+ local a,b = common.runboth()
+ assert.is_not_nil(a:find("\nGoodbye\n$"))
+ assert.is_not_nil(b:find("\nGoodbye\n$"))
+end
+return common
diff --git a/spec/headless/deviceinit.lua b/spec/headless/deviceinit.lua new file mode 100644 index 0000000..6725820 --- /dev/null +++ b/spec/headless/deviceinit.lua @@ -0,0 +1,15 @@ +return {
+ ["Anti Alias"] = 16,
+ ["Bits Per Pixel"] = 16,
+ ["Device Type"] = "BEST",
+ ["Display Adapter"] = 0,
+ ["Double Buffer"] = true,
+ ["Multithreaded"] = false,
+ ["Driver Type"] = "NULL",
+ ["Fullscreen"] = false,
+ ["Stencil Buffer"] = true,
+ ["Stereo Buffer"] = false,
+ ["VSync"] = true,
+ ["Window Width"] = 640,
+ ["Window Height"] = 480,
+}
diff --git a/spec/headless/init.lua b/spec/headless/init.lua new file mode 100644 index 0000000..a5cf357 --- /dev/null +++ b/spec/headless/init.lua @@ -0,0 +1,13 @@ +GAME.crashy()
+ local socket = net.newsocket(net.PAIR)
+ socket:connect("tcp://127.0.0.1:5555")
+ function socket:receive(stream)
+ local message = stream:readstring()
+ assert(message == "pong")
+ end
+ socket:send(function(stream)
+ stream:writestring("ping")
+ end)
+
+
+GAME.exit()
diff --git a/spec/server/init.lua b/spec/server/init.lua new file mode 100644 index 0000000..f895ba3 --- /dev/null +++ b/spec/server/init.lua @@ -0,0 +1,20 @@ + local has_ponged = false
+ local socket = net.newsocket(net.PAIR)
+ socket:bind("tcp://127.0.0.1:5555")
+ function socket:receive(stream)
+ print("Socket receive triggered")
+ has_ponged = true
+ local message = stream:readstring()
+ assert(message == "ping")
+ socket:send(function(stream2)
+ stream2:writestring("pong")
+ end)
+ end
+ function GAME.tick()
+ if has_ponged then
+ GAME.exit()
+ end
+ end
+
+
+GAME.exit()
diff --git a/spec/test1_spec.lua b/spec/test1_spec.lua index 147abbd..01d6b0d 100644 --- a/spec/test1_spec.lua +++ b/spec/test1_spec.lua @@ -1,5 +1,10 @@ -print("Hello, world!") +if not package.path:find("spec/%?%.lua;") then + print("including spec") + package.path = "./spec/?.lua;" .. package.path +end +_G.assert = assert +local common = require("common") --[[Create the headless client init file]] local f = io.open("spec/headless/deviceinit.lua","w") f:write([=[ @@ -21,44 +26,14 @@ return { ]=]) f:close() -local game_bin = nil -if package.config:sub(1,1) == "/" then -- linux or osx - game_bin = "bin/client/bin/brokengine_client" -else - game_bin = "bin\\client\\bin\\brokengine_client.exe" -end - -function rungame() - f = io.popen(game_bin .. " spec/headless","r") - d = f:read("*all") - f:close() - return d -end - -function writegame(...) - f = assert(io.open("spec/headless/init.lua","w")) - data = {"GAME.crashy()"} - for _,v in pairs({...}) do - data[#data + 1] = v - end - data[#data + 1] = "\nGAME.exit()\n" - f:write(table.concat(data)) - f:close() -end - -function assert_game_runs() - assert.truthy(rungame():find("\nGoodbye\n$")) -end - describe("Brok[en]gine",function() - it("should run",function() - writegame() - d = rungame() - assert_game_runs() + it("should run #smoke",function() + common.writegame() + common.assert_game_runs() end) - it("should provide a lua environment",function() - writegame("print(\"Hello from lua!\")") - d = rungame() + it("should provide a lua environment #smoke",function() + common.writegame("print(\"Hello from lua!\")") + d = common.rungame() assert.truthy(d:find("\nHello from lua!\n")) end) @@ -75,15 +50,16 @@ describe("Brok[en]gine",function() windows = "newwindow", }) do it("should provide functions to make gui " .. k,function() - writegame("assert(gui." .. v .. ")") - assert_game_runs() + common.writegame("assert(gui." .. v .. ")") + common.assert_game_runs() end) end it("should provide functions to get the width and height of the screen",function() - writegame("assert(scrw)") - assert_game_runs() - writegame("assert(scrh)") - assert_game_runs() + common.writegame("assert(scrw)") + common.assert_game_runs() + common.writegame("assert(scrh)") + common.assert_game_runs() end) + end) diff --git a/spec/test2_spec.lua b/spec/test2_spec.lua index 6b90878..82ca33e 100644 --- a/spec/test2_spec.lua +++ b/spec/test2_spec.lua @@ -1,195 +1,102 @@ - -do return end -local test = require("u-test") - -function rungame() - f = io.popen("bin\\client\\bin\\brokengine_client.exe spec/headless","r") - d = f:read("*all") - f:close() - return d -end - -function runboth() - f1 = io.popen("bin\\server\\bin\\brokengine_server.exe spec/server","r") - f2 = io.popen("bin\\client\\bin\\brokengine_client.exe spec/headless","r") - d1 = f1:read("*all") - d2 = f2:read("*all") - f1:close() - f2:close() - return d1, d2 -end - -function writegame(...) - f = io.open("spec/headless/init.lua","w") - data = {"GAME.crashy()"} - for _,v in pairs({...}) do - data[#data + 1] = v - end - data[#data + 1] = "\nGAME.exit()\n" - f:write(table.concat(data,"\n")) - f:close() -end - -function writeserver(...) - f = io.open("spec/server/init.lua","w") - data = {...} - --data[#data + 1] = "\nGAME.exit()\n" - f:write(table.concat(data,"\n")) - f:close() -end - -function assert_game_runs() - test.is_not_nil(rungame():find("\nGoodbye\n$")) -end -function assert_both_run() - local a,b = runboth() - test.is_not_nil(a:find("\nGoodbye\n$")) - test.is_not_nil(b:find("\nGoodbye\n$")) -end - -test.game_runs = function() - writegame("") - assert_game_runs() -end - -test.gui.elements_exist = function() - for k,v in pairs({ - buttons = "newbutton", - checkboxes = "newcheckbox", - colorselectors = "newcolorselector", - editboxes = "neweditbox", - openfiledialogs = "newfileopendialog", - images = "newiguiimage", - labels = "newlabel", - spinboxes = "newspinbox", - treeviews = "newtreeview", - windows = "newwindow", - }) do - writegame("assert(gui." .. v .. ")") - assert_game_runs() - end -end - -test.gui.screen_functions = function() - writegame("assert(scrw)") - assert_game_runs() - writegame("assert(scrh)") - assert_game_runs() -end - ---#define PAIR 1 ---#define BUS 2 ---#define PUB 3 ---#define SUB 4 ---#define PULL 5 ---#define PUSH 6 ---#define REQ 7 ---#define REP 8 ---#define RESPOND 9 ---#define SURVEY 10 -local protocols = { - "PAIR", "BUS", "PUB", "SUB", "PULL", "PUSH", "REQ", "REP", "RESPOND", "SURVEY" -} -test.net.protocols_exist = function() - for k,v in pairs(protocols) do - writegame(string.format("assert(net.%s)",v)) - assert_game_runs() - end -end - -for _,sockettype in pairs(protocols) do - for _,func in pairs({ - "bind","connect","send" - }) do - test.net[sockettype .. "_socket_has_" .. func .. "_function"] = function() - writegame(string.format([[ - local socket = net.newsocket(net.%s) - assert(socket.%s) - assert(type(socket.%s) == "function") - ]],sockettype,func,func)) - assert_game_runs() - end - end -end ---test.net.functions_exist = function() - --writegame("assert(net.newsocket and type(net.newsocket == 'function'))") - --assert_game_runs() - --for _,sockettype in pairs(protocols) do - --for _,func in pairs({ - --}) do - --writegame(string.format([[ - --local socket = net.newsocket(net.%s) - --assert(socket.%s) - --assert(type(socket.%s) == "function") - --]],sockettype,func,func)) - --assert_game_runs() - --end - --end ---end - -test.net.protocol_pair = function() - writeserver([[ - local has_ponged = false - local socket = net.newsocket(net.PAIR) - socket:bind("tcp://127.0.0.1:5555") - function socket:receive(stream) - print("Socket receive triggered") - has_ponged = true - local message = stream:readstring() - assert(message == "ping") - socket:send(function(stream2) - stream2:writestring("pong") - end) - end - function GAME.tick() - if has_ponged then - GAME.exit() - end - end - ]]) - writegame([[ - local socket = net.newsocket(net.PAIR) - socket:connect("tcp://127.0.0.1:5555") - function socket:receive(stream) - local message = stream:readstring() - assert(message == "pong") - end - socket:send(function(stream) - stream:writestring("ping") - end) - ]]) - assert_both_run() -end - ---test.net.protocol_pubsub = function() - --writeserver([[ - --local counter = 0 - --local max_count = 10000 --How long to live for, - ----since we can't detect when the user - ----sends the message - --local socket = net.newsocket(net.PUB) - --socket:bind("tcp://127.0.0.1:5555") - --function GAME.tick() - --if counter < max_count then - --counter = counter + 1 - --socket:send(function(stream) - --stream:writestring("ping") - --end) - --else - --GAME.exit() - --end - --end - --]]) - --writegame([[ - --local socket = net.newsocket(net.SUB) - --socket:connect("tcp://127.0.0.1:5555") - --local oldgameexit = GAME.exit - --socket:receive(function(stream) - --assert(stream:readstring() == "ping") - --oldgameexit() - --end) - --function GAME.exit() return end --Stop the client from exiting - --]]) ---end - -test.summary() +
+--do return end
+--local test = require("u-test")
+if not package.path:find("spec/%?%.lua;") then
+ print("including spec")
+ package.path = "./spec/?.lua;" .. package.path
+end
+local common = require("common")
+_G.assert = assert
+
+describe("gui library", function()
+ for k,v in pairs({
+ buttons = "newbutton",
+ checkboxes = "newcheckbox",
+ colorselectors = "newcolorselector",
+ editboxes = "neweditbox",
+ openfiledialogs = "newfileopendialog",
+ images = "newiguiimage",
+ labels = "newlabel",
+ spinboxes = "newspinbox",
+ treeviews = "newtreeview",
+ windows = "newwindow",
+ }) do
+ it("should have a function to create " .. k,function()
+ common.writegame("assert(gui." .. v .. ")")
+ common.assert_game_runs()
+ end)
+ end
+ it("should have a function to check the screen's width",function()
+ common.writegame("assert(scrw)")
+ common.assert_game_runs()
+ end)
+ it("should have a function to check the screen's height", function()
+ common.writegame("assert(scrh)")
+ common.assert_game_runs()
+ end)
+end)
+
+
+local protocols = {
+ "PAIR", "BUS", "PUB", "SUB", "PULL", "PUSH", "REQ", "REP", "RESPOND", "SURVEY"
+}
+describe("network library",function()
+ for _,v in pairs(protocols) do
+ it("should have a constant for the " .. v .. " protocol",function()
+ common.writegame(string.format("assert(net.%s)",v))
+ common.assert_game_runs()
+ end)
+ end
+ it("should have a function to create a new socket",function()
+ common.writegame("assert(net.newsocket)")
+ common.assert_game_runs()
+ end)
+ for _,v in pairs(protocols) do
+ for _,j in pairs{"bind","connect","send"} do
+ it(string.format("should be able to create a %s socket with a %s method",v,j))
+ common.writegame(string.format([[
+ local socket = net.newsocket(net.%s)
+ assert(socket.%s)
+ assert(type(socket.%s) == "function")
+ ]],v,j,j))
+ common.assert_game_runs()
+ end
+ end
+ it("should be able to set up a PAIR connection and send data through #smoke",function()
+ common.writeserver([[
+ local has_ponged = false
+ local socket = net.newsocket(net.PAIR)
+ socket:bind("tcp://127.0.0.1:5555")
+ function socket:receive(stream)
+ print("socket receive triggered")
+ has_ponged = true
+ local message = stream:readstring()
+ assert(message == "ping")
+ socket:send(function(stream2)
+ stream2:writestring("pong")
+ end)
+ end
+ local i = os.time()
+ function GAME.tick()
+ if has_ponged then
+ GAME.exit()
+ end
+ if i - os.time() > 5 then
+ error("Failed")
+ end
+ end
+ ]])
+ common.writegame([[
+ local socket = net.newsocket(net.PAIR)
+ socket:connect("tcp://127.0.0.1:5555")
+ function socket:receive(stream)
+ local message = stream:readstring()
+ assert(message == "pong")
+ end
+ socket:send(function(stream)
+ stream:writestring("ping")
+ end)
+ ]])
+ common.assert_both_run()
+ end)
+end)
diff --git a/spec/test3_spec.lua b/spec/test3_spec.lua index 8861b0c..e0c4c93 100644 --- a/spec/test3_spec.lua +++ b/spec/test3_spec.lua @@ -1,97 +1,13 @@ -local game_bin = nil -if package.config:sub(1,1) == "/" then -- linux or osx - game_bin = "bin/client/bin/brokengine_client" - server_bin = "bin/server/bin/brokengine_server" -else - game_bin = "bin\\client\\bin\\brokengine_client.exe" - server_bin = "bin\\server\\bin\\brokengine_server.exe" +if not package.path:find("spec/%?%.lua;") then + print("including spec") + package.path = "./spec/?.lua;" .. package.path end +local common = require("common") +_G.assert = assert -function rungame() - f = io.popen(game_bin .. " spec/headless","r") - d = f:read("*all") - f:close() - return d -end - -function runboth() - --print("Running both") - --Do we have a race condition here? (Can client start and send it's message - --before the server is ready to accept? - f1 = io.popen(server_bin .. " spec/server","r") - f2 = io.popen(game_bin .. " spec/headless","r") - --print("Both ran...") - d1 = f1:read("*all") - d2 = f2:read("*all") - --print("Both read all") - f1:close() - f2:close() - --print("returning") - return d1, d2 -end - -function writegame(...) - f = io.open("spec/headless/init.lua","w") - data = {"GAME.crashy()"} - for _,v in pairs({...}) do - data[#data + 1] = v - end - data[#data + 1] = "\nGAME.exit()\n" - f:write(table.concat(data,"\n")) - f:close() -end - -function writeserver(...) - f = io.open("spec/server/init.lua","w") - data = {...} - data[#data + 1] = "\nGAME.exit()\n" - f:write(table.concat(data,"\n")) - f:close() -end - -function assert_game_runs() - test.is_not_nil(rungame():find("\nGoodbye\n$")) -end -function assert_both_run() - local a,b = runboth() - assert.is_not_nil(a:find("\nGoodbye\n$")) - assert.is_not_nil(b:find("\nGoodbye\n$")) -end -describe("networking",function() - it("should communicate with PAIR sockets",function() - writeserver([[ - local has_ponged = false - local socket = net.newsocket(net.PAIR) - socket:bind("tcp://127.0.0.1:5555") - function socket:receive(stream) - print("Socket receive triggered") - has_ponged = true - local message = stream:readstring() - assert(message == "ping") - socket:send(function(stream2) - stream2:writestring("pong") - end) - end - function GAME.tick() - if has_ponged then - GAME.exit() - end - end - ]]) - --print("writing game...") - writegame([[ - local socket = net.newsocket(net.PAIR) - socket:connect("tcp://127.0.0.1:5555") - function socket:receive(stream) - local message = stream:readstring() - assert(message == "pong") - end - socket:send(function(stream) - stream:writestring("ping") - end) - ]]) - --print("asserting both run...") - assert_both_run() +describe("physics library",function() + it("should have methods to create a physics box",function() + end) end) diff --git a/spec/test4_spec.lua b/spec/test4_spec.lua new file mode 100644 index 0000000..93c4e70 --- /dev/null +++ b/spec/test4_spec.lua @@ -0,0 +1,170 @@ +local game_bin = nil
+if package.config:sub(1,1) == "/" then -- linux or osx
+ game_bin = "bin/client/bin/brokengine_client"
+else
+ game_bin = "bin\\client\\bin\\brokengine_client.exe"
+end
+
+function rungame()
+ f = io.popen(game_bin .. " spec/headless","r")
+ d = f:read("*all")
+ f:close()
+ return d
+end
+
+function writegame(...)
+ f = assert(io.open("spec/headless/init.lua","w"))
+ data = {"GAME.crashy()"}
+ for _,v in pairs({...}) do
+ data[#data + 1] = v
+ end
+ data[#data + 1] = "\nGAME.exit()\n"
+ f:write(table.concat(data))
+ f:close()
+end
+
+function assert_game_runs()
+ local results = rungame()
+ assert.truthy(results:find("\nGoodbye\n$"), results)
+end
+
+gui_api = {
+ button = {
+ func = "gui.newbutton",
+ params = {
+ {
+ name = "dimensions",
+ required = true,
+ type = "rect4d",
+ },
+ {
+ name = "default_text",
+ required = true,
+ type = "string",
+ },
+ {
+ name = "parent",
+ required = false,
+ type = "guielement",
+ },
+ },
+ callbacks = {
+ "onClick", "onFocus", "onUnfocus", "onHover", "onLeave"
+ }
+ },
+ fileopendialog = {
+ func = "gui.newfileopendialog",
+ params = {
+ {
+ name = "title",
+ required = false,
+ type = "string",
+ },
+ {
+ name = "path",
+ required = false,
+ type = "filepath",
+ },
+ {
+ name = "parent",
+ required = false,
+ type = "guielement",
+ },
+ {
+ name = "modal",
+ required = false,
+ type = "boolean",
+ }
+ },
+ callbacks = {
+ "onDirectorySelect","onFileSelect","onCanceled"
+ }
+ },
+ label = {
+ func = "gui.newlabel",
+ params = {
+ {
+ name = "pos",
+ required = true,
+ type = "rect4d",
+ },
+ {
+ name = "text",
+ required = true,
+ type = "string",
+ },
+ {
+ name = "parent",
+ required = false,
+ type = "guielement",
+ }
+ },
+ callbacks = {
+
+ }
+ },
+}
+
+--[[For some reason these can't be local, _ENV dosn't find them.]]
+local function mr()
+ return string.format("%d",math.floor(math.random()*100))
+end
+function generate_rect4d()
+ return string.format("{{%d,%d},{%d,%d}}",mr(),mr(),mr(),mr())
+end
+function generate_string()
+ return "\"test!\""
+end
+function generate_guielement()
+ return "gui.getroot()"
+end
+function generate_filepath()
+ return "\".\""
+end
+function generate_boolean()
+ return "true"
+end
+describe("Brok[en]gine",function()
+ describe("gui system",function()
+ for k,v in pairs(gui_api) do
+ describe(k,function()
+ local paramstring = {}
+ local num_optional_args = 0
+ local num_required_args = 0
+ for i,j in pairs(v.params) do
+ assert(_ENV["generate_" .. j.type], "Could not find a generator for type: " .. j.type)
+ if j.required then
+ num_required_args = num_required_args + 1
+ else
+ num_optional_args = num_optional_args + 1
+ end
+ paramstring[#paramstring + 1] = _ENV["generate_" .. j.type]()
+ end
+ for i = num_required_args, num_required_args + num_optional_args do
+ it(string.format(" with %d params", i),function()
+ local truncated_params = {}
+ for j = 1, i do
+ truncated_params[j] = paramstring[j]
+ end
+ local game_file = string.format("%s(%s)",v.func,table.concat(truncated_params, ","))
+ --print("running:",game_file)
+ writegame(game_file)
+ assert_game_runs()
+ end)
+ it(string.format(" 100 elemants with %d params", i),function()
+ local game_file = {}
+ for j = 1,100 do
+ local truncated_params = {}
+ for k = 1, i do
+ truncated_params[k] = paramstring[k]
+ end
+ game_file[#game_file + 1] = string.format("%s(%s)",v.func,table.concat(truncated_params, ","))
+ end
+ writegame(table.concat(game_file,"\n"))
+ assert_game_runs()
+ end)
+ end
+ end)
+ end
+ end)
+end)
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)
|
