local test_helper = require('test.test_helper') local mocks = test_helper.mocks local utils = test_helper.utils describe('House Module', function() local house before_each(function() house = require('src.house.init') end) it('should create furniture', function() local type = { id = 'bed', name = 'Bed', baseHappiness = 0.7, size = { 1, 0.3, 1 } } local furn = house.createFurniture(type, { x = 0, y = 0, z = 0 }) assert.are.equal('bed', furn.type.id) assert.are.equal(1, furn.upgradeLevel) end) it('should upgrade furniture', function() local type = { id = 'bed', name = 'Bed', baseHappiness = 0.7, size = { 1, 0.3, 1 } } local furn = house.createFurniture(type, { x = 0, y = 0, z = 0 }) local oldContribution = furn.happinessContribution furn:upgrade() assert.are.equal(2, furn.upgradeLevel) assert.is_true(furn.happinessContribution > oldContribution) end) it('should limit furniture upgrades to 3', function() local type = { id = 'bed', name = 'Bed', baseHappiness = 0.7, size = { 1, 0.3, 1 } } local furn = house.createFurniture(type, { x = 0, y = 0, z = 0 }) furn:upgrade() furn:upgrade() local result = furn:upgrade() assert.is_false(result) assert.are.equal(3, furn.upgradeLevel) end) it('should serialize furniture', function() local type = { id = 'bed', name = 'Bed', baseHappiness = 0.7, size = { 1, 0.3, 1 } } local furn = house.createFurniture(type, { x = 0, y = 0, z = 0 }) local serialized = furn:serialize() assert.are.equal('bed', serialized.typeId) assert.are.equal(1, serialized.upgradeLevel) end) it('should deserialize furniture', function() mocks.setupFilesystem() require('src.core') local type = { id = 'bed', name = 'Bed', baseHappiness = 0.7, size = { 1, 0.3, 1 } } local furn = house.createFurniture(type, { x = 0, y = 0, z = 0 }) local serialized = furn:serialize() local deserialized = house.deserializeFurniture(serialized) assert.are.equal('bed', deserialized.type.id) assert.are.equal(1, deserialized.upgradeLevel) end) it('should check furniture placement bounds', function() local canPlace, reason = house.canPlaceFurniture({ x = 0, y = 0, z = 0 }, { 1, 1, 1 }) assert.is_true(canPlace) end) it('should reject furniture out of bounds', function() local canPlace, reason = house.canPlaceFurniture({ x = 100, y = 0, z = 100 }, { 1, 1, 1 }) assert.is_false(canPlace) assert.are.equal('out of bounds', reason) end) it('should detect furniture collision', function() mocks.setupFilesystem() require('src.core') local type = { id = 'bed', name = 'Bed', baseHappiness = 0.7, size = { 1, 0.3, 1 } } house.createFurniture(type, { x = 0, y = 0, z = 0 }) local canPlace, reason = house.canPlaceFurniture({ x = 0, y = 0, z = 0 }, { 1, 1, 1 }) assert.is_false(canPlace) assert.are.equal('collision', reason) end) it('should place furniture', function() mocks.setupFilesystem() require('src.core') local furn = house.placeFurniture('bed', { x = 0, y = 0, z = 0 }) assert.are_not.equal(nil, furn) end) it('should reject invalid furniture type', function() local furn = house.placeFurniture('invalid_type', { x = 0, y = 0, z = 0 }) assert.are.equal(nil, furn) end) it('should detect collision with furniture', function() local result = house.checkCollision({ x = 0, y = 0, z = 0 }, { 1, 1, 1 }) assert.is_false(result) end) it('should interact with furniture', function() local furn = house.interactWithFurniture({ x = 0, y = 0, z = 0 }) assert.are.equal(nil, furn) end) it('should handle nil furniture type', function() local furn = house.createFurniture(nil, { x = 0, y = 0, z = 0 }) assert.are.equal(nil, furn) end) it('should handle nil data in deserialize', function() local furn = house.deserializeFurniture(nil) assert.are.equal(nil, furn) end) it('should handle nil core in canPlaceFurniture', function() local canPlace, reason = house.canPlaceFurniture({ x = 0, y = 0, z = 0 }, { 1, 1, 1 }) assert.is_false(canPlace) end) it('should handle nil core in checkCollision', function() local result = house.checkCollision({ x = 0, y = 0, z = 0 }, { 1, 1, 1 }) assert.is_false(result) end) it('should handle nil core in interactWithFurniture', function() local furn = house.interactWithFurniture({ x = 0, y = 0, z = 0 }) assert.are.equal(nil, furn) end) end)