| 1 |
--[[ Copyright (c) 2014 Pavel "sofo" Schoffer |
| 2 |
|
| 3 |
Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 4 |
this software and associated documentation files (the "Software"), to deal in |
| 5 |
the Software without restriction, including without limitation the rights to |
| 6 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 7 |
of the Software, and to permit persons to whom the Software is furnished to do |
| 8 |
so, subject to the following conditions: |
| 9 |
|
| 10 |
The above copyright notice and this permission notice shall be included in all |
| 11 |
copies or substantial portions of the Software. |
| 12 |
|
| 13 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 |
SOFTWARE. --]] |
| 20 |
require("corsixth") |
| 21 |
|
| 22 |
require("class_test_base") |
| 23 |
|
| 24 |
require("utility") |
| 25 |
require("announcer") |
| 26 |
require("entity") |
| 27 |
require("entities/object") |
| 28 |
require("entities/machine") |
| 29 |
|
| 30 |
describe("object.lua: ", function() |
| 31 |
local stub_world = {map = {}} |
| 32 |
local stub_hospital = {world = stub_world} |
| 33 |
_G["Hospital"] = stub_hospital |
| 34 |
|
| 35 |
local tile_x, tile_y, direction = 10, 10, "west" |
| 36 |
|
| 37 |
local function createMachineWithFakeInput() |
| 38 |
stub(stub_world, "addObjectToTile") |
| 39 |
stub(stub_world, "clearCaches") |
| 40 |
local offset = {0, 0} |
| 41 |
local orientation = { |
| 42 |
render_attach_position = offset, |
| 43 |
use_position = {0, 0} |
| 44 |
} |
| 45 |
local fake_object_type = { |
| 46 |
ticks = false, |
| 47 |
idle_animations = {west = true}, |
| 48 |
orientations = {west = orientation} |
| 49 |
} |
| 50 |
return Machine(stub_hospital, fake_object_type, tile_x, tile_y, direction) |
| 51 |
end |
| 52 |
|
| 53 |
it("can update dynamic Info", function() |
| 54 |
local machine = createMachineWithFakeInput() |
| 55 |
machine:incrementUsageCounts() |
| 56 |
machine:updateDynamicInfo() |
| 57 |
assert.are.equal(1, machine.times_used) |
| 58 |
assert.are.equal(1, machine.total_usage) |
| 59 |
end) |
| 60 |
it("can transfer state", function() |
| 61 |
local machine1 = createMachineWithFakeInput() |
| 62 |
machine1:updateDynamicInfo() |
| 63 |
local machine2 = createMachineWithFakeInput() |
| 64 |
|
| 65 |
machine2:setState(machine1:getState()) |
| 66 |
|
| 67 |
assert.are.equal(machine1.times_used, machine2.times_used) |
| 68 |
assert.are.equal(machine1.total_usage, machine2.total_usage) |
| 69 |
end) |
| 70 |
it("setting null state doesn't clear values", function() |
| 71 |
local machine = createMachineWithFakeInput() |
| 72 |
machine:incrementUsageCounts() |
| 73 |
machine:updateDynamicInfo() |
| 74 |
|
| 75 |
assert.are.equal(1, machine.times_used) |
| 76 |
assert.are.equal(1, machine.total_usage) |
| 77 |
|
| 78 |
machine:setState(nil) |
| 79 |
|
| 80 |
assert.are.equal(1, machine.times_used) |
| 81 |
assert.are.equal(1, machine.total_usage) |
| 82 |
end) |
| 83 |
end) |