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

81 lines
1.7 KiB
Lua
Raw Normal View History

2022-09-19 02:18:48 +02:00
local Vector3 = require("worldeditadditions_core.utils.vector3")
describe("Vector3.add", function()
it("should add 2 positive vectors", function()
local a = Vector3.new(3, 4, 5)
local b = Vector3.new(1, 1, 1)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(4, 5, 6),
a:add(b)
)
end)
it("should support the add operator", function()
local a = Vector3.new(3, 4, 5)
local b = Vector3.new(1, 1, 1)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(4, 5, 6),
a + b
)
end)
it("should work with floats", function()
local a = Vector3.new(3.5, 4.5, 5.5)
local b = Vector3.new(1.1, 1.1, 1.1)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(4.6, 5.6, 6.6),
a + b
)
end)
it("should work with scalar a", function()
local a = 2
local b = Vector3.new(6, 7, 8)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(8, 9, 10),
a + b
)
end)
it("should work with scalar b", function()
local a = Vector3.new(6, 7, 8)
local b = 2
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(8, 9, 10),
a + b
)
end)
it("should handle negative b", function()
local a = Vector3.new(3, 4, 5)
local b = Vector3.new(-1, -1, -1)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(2, 3, 4),
a + b
)
end)
it("should handle negative a", function()
local a = Vector3.new(-3, -4, -5)
local b = Vector3.new(1, 1, 1)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(-2, -3, -4),
a + b
)
end)
it("should handle negative a and b", function()
local a = Vector3.new(-3, -4, -5)
local b = Vector3.new(-1, -1, -1)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(-4, -5, -6),
a + b
)
end)
it("should return a new Vector3 instance", function()
local a = Vector3.new(3, 4, 5)
local b = Vector3.new(1, 1, 1)
local result = a + b
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(4, 5, 6),
result
)
assert.are_not.equal(result, a)
assert.are_not.equal(result, b)
end)
end)