Minetest-WorldEditAdditions/.tests/Vector3/snap_to.test.lua

36 lines
809 B
Lua
Raw Normal View History

2021-06-26 13:40:14 +00:00
local Vector3 = require("worldeditadditions.utils.vector3")
describe("Vector3.snap_to", function()
it("should snap_to a positive vector", function()
local a = Vector3.new(3.1, 4.75, 5.9)
assert.are.same(
2021-06-26 13:44:40 +00:00
Vector3.new(0, 0, 10),
a:snap_to(10)
2021-06-26 13:40:14 +00:00
)
end)
it("should snap_to a negative vector", function()
local a = Vector3.new(-2.5, -4.2, -5.3)
assert.are.same(
2021-06-26 13:44:40 +00:00
Vector3.new(0, -6, -6),
a:snap_to(6)
2021-06-26 13:40:14 +00:00
)
end)
it("should work with integers", function()
local a = Vector3.new(3, 4, 5)
assert.are.same(
2021-06-26 13:44:40 +00:00
Vector3.new(3, 3, 6),
a:snap_to(3)
2021-06-26 13:40:14 +00:00
)
end)
it("should return a new Vector3 instance", function()
local a = Vector3.new(3.1, 4.7, 5.99999)
local result = a:snap_to(3)
assert.are.same(
2021-06-26 13:44:40 +00:00
Vector3.new(3, 6, 6),
result
2021-06-26 13:40:14 +00:00
)
assert.are_not.equal(result, a)
end)
end)