Browse Source

change to exact rgba comparison for visual tests

ell 1 year ago
parent
commit
a8c714bc89
2 changed files with 8 additions and 22 deletions
  1. 6 15
      testing/classes/TestMethod.lua
  2. 2 7
      testing/tests/graphics.lua

+ 6 - 15
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 = ''

+ 2 - 7
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)