parse_relative_axis_name: write tests

This commit is contained in:
Starbeamrainbowlabs 2021-11-08 00:16:51 +00:00
parent be81e6dfaa
commit 4fb59a160f
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 458 additions and 0 deletions

View file

@ -0,0 +1,142 @@
local z_pos = {
right = {
axis = "x",
sign = 1
},
x = 0.30876246094704,
y = -0.22614130377769,
up = {
axis = "y",
sign = 1
},
left = {
axis = "x",
sign = -1
},
back = {
axis = "z",
sign = -1
},
front = {
axis = "z",
sign = 1
},
down = {
axis = "y",
sign = -1
},
z = 0.92386466264725,
facing = {
axis = "z",
sign = 1
}
}
local x_pos = {
right = {
axis = "z",
sign = -1
},
x = 0.9800808429718,
y = -0.095324546098709,
up = {
axis = "y",
sign = 1
},
left = {
axis = "z",
sign = 1
},
back = {
axis = "x",
sign = -1
},
front = {
axis = "x",
sign = 1
},
down = {
axis = "y",
sign = -1
},
z = -0.17422623932362,
facing = {
axis = "x",
sign = 1
}
}
local z_neg = {
right = {
axis = "x",
sign = -1
},
x = -0.29956161975861,
y = -0.16453117132187,
up = {
axis = "y",
sign = 1,
},
left = {
axis = "x",
sign = 1,
},
back = {
axis = "z",
sign = 1
},
front = {
axis = "z",
sign = -1
},
down = {
axis = "y",
sign = -1
},
z = -0.93978309631348,
facing = {
axis = "z",
sign = -1
}
}
local x_neg = {
right = {
axis = "z",
sign = 1
},
x = -0.96041119098663,
y = -0.20227454602718,
up = {
axis = "y",
sign = 1
},
left = {
axis = "z",
sign = -1
},
back = {
axis = "x",
sign = 1
},
front = {
axis = "x",
sign = -1
},
down = {
axis = "y",
sign = -1
},
z = 0.19156044721603,
facing = {
axis = "x",
sign = -1
}
}
return {
x_pos = x_pos,
z_pos = z_pos,
x_neg = x_neg,
z_neg = z_neg
}

View file

