|
@@ -48,6 +48,25 @@ describe("vector", function()
|
|
|
assert.same({ x = 41, y = 52, z = 63 }, vector.offset(vector.new(1, 2, 3), 40, 50, 60))
|
|
|
end)
|
|
|
|
|
|
+ it("to_string()", function()
|
|
|
+ local v = vector.new(1, 2, 3.14)
|
|
|
+ assert.same("(1, 2, 3.14)", vector.to_string(v))
|
|
|
+ end)
|
|
|
+
|
|
|
+ it("from_string()", function()
|
|
|
+ local v = vector.new(1, 2, 3.14)
|
|
|
+ assert.same({v, 13}, {vector.from_string("(1, 2, 3.14)")})
|
|
|
+ assert.same({v, 12}, {vector.from_string("(1,2 ,3.14)")})
|
|
|
+ assert.same({v, 12}, {vector.from_string("(1,2,3.14,)")})
|
|
|
+ assert.same({v, 11}, {vector.from_string("(1 2 3.14)")})
|
|
|
+ assert.same({v, 15}, {vector.from_string("( 1, 2, 3.14 )")})
|
|
|
+ assert.same({v, 15}, {vector.from_string(" ( 1, 2, 3.14) ")})
|
|
|
+ assert.same({vector.new(), 8}, {vector.from_string("(0,0,0) ( 1, 2, 3.14) ")})
|
|
|
+ assert.same({v, 22}, {vector.from_string("(0,0,0) ( 1, 2, 3.14) ", 8)})
|
|
|
+ assert.same({v, 22}, {vector.from_string("(0,0,0) ( 1, 2, 3.14) ", 9)})
|
|
|
+ assert.same(nil, vector.from_string("nothing"))
|
|
|
+ end)
|
|
|
+
|
|
|
-- This function is needed because of floating point imprecision.
|
|
|
local function almost_equal(a, b)
|
|
|
if type(a) == "number" then
|