diff options
Diffstat (limited to 'resources/image_test.go')
-rw-r--r-- | resources/image_test.go | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/resources/image_test.go b/resources/image_test.go index 231a06453..7e26c1f55 100644 --- a/resources/image_test.go +++ b/resources/image_test.go @@ -85,9 +85,16 @@ func TestImageTransformBasic(t *testing.T) { assertWidthHeight(c, img, w, h) } - colors, err := image.Colors() + gotColors, err := image.Colors() c.Assert(err, qt.IsNil) - c.Assert(colors, qt.DeepEquals, []string{"#2d2f33", "#a49e93", "#d39e59", "#a76936", "#737a84", "#7c838b"}) + expectedColors := images.HexStringsToColors("#2d2f33", "#a49e93", "#d39e59", "#a76936", "#737a84", "#7c838b") + c.Assert(len(gotColors), qt.Equals, len(expectedColors)) + for i := range gotColors { + c1, c2 := gotColors[i], expectedColors[i] + c.Assert(c1.ColorHex(), qt.Equals, c2.ColorHex()) + c.Assert(c1.ColorGo(), qt.DeepEquals, c2.ColorGo()) + c.Assert(c1.Luminance(), qt.Equals, c2.Luminance()) + } c.Assert(image.RelPermalink(), qt.Equals, "/a/sunset.jpg") c.Assert(image.ResourceType(), qt.Equals, "image") @@ -445,6 +452,24 @@ func TestImageExif(t *testing.T) { getAndCheckExif(c, image) } +func TestImageColorsLuminance(t *testing.T) { + c := qt.New(t) + + _, image := fetchSunset(c) + c.Assert(image, qt.Not(qt.IsNil)) + colors, err := image.Colors() + c.Assert(err, qt.IsNil) + c.Assert(len(colors), qt.Equals, 6) + var prevLuminance float64 + for i, color := range colors { + luminance := color.Luminance() + c.Assert(err, qt.IsNil) + c.Assert(luminance > 0, qt.IsTrue) + c.Assert(luminance, qt.Not(qt.Equals), prevLuminance, qt.Commentf("i=%d", i)) + prevLuminance = luminance + } +} + func BenchmarkImageExif(b *testing.B) { getImages := func(c *qt.C, b *testing.B, fs afero.Fs) []images.ImageResource { spec := newTestResourceSpec(specDescriptor{fs: fs, c: c}) |