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

81 lines
1.8 KiB
Lua
Raw Normal View History

2022-09-19 02:18:48 +02:00
local Vector3 = require("worldeditadditions_core.utils.vector3")
describe("Vector3.divide", function()
it("should divide 2 positive vectors", function()
local a = Vector3.new(30, 40, 50)
local b = Vector3.new(2, 2, 2)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(15, 20, 25),
a:divide(b)
)
end)
it("should work with the div alias", function()
local a = Vector3.new(30, 40, 50)
local b = Vector3.new(2, 2, 2)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(15, 20, 25),
a:div(b)
)
end)
it("should work with scalar a", function()
2022-09-19 02:31:47 +02:00
local a = 100
local b = Vector3.new(4, 5, 2)
assert.are.same(
2022-09-19 02:31:47 +02:00
Vector3.new(25, 20, 50),
2021-06-26 15:40:14 +02:00
a / b
)
end)
it("should work with scalar b", function()
local a = Vector3.new(6, 8, 10)
local b = 2
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(3, 4, 5),
a / b
)
end)
it("should support the divide operator", function()
local a = Vector3.new(10, 12, 14)
local b = Vector3.new(2, 3, 2)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(5, 4, 7),
a / b
)
end)
it("should handle negative b", function()
local a = Vector3.new(30, 40, 50)
local b = Vector3.new(-2, -2, -2)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(-15, -20, -25),
a / b
)
end)
it("should handle negative a", function()
local a = Vector3.new(-30, -40, -50)
local b = Vector3.new(2, 4, 2)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(-15, -10, -25),
a / b
)
end)
it("should handle negative a and b", function()
local a = Vector3.new(-30, -40, -50)
local b = Vector3.new(-2, -2, -2)
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(15, 20, 25),
a / b
)
end)
it("should return a new Vector3 instance", function()
local a = Vector3.new(9, 12, 15)
local b = Vector3.new(3, 3, 3)
local result = a / b
assert.are.same(
2021-06-26 15:40:14 +02:00
Vector3.new(3, 4, 5),
result
)
assert.are_not.equal(result, a)
assert.are_not.equal(result, b)
end)
end)