From a8c714bc8982f936b26293410d75bb486e0077db Mon Sep 17 00:00:00 2001 From: ell <77150506+ellraiser@users.noreply.github.com> Date: Fri, 17 Nov 2023 00:11:32 +0000 Subject: [PATCH] change to exact rgba comparison for visual tests --- testing/classes/TestMethod.lua | 21 ++++++--------------- testing/tests/graphics.lua | 9 ++------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/testing/classes/TestMethod.lua b/testing/classes/TestMethod.lua index 023bae2bd..a5c8a4c3f 100644 --- a/testing/classes/TestMethod.lua +++ b/testing/classes/TestMethod.lua @@ -273,29 +273,20 @@ TestMethod = { ) local iw = imgdata:getWidth()-2 local ih = imgdata:getHeight()-2 + local tolerance = 0 -- @NOTE could pass in optional tolerance i.e. 1/255 for ix=2,iw do for iy=2,ih do local ir, ig, ib, ia = imgdata:getPixel(ix, iy) - local tolerance = { - {expected:getPixel(ix, iy)}, - {expected:getPixel(ix+1, iy+1)}, - {expected:getPixel(ix+1, iy)}, - {expected:getPixel(ix+1, iy-1)}, - {expected:getPixel(ix, iy+1)}, - {expected:getPixel(ix, iy-1)}, - {expected:getPixel(ix-1, iy+1)}, - {expected:getPixel(ix-1, iy)}, - {expected:getPixel(ix-1, iy-1)} - } + local er, eg, eb, ea = expected:getPixel(ix, iy) local has_match_r = false local has_match_g = false local has_match_b = false local has_match_a = false for t=1,9 do - if ir == tolerance[t][1] then has_match_r = true; end - if ig == tolerance[t][2] then has_match_g = true; end - if ib == tolerance[t][3] then has_match_b = true; end - if ia == tolerance[t][4] then has_match_a = true; end + if ir >= er - tolerance and ir <= er + tolerance then has_match_r = true; end + if ig >= eg - tolerance and ig <= eg + tolerance then has_match_g = true; end + if ib >= eb - tolerance and ib <= eb + tolerance then has_match_b = true; end + if ia >= ea - tolerance and ia <= ea + tolerance then has_match_a = true; end end local matching = has_match_r and has_match_g and has_match_b and has_match_a local ymatch = '' diff --git a/testing/tests/graphics.lua b/testing/tests/graphics.lua index 911fd6fde..4417c6f44 100644 --- a/testing/tests/graphics.lua +++ b/testing/tests/graphics.lua @@ -558,7 +558,6 @@ love.test.graphics.Video = function(test) video:rewind() test:assertEquals(0, video:tell(), 'check video rewind') video:setFilter('nearest', 'nearest', 1) - video:play() -- check actuall drawing with the vid local canvas = love.graphics.newCanvas(500, 500) love.graphics.setCanvas(canvas) @@ -570,11 +569,7 @@ love.test.graphics.Video = function(test) black = {{0,0},{495,0},{495,499},{0,499}}, red = {{499,0},{499,499}} }, 'video draw') - -- @NOTE on github runners the video doesnt seem to draw at all for any platform - -- however it passes locally - if GITHUB_RUNNER == false then - test:compareImg(imgdata) - end + test:compareImg(imgdata) end @@ -709,7 +704,7 @@ end love.test.graphics.draw = function(test) local canvas1 = love.graphics.newCanvas(32, 32) local canvas2 = love.graphics.newCanvas(32, 32) - local transform = love.math.newTransform( ) + local transform = love.math.newTransform() transform:translate(16, 0) transform:scale(0.5, 0.5) love.graphics.setCanvas(canvas1)