mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
[spec] Test all aspects of Math module (#3683)
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user