From 83f6144cfe0e91df991e107e66b73d9e037ea969 Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 3 Mar 2020 18:16:25 +0000 Subject: Add edge detection tests for wipesides These should be nice and robust to small changes that are still valid, as they don't depend on the output not changing, only on the detected sides being within appropriate limits. --- testdata/0002.png | Bin 0 -> 760657 bytes wipesides_test.go | 45 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 testdata/0002.png diff --git a/testdata/0002.png b/testdata/0002.png new file mode 100644 index 0000000..fb40761 Binary files /dev/null and b/testdata/0002.png differ diff --git a/wipesides_test.go b/wipesides_test.go index 4906c5b..36d884e 100644 --- a/wipesides_test.go +++ b/wipesides_test.go @@ -13,23 +13,24 @@ import ( "image/png" "os" "testing" + + "rescribe.xyz/integralimg" ) func TestWipeSides(t *testing.T) { cases := []struct { - name string orig string golden string thresh float64 wsize int }{ - {"integralwipesides", "testdata/pg2.png", "testdata/pg2_integralwipesides_t0.02_w5.png", 0.02, 5}, - {"integralwipesides", "testdata/pg2.png", "testdata/pg2_integralwipesides_t0.05_w5.png", 0.05, 5}, - {"integralwipesides", "testdata/pg2.png", "testdata/pg2_integralwipesides_t0.05_w25.png", 0.05, 25}, + {"testdata/pg2.png", "testdata/pg2_integralwipesides_t0.02_w5.png", 0.02, 5}, + {"testdata/pg2.png", "testdata/pg2_integralwipesides_t0.05_w5.png", 0.05, 5}, + {"testdata/pg2.png", "testdata/pg2_integralwipesides_t0.05_w25.png", 0.05, 25}, } for _, c := range cases { - t.Run(fmt.Sprintf("%s_%0.2f_%d", c.name, c.thresh, c.wsize), func(t *testing.T) { + t.Run(fmt.Sprintf("Exact/%s_%0.2f_%d", c.orig, c.thresh, c.wsize), func(t *testing.T) { var actual *image.Gray orig, err := decode(c.orig) if err != nil { @@ -56,4 +57,38 @@ func TestWipeSides(t *testing.T) { } }) } + testedgecases := []struct { + filename string + minleft int + maxleft int + minright int + maxright int + thresh float64 + wsize int + }{ + {"testdata/0002.png", 36, 250, 967, 998, 0.02, 5}, + } + + for _, c := range testedgecases { + t.Run(fmt.Sprintf("Edge/%s_%0.2f_%d", c.filename, c.thresh, c.wsize), func(t *testing.T) { + img, err := decode(c.filename) + if err != nil { + t.Fatalf("Could not open file %s: %v\n", c.filename, err) + } + integral := integralimg.ToIntegralImg(img) + leftedge, rightedge := findedges(integral, c.wsize, c.thresh) + if leftedge < c.minleft { + t.Errorf("Left edge %d < minimum %d", leftedge, c.minleft) + } + if leftedge > c.maxleft { + t.Errorf("Left edge %d > maximum %d", leftedge, c.maxleft) + } + if rightedge < c.minright { + t.Errorf("Right edge %d < minimum %d", rightedge, c.minright) + } + if rightedge > c.maxright { + t.Errorf("Right edge %d > maximum %d", rightedge, c.maxright) + } + }) + } } -- cgit v1.2.1-24-ge1ad