local test_helper = require('test.test_helper') local mocks = test_helper.mocks local utils = test_helper.utils describe('Core Module', function() local core setup(function() mocks.setupFilesystem() core = require('src.core') end) it('should initialize game state', function() core.init() assert.are.equal(0, core.state.gameTime) assert.are.equal(2, #core.state.cats) assert.are.equal(0, #core.state.furniture) end) it('should spawn cats', function() local initialCount = #core.state.cats core.spawnCat() assert.are.equal(initialCount + 1, #core.state.cats) end) it('should generate cat names', function() local name = core.generateCatName() assert.are_not.equal(nil, name:find(' ')) end) it('should remove cats', function() local catId = core.state.cats[1].id local result = core.removeCat(catId) assert.is_true(result) assert.are.equal(1, #core.state.cats) end) it('should add furniture', function() local furn = core.addFurniture('bed', { x = 0, y = 0, z = 0 }) assert.are_not.equal(nil, furn) end) it('should reject invalid furniture type', function() local furn = core.addFurniture('invalid_type', { x = 0, y = 0, z = 0 }) assert.is_false(furn) end) it('should save game', function() local result = core.saveGame() assert.is_true(result) end) it('should load game', function() core.saveGame() local result = core.loadGame() assert.is_true(result) end) it('should handle missing save file', function() local result = core.loadGame() assert.is_false(result) end) it('should toggle pause', function() core.togglePause() assert.is_true(core.state.isPaused) core.togglePause() assert.is_false(core.state.isPaused) end) it('should get happiness percentage', function() local happiness = core.getHappinessPercentage() assert.is_true(happiness >= 0) assert.is_true(happiness <= 100) end) it('should calculate happiness with zero cats', function() core.state.cats = {} core.calculateHouseHappiness() assert.are.equal(0, core.state.house.totalHappiness) end) it('should check cat departures', function() local cat = utils.createMockCat({ needs = { comfort = 0.05, hunger = 0.5 } }) table.insert(core.state.cats, cat) local initialCount = #core.state.cats core.checkCatDepartures() assert.is_true(#core.state.cats < initialCount) end) it('should handle nil cat in update', function() core.state.cats = { nil } core.update(0.1) end) it('should handle nil cat in happiness calculation', function() core.state.cats = { nil } core.calculateHouseHappiness() end) it('should handle nil cat in removeCat', function() local result = core.removeCat(999) assert.is_false(result) end) it('should handle nil core in update', function() _G.core = nil core.update(0.1) end) it('should handle nil cat module', function() _G.cat = nil core.update(0.1) end) it('should handle nil ui module', function() _G.ui = nil core.update(0.1) end) it('should handle nil voxel module', function() _G.voxel = nil core.update(0.1) end) it('should handle nil audio module', function() _G.audio = nil core.update(0.1) end) it('should handle nil house module', function() _G.house = nil core.update(0.1) end) it('should handle empty furniture list', function() core.state.furniture = {} core.calculateHouseHappiness() end) it('should handle nil needs in cat', function() local cat = utils.createMockCat() cat.needs = nil table.insert(core.state.cats, cat) core.calculateHouseHappiness() end) it('should handle nil personality in cat', function() local cat = utils.createMockCat() cat.personality = nil table.insert(core.state.cats, cat) cat:updateNeeds() end) it('should handle nil furniture in cat ai behavior', function() core.state.furniture = nil local cat = utils.createMockCat() cat:aiBehavior() end) end)