diff --git a/lib/libs/math.lua b/lib/libs/math.lua index c107d78..f6540e9 100644 --- a/lib/libs/math.lua +++ b/lib/libs/math.lua @@ -8,4 +8,8 @@ rbxMath.clamp = function(n, min, max) return math.min(max, math.max(min, n)) end -return rbxMath \ No newline at end of file +rbxMath.sign = function(n) + return n > 0 and 1 or n < 0 and -1 or 0 +end + +return rbxMath diff --git a/lib/libs/math_spec.lua b/lib/libs/math_spec.lua index f1b7b62..2d7e90a 100644 --- a/lib/libs/math_spec.lua +++ b/lib/libs/math_spec.lua @@ -18,4 +18,22 @@ describe("libs.math", function() assert.are.equals(0.5, math.clamp(0.5, 0, 1)) end) end) -end) \ No newline at end of file + + describe("sign", function() + it("should be a function", function() + assert.is_function(math.sign) + end) + + it("should return 1 for a positive number", function() + assert.are.equals(1, math.sign(2)) + end) + + it("should return -1 for a negative number", function() + assert.are.equals(-1, math.sign(-2)) + end) + + it("should return 0 for 0.", function() + assert.are.equals(0, math.sign(0)) + end) + end) +end)