diff options
author | Nick White <git@njw.name> | 2020-03-03 18:16:25 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2020-03-03 18:16:25 +0000 |
commit | 83f6144cfe0e91df991e107e66b73d9e037ea969 (patch) | |
tree | abc4f781d41d7edaa2585484fb4a8760e2361c63 /wipesides_test.go | |
parent | a12fb10e9355d12db1dfd2d8871fb73c50b4cfc3 (diff) |
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.
Diffstat (limited to 'wipesides_test.go')
-rw-r--r-- | wipesides_test.go | 45 |
1 files changed, 40 insertions, 5 deletions
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) + } + }) + } } |