diff --git a/.luacheckrc b/.luacheckrc index 0da515bcb..e73f559bf 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -108,8 +108,6 @@ exclude_files = { files["spec/unit/*"].std = "+busted" files["spec/unit/*"].globals = { "package", - "assertAlmostEquals", - "assertNotAlmostEquals", "requireBackgroundRunner", "stopBackgroundRunner", } diff --git a/Makefile b/Makefile index 63ec44511..9db57678d 100644 --- a/Makefile +++ b/Makefile @@ -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'"; \ diff --git a/spec/unit/commonrequire.lua b/spec/unit/commonrequire.lua index bdac7dff4..6b21e8dad 100644 --- a/spec/unit/commonrequire.lua +++ b/spec/unit/commonrequire.lua @@ -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 diff --git a/spec/unit/koptinterface_spec.lua b/spec/unit/koptinterface_spec.lua index 1406e3971..43d3f83c7 100644 --- a/spec/unit/koptinterface_spec.lua +++ b/spec/unit/koptinterface_spec.lua @@ -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() diff --git a/spec/unit/readerview_spec.lua b/spec/unit/readerview_spec.lua index 8dae1345a..37f9ce1ab 100644 --- a/spec/unit/readerview_spec.lua +++ b/spec/unit/readerview_spec.lua @@ -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)