Files
cat-haven/test/spec/voxel_spec.lua
T
2026-07-23 21:23:01 +00:00

102 lines
2.8 KiB
Lua

local test_helper = require('test.test_helper')
local mocks = test_helper.mocks
local utils = test_helper.utils
describe('Voxel Module', function()
local voxel
before_each(function()
-- Mock LOVR
_G.lovr = mocks.lovr
voxel = require('src.voxel.init')
end)
it('should create voxel texture', function()
local color = { 1, 0, 0 }
local texture = voxel.createVoxelTexture(color)
assert.are.equal('texture', texture.type)
assert.are.equal(64, texture.image.width)
assert.are.equal(64, texture.image.height)
end)
it('should initialize textures for furniture', function()
mocks.setupFilesystem()
require('src.core')
voxel.init()
assert.are_not.equal(nil, voxel.textures['bed'])
assert.are_not.equal(nil, voxel.textures['cat_tree'])
end)
it('should create cube mesh', function()
local mesh = voxel.cubeMesh
assert.are.equal('mesh', mesh.type)
assert.are.equal(36, #mesh.indices) -- 12 triangles
end)
it('should render world', function()
mocks.setupFilesystem()
require('src.core')
local pass = utils.createMockPass()
voxel.renderWorld(pass)
-- Should draw floor and walls
end)
it('should render furniture', function()
mocks.setupFilesystem()
require('src.core')
local pass = utils.createMockPass()
voxel.renderFurniture(pass)
end)
it('should render cats', function()
mocks.setupFilesystem()
require('src.core')
local pass = utils.createMockPass()
voxel.renderCats(pass)
end)
it('should raycast furniture', function()
local start = { 0, 0, 0 }
local direction = { 0, 0, -1 }
local maxDistance = 10
local result = voxel.raycast(start, direction, maxDistance)
assert.are.equal('table', type(result))
end)
it('should raycast cats', function()
local start = { 0, 0, 0 }
local direction = { 0, 0, -1 }
local maxDistance = 10
local result = voxel.raycast(start, direction, maxDistance)
assert.are.equal('table', type(result))
end)
it('should handle nil inputs', function()
local result = voxel.raycast(nil, nil, nil)
assert.are.equal('table', type(result))
assert.are.equal(0, #result)
end)
it('should handle zero distance direction', function()
local start = { 0, 0, 0 }
local direction = { 0, 0, 0 }
local maxDistance = 10
local result = voxel.raycast(start, direction, maxDistance)
assert.are.equal('table', type(result))
end)
it('should sort raycast results by distance', function()
local start = { 0, 0, 0 }
local direction = { 0, 0, -1 }
local maxDistance = 10
local result = voxel.raycast(start, direction, maxDistance)
for i = 2, #result do
assert.is_true(result[i].distance >= result[i-1].distance)
end
end)
end)