Skip to content

Commit

Permalink
Authorize 1% of pixels error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluebugs committed Oct 31, 2023
1 parent 9276afc commit dd8ee04
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 0 additions & 3 deletions cmd/htmx-fan/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build e2e
// +build e2e

package main

import (
Expand Down
Binary file modified cmd/htmx-fan/testdata/screenshot-index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 24 additions & 3 deletions pkg/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ func VerifyImage(t *testing.T, resultPath string) {
masterBound, masterPixels := get(t, masterPath)
resultBound, resultPixels := get(t, resultPath)

assert.Len(t, resultPixels, len(masterPixels))
if len(resultPixels) == 0 || len(masterPixels) == 0 {
return
}

assert.Len(t, resultPixels, len(masterPixels))
assert.Equal(t, masterBound, resultBound)
assert.Equal(t, masterPixels, resultPixels)
if masterBound != resultBound {
return
}

ratio := compare(masterPixels, resultPixels)
assert.LessOrEqual(t, ratio, 1)

if !t.Failed() {
os.Remove(resultPath)
Expand Down Expand Up @@ -73,3 +77,20 @@ func pixels(i image.Image) ([]uint8, error) {
return nil, fmt.Errorf("unsupported image type %T", i)
}
}

func compare(img1, img2 []uint8) int {
overallChange := 0

for i := 0; i < len(img1); i++ {
overallChange += diffUInt8(img1[i], img2[i])
}

return 100 * overallChange / len(img1)
}

func diffUInt8(x, y uint8) int {
if x != y {
return 1
}
return 0
}

0 comments on commit dd8ee04

Please sign in to comment.