[spec] Replace custom assert[Not]AlmostEquals with assert.is[_not].near (#3885)

Also, change "make static-check" to also check the tests.
pull/3887/head
Frode Austvik 6 years ago committed by Frans de Jonge
parent 88dee4194d
commit f12f317e9d

@ -108,8 +108,6 @@ exclude_files = {
files["spec/unit/*"].std = "+busted"
files["spec/unit/*"].globals = {
"package",
"assertAlmostEquals",
"assertNotAlmostEquals",
"requireBackgroundRunner",
"stopBackgroundRunner",
}

@ -413,7 +413,7 @@ po:
static-check:
@if which luacheck > /dev/null; then \
luacheck -q {reader,setupkoenv,datastorage}.lua frontend plugins; \
luacheck -q {reader,setupkoenv,datastorage}.lua frontend plugins spec; \
else \
echo "[!] luacheck not found. "\
"you can install it with 'luarocks install luacheck'"; \

@ -24,32 +24,6 @@ Screen:init()
local Input = require("device").input
Input.dummy = true
function assertAlmostEquals(expected, actual, margin)
if type(actual) ~= 'number' or type(expected) ~= 'number'
or type(margin) ~= 'number' then
error('assertAlmostEquals: must supply only number arguments.', 2)
end
assert(math.abs(expected - actual) <= margin,
'Values are not almost equal\n'
.. 'Expected: ' .. expected .. ' with margin of ' .. margin
.. ', received: ' .. actual
)
end
function assertNotAlmostEquals(expected, actual, margin)
if type(actual) ~= 'number' or type(expected) ~= 'number'
or type(margin) ~= 'number' then
error('assertAlmostEquals: must supply only number arguments.', 2)
end
assert(math.abs(expected - actual) > margin,
'Values are almost equal\n'
.. 'Expected: ' .. expected .. ' with margin of ' .. margin
.. ', received: ' .. actual
)
end
package.unload = function(module)
if type(module) ~= "string" then return false end
package.loaded[module] = nil

@ -30,10 +30,10 @@ describe("Koptinterface module", function()
it("should get auto bbox", function()
local auto_bbox = Koptinterface:getAutoBBox(doc, 1)
assertAlmostEquals(22, auto_bbox.x0, 0.5)
assertAlmostEquals(38, auto_bbox.y0, 0.5)
assertAlmostEquals(548, auto_bbox.x1, 0.5)
assertAlmostEquals(1387, auto_bbox.y1, 0.5)
assert.is.near(22, auto_bbox.x0, 0.5)
assert.is.near(38, auto_bbox.y0, 0.5)
assert.is.near(548, auto_bbox.x1, 0.5)
assert.is.near(1387, auto_bbox.y1, 0.5)
end)
it("should get semi auto bbox", function()
@ -47,10 +47,10 @@ describe("Koptinterface module", function()
}
local bbox = Koptinterface:getSemiAutoBBox(doc, 1)
assertNotAlmostEquals(semiauto_bbox.x0, bbox.x0, 0.5)
assertNotAlmostEquals(semiauto_bbox.y0, bbox.y0, 0.5)
assertNotAlmostEquals(semiauto_bbox.x1, bbox.x1, 0.5)
assertNotAlmostEquals(semiauto_bbox.y1, bbox.y1, 0.5)
assert.is_not.near(semiauto_bbox.x0, bbox.x0, 0.5)
assert.is_not.near(semiauto_bbox.y0, bbox.y0, 0.5)
assert.is_not.near(semiauto_bbox.x1, bbox.x1, 0.5)
assert.is_not.near(semiauto_bbox.y1, bbox.y1, 0.5)
end)
it("should render optimized page to de-watermark", function()

@ -81,7 +81,7 @@ describe("Readerview module", function()
},
}
assert.are.same(saved_ctx, ctx)
assertAlmostEquals(zoom, 0.95011876484561, 0.0001)
assert.is.near(0.95011876484561, zoom, 0.0001)
assert.is.same(view.state.page, 1)
assert.is.same(view.visible_area.x, 0)
@ -128,7 +128,7 @@ describe("Readerview module", function()
}
assert.are.same(saved_ctx, ctx)
assertAlmostEquals(zoom, 0.95011876484561, 0.0001)
assert.is.near(0.95011876484561, zoom, 0.0001)
assert.is.same(view.state.page, 1)
assert.is.same(view.visible_area.x, 0)

Loading…
Cancel
Save