Skip to content

Commit d567458

Browse files
committed
all: use cmpimg.EqualApprox for jpg
jpg comparison is finicky, especially across architectures. use EqualApprox (with a delta=0.1) so tests pass on darwin. Signed-off-by: Sebastien Binet <binet@cern.ch>
1 parent 540f801 commit d567458

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

vg/vg_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import (
1919
"gonum.org/v1/plot/vg"
2020
)
2121

22+
const (
23+
cmpDelta = 0.1
24+
)
25+
2226
// TestLineWidth tests output against test images generated by
2327
// running tests with -tag good.
2428
func TestLineWidth(t *testing.T) {
@@ -68,7 +72,7 @@ func TestLineWidth(t *testing.T) {
6872
t.Fatalf("failed to read test image [%s]: %v\n", name, err)
6973
}
7074

71-
ok, err := cmpimg.Equal(typ, buf.Bytes(), want)
75+
ok, err := cmpimg.EqualApprox(typ, buf.Bytes(), want, cmpDelta)
7276
if err != nil {
7377
t.Fatalf("failed to run cmpimg test [%s]: %v\n", name, err)
7478
}

vg/vgimg/vgimg_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import (
2525
"gonum.org/v1/plot/vg/vgimg"
2626
)
2727

28+
const (
29+
delta = 0.1
30+
)
31+
2832
var cache = font.NewCache(liberation.Collection())
2933

3034
func TestIssue179(t *testing.T) {
@@ -50,7 +54,7 @@ func TestIssue179(t *testing.T) {
5054
t.Fatal(err)
5155
}
5256

53-
ok, err := cmpimg.Equal("jpg", b.Bytes(), want)
57+
ok, err := cmpimg.EqualApprox("jpg", b.Bytes(), want, delta)
5458
if err != nil {
5559
t.Fatal(err)
5660
}
@@ -154,7 +158,7 @@ func TestIssue687(t *testing.T) {
154158
fname = "testdata/issue687.png"
155159
size = 500
156160
)
157-
cmpimg.CheckPlot(func() {
161+
cmpimg.CheckPlotApprox(func() {
158162
p := plot.New()
159163
p.Title.Text = "Issue 687"
160164
p.X.Label.Text = "X"
@@ -175,5 +179,5 @@ func TestIssue687(t *testing.T) {
175179
t.Fatal(err)
176180
}
177181

178-
}, t, filepath.Base(fname))
182+
}, t, delta, filepath.Base(fname))
179183
}

0 commit comments

Comments
 (0)