[spec] Test all aspects of Math module (#3683)

pull/3681/head
Frans de Jonge 6 years ago committed by GitHub
parent ca6a486806
commit 720fd5d826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,34 @@ describe("Math module", function()
Math = require("optmath")
end)
describe("tmin", function()
it("should return nil on empty table", function()
assert.is_nil(Math.tmin({}))
end)
it("should get minimum element in table", function()
assert.are.same(5, Math.tmin({9,7,10,11,5,7}))
end)
it("should get minimum element in table using custom function", function()
assert.are.same(5,
Math.tmin({"9","7","10","11","5","7"}, function(a,b)
return tonumber(a) > tonumber(b)
end))
end)
end)
describe("tmax", function()
it("should return nil on empty table", function()
assert.is_nil(Math.tmin({}))
end)
it("should get maximum element in table", function()
assert.are.same(4, Math.tmax({9,7,10,11,5,7}))
end)
it("should get maximum element in table using custom function", function()
assert.are.same(4,
Math.tmax({"9","7","10","11","5","7"}, function(a,b)
return tonumber(a) < tonumber(b)
end))
end)
end)
it("should round away from zero", function()
assert.are.same(2, Math.roundAwayFromZero(1.5))
assert.are.same(2, Math.roundAwayFromZero(1.4))

Loading…
Cancel
Save