Skip to content

Commit

Permalink
[spec] Test all aspects of Math module (#3683)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frenzie committed Feb 22, 2018
1 parent ca6a486 commit 720fd5d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/unit/optmath_spec.lua
Expand Up @@ -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))
Expand Down

0 comments on commit 720fd5d

Please sign in to comment.