diff options
author | rubenwardy <rw@rubenwardy.com> | 2020-01-18 02:09:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-18 02:09:18 +0000 |
commit | 1173ff0c13a07dec2ede3166378dc5f50fff37b3 (patch) | |
tree | df83476a7389fce570fb2bb6852e0de024d20e98 /builtin/common/tests/vector_spec.lua | |
parent | 6d472b1840971a087841ea7feee5a921fb82b84a (diff) | |
download | minetest-1173ff0c13a07dec2ede3166378dc5f50fff37b3.tar.gz minetest-1173ff0c13a07dec2ede3166378dc5f50fff37b3.tar.bz2 minetest-1173ff0c13a07dec2ede3166378dc5f50fff37b3.zip |
Add Lua unit tests to builtin using busted (#9184)
Diffstat (limited to 'builtin/common/tests/vector_spec.lua')
-rw-r--r-- | builtin/common/tests/vector_spec.lua | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/builtin/common/tests/vector_spec.lua b/builtin/common/tests/vector_spec.lua new file mode 100644 index 000000000..79f032f28 --- /dev/null +++ b/builtin/common/tests/vector_spec.lua @@ -0,0 +1,46 @@ +_G.vector = {} +dofile("builtin/common/vector.lua") + +describe("vector", function() + describe("new()", function() + it("constructs", function() + assert.same({ x = 0, y = 0, z = 0 }, vector.new()) + assert.same({ x = 1, y = 2, z = 3 }, vector.new(1, 2, 3)) + assert.same({ x = 3, y = 2, z = 1 }, vector.new({ x = 3, y = 2, z = 1 })) + + local input = vector.new({ x = 3, y = 2, z = 1 }) + local output = vector.new(input) + assert.same(input, output) + assert.are_not.equal(input, output) + end) + + it("throws on invalid input", function() + assert.has.errors(function() + vector.new({ x = 3 }) + end) + + assert.has.errors(function() + vector.new({ d = 3 }) + end) + end) + end) + + it("equal()", function() + local function assertE(a, b) + assert.is_true(vector.equals(a, b)) + end + local function assertNE(a, b) + assert.is_false(vector.equals(a, b)) + end + + assertE({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) + assertE({x = -1, y = 0, z = 1}, {x = -1, y = 0, z = 1}) + local a = { x = 2, y = 4, z = -10 } + assertE(a, a) + assertNE({x = -1, y = 0, z = 1}, a) + end) + + it("add()", function() + assert.same({ x = 2, y = 4, z = 6 }, vector.add(vector.new(1, 2, 3), { x = 1, y = 2, z = 3 })) + end) +end) |