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

38 lines
1.1 KiB
Lua
Raw Permalink Normal View History

2022-09-19 00:18:48 +00:00
local Vector3 = require("worldeditadditions_core.utils.vector3")
2021-06-26 15:56:26 +00:00
-- To find these numbers, in Javascript:
-- function t(x) { return Math.sqrt((x*x)*3); }
-- for(let i = 0; i < 1000000000; i++) { let r = t(i); if(Math.floor(r) === r) console.log(`i ${i}, r ${r}`); }
describe("Vector3.unit", function()
it("should work with a positive vector", function()
local a = Vector3.new(10, 10, 10)
assert.are.same(
Vector3.new(57735, 57735, 57735),
a:unit():multiply(100000):floor()
)
end)
it("should work with a the normalise alias", function()
local a = Vector3.new(10, 10, 10)
assert.are.same(
Vector3.new(57735, 57735, 57735),
a:normalise():multiply(100000):floor()
)
end)
it("should work with a negative vector", function()
local a = Vector3.new(10, 10, 10)
assert.are.same(
Vector3.new(57735, 57735, 57735),
a:unit():multiply(100000):floor()
)
end)
it("should work with a mixed vector", function()
local a = Vector3.new(-371635731, 371635731, -371635731)
assert.are.same(
Vector3.new(-57736, 57735, -57736),
a:unit():multiply(100000):floor()
)
end)
end)