@ -0,0 +1,315 @@
local Vector3 = require("worldeditadditions.utils.vector3")
local facing_dirs = dofile("./.tests/parse/axes/include_facing_dirs.lua")
local axes = require("worldeditadditions.utils.parse.axes")
local parse_relative_axis_name = axes.parse_relative_axis_name
describe("parse_relative_axis_name", function()
it("should work with up", function()
local success, result = parse_relative_axis_name(
"up",
facing_dirs.x_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 1, 0),
result
)
end)
it("should work with down", function()
local success, result = parse_relative_axis_name(
"down",
facing_dirs.x_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, -1, 0),
result
)
end)
-- ██ ██ ██████ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██
-- ███ ██████ ██ ██ ███████
-- ██ ██ ██ ██ ██ ██
-- ██ ██ ███████ ██ ██████ ███████
it("should work with positive x → front", function()
local success, result = parse_relative_axis_name(
"front",
facing_dirs.x_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(1, 0, 0),
result
)
end)
it("should work with positive x → ?", function()
local success, result = parse_relative_axis_name(
"?",
facing_dirs.x_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(1, 0, 0),
result
)
end)
it("should work with positive x → back", function()
local success, result = parse_relative_axis_name(
"back",
facing_dirs.x_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(-1, 0, 0),
result
)
end)
it("should work with positive x → left", function()
local success, result = parse_relative_axis_name(
"left",
facing_dirs.x_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 0, 1),
result
)
end)
it("should work with positive x → right", function()
local success, result = parse_relative_axis_name(
"right",
facing_dirs.x_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 0, -1),
result
)
end)
-- ██ ██ ███ ██ ███████ ██████
-- ██ ██ ████ ██ ██ ██
-- ███ ██ ██ ██ █████ ██ ███
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ███████ ██ ████ ███████ ██████
it("should work with negative x → front", function()
local success, result = parse_relative_axis_name(
"front",
facing_dirs.x_neg
)
assert.is_true(success)
assert.are.same(
Vector3.new(-1, 0, 0),
result
)
end)
it("should work with negative x → ?", function()
local success, result = parse_relative_axis_name(
"?",
facing_dirs.x_neg
)
assert.is_true(success)
assert.are.same(
Vector3.new(-1, 0, 0),
result
)
end)
it("should work with negative x → back", function()
local success, result = parse_relative_axis_name(
"back",
facing_dirs.x_neg
)
assert.is_true(success)
assert.are.same(
Vector3.new(1, 0, 0),
result
)
end)
it("should work with negative x → left", function()
local success, result = parse_relative_axis_name(
"left",
facing_dirs.x_neg
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 0, -1),
result
)
end)
it("should work with negative x → right", function()
local success, result = parse_relative_axis_name(
"right",
facing_dirs.x_neg
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 0, 1),
result
)
end)
-- ███████ ██████ ██████ ███████
-- ███ ██ ██ ██ ██ ██
-- ███ ██████ ██ ██ ███████
-- ███ ██ ██ ██ ██
-- ███████ ███████ ██ ██████ ███████
it("should work with positive z → front", function()
local success, result = parse_relative_axis_name(
"front",
facing_dirs.z_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 0, 1),
result
)
end)
it("should work with positive z → ?", function()
local success, result = parse_relative_axis_name(
"?",
facing_dirs.z_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 0, 1),
result
)
end)
it("should work with positive z → back", function()
local success, result = parse_relative_axis_name(
"back",
facing_dirs.z_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 0, -1),
result
)
end)
it("should work with positive z → left", function()
local success, result = parse_relative_axis_name(
"left",
facing_dirs.z_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(-1, 0, 0),
result
)
end)
it("should work with positive z → right", function()
local success, result = parse_relative_axis_name(
"right",
facing_dirs.z_pos
)
assert.is_true(success)
assert.are.same(
Vector3.new(1, 0, 0),
result
)
end)
-- ███████ ███ ██ ███████ ██████
-- ███ ████ ██ ██ ██
-- ███ ██ ██ ██ █████ ██ ███
-- ███ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ██ ████ ███████ ██████
it("should work with negative z → front", function()
local success, result = parse_relative_axis_name(
"front",
facing_dirs.z_neg
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 0, -1),
result
)
end)
it("should work with negative z → ?", function()
local success, result = parse_relative_axis_name(
"?",
facing_dirs.z_neg
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 0, -1),
result
)
end)
it("should work with negative z → back", function()
local success, result = parse_relative_axis_name(
"back",
facing_dirs.z_neg
)
assert.is_true(success)
assert.are.same(
Vector3.new(0, 0, 1),
result
)
end)
it("should work with negative z → left", function()
local success, result = parse_relative_axis_name(
"left",
facing_dirs.z_neg
)
assert.is_true(success)
assert.are.same(
Vector3.new(1, 0, 0),
result
)
end)
it("should work with negative z → right", function()
local success, result = parse_relative_axis_name(
"right",
facing_dirs.z_neg
)
assert.is_true(success)
assert.are.same(
Vector3.new(-1, 0, 0),
result
)
end)
it("returns an error with invalid input", function()
local success, result = parse_relative_axis_name("cheese")
assert.is_false(success)
assert.are.same(
"string",
type(result)
)
end)
it("returns an error with no input", function()
local success, result = parse_relative_axis_name()
assert.is_false(success)
assert.are.same(
"string",
type(result)
)
end)
it("returns an error with input of the wrong type", function()
local success, result = parse_relative_axis_name(5)
assert.is_false(success)
assert.are.same(
"string",
type(result)
)
end)
it("returns an error with input of the wrong type again", function()
local success, result = parse_relative_axis_name({ "yay", "tests are very useful" })
assert.is_false(success)
assert.are.same(
"string",
type(result)
)
end)
end)

View file

@ -29,6 +29,7 @@ function worldeditadditions.player_dir(name)
dir.down = {axis="y",sign=-1}
return dir
end
-- /lua print(worldeditadditions.vector.tostring(minetest.get_player_by_name(myname):get_look_dir()))
--- DEPRICATED =================================================================