2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00

test: add optmath spec stub (#2950)

* test: add optmath spec stub
This commit is contained in:
Frans de Jonge 2017-06-13 18:40:56 +02:00 committed by Hzj_jie
parent 2096a27b65
commit ed0ba6737e
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,32 @@
describe("Math module", function()
setup(function()
require("commonrequire")
Math = require("optmath")
end)
it("should round away from zero", function()
assert.are.same(2, Math.roundAwayFromZero(1.5))
assert.are.same(2, Math.roundAwayFromZero(1.4))
assert.are.same(-2, Math.roundAwayFromZero(-1.4))
assert.are.same(1, Math.roundAwayFromZero(0.2))
assert.are.same(-1, Math.roundAwayFromZero(-0.2))
end)
it("should round", function()
assert.are.same(2, Math.round(1.5))
assert.are.same(1, Math.round(1.4))
assert.are.same(-1, Math.round(-1.4))
assert.are.same(0, Math.round(0.2))
assert.are.same(0, Math.round(-0.2))
end)
it("should determine odd or even", function()
assert.are.same("odd", Math.oddEven(1))
assert.are.same("even", Math.oddEven(2))
assert.are.same("odd", Math.oddEven(3))
assert.are.same("even", Math.oddEven(4))
assert.are.same("even", Math.oddEven(-4))
assert.are.same("odd", Math.oddEven(-3))
assert.are.same("even", Math.oddEven(0))
end)
end)

View File

@ -11,6 +11,8 @@ describe("util module", function()
assert.is_equal(util.stripePunctuations("\"hello, world?\""), "hello, world")
assert.is_equal(util.stripePunctuations("“你好“"), "你好")
assert.is_equal(util.stripePunctuations("“你好?“"), "你好")
assert.is_equal(util.stripePunctuations(""), "")
assert.is_equal(util.stripePunctuations(nil), nil)
end)
it("should split string with patterns", function()