From 1fe7dcdd23691212e8393559fc9d7d5100981386 Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 3 Aug 2020 15:49:55 +0100 Subject: Add more Sum() tests, and further correct bugs found from it The implementation should be bug-free now. Of course, I thought that previously, then found more, so we shall see. There are more tests, though, and they definitely pass, so that's a good start. --- integralimg_test.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'integralimg_test.go') diff --git a/integralimg_test.go b/integralimg_test.go index bd8a983..35b353d 100644 --- a/integralimg_test.go +++ b/integralimg_test.go @@ -70,11 +70,25 @@ func TestSum(t *testing.T) { draw.Draw(imgplus, b, img, b.Min, draw.Src) draw.Draw(integral, b, img, b.Min, draw.Src) - sumimg := imgplus.sum(b) - sumint := integral.Sum(b) + cases := []struct { + name string + r image.Rectangle + }{ + {"fullimage", b}, + {"small", image.Rect(1, 1, 5, 5)}, + {"toobig", image.Rect(0, 0, 2000, b.Dy())}, + {"toosmall", image.Rect(-1, -1, 4, 5)}, + {"small2", image.Rect(0, 0, 4, 4)}, + } - if sumimg != sumint { - t.Errorf("Sum of integral image differs to regular image: regular: %d, integral: %d\n", sumimg, sumint) + for _, c := range cases{ + t.Run(c.name, func(t *testing.T) { + sumimg := imgplus.sum(c.r) + sumint := integral.Sum(c.r) + if sumimg != sumint { + t.Errorf("Sum of integral image differs to regular image: regular: %d, integral: %d\n", sumimg, sumint) + } + }) } } -- cgit v1.2.1-24-ge1ad