diff options
Diffstat (limited to 'resources/images/color_test.go')
-rw-r--r-- | resources/images/color_test.go | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/resources/images/color_test.go b/resources/images/color_test.go index c3860a82c..cbbc76cf9 100644 --- a/resources/images/color_test.go +++ b/resources/images/color_test.go @@ -46,7 +46,7 @@ func TestHexStringToColor(t *testing.T) { c.Run(test.arg, func(c *qt.C) { c.Parallel() - result, err := hexStringToColor(test.arg) + result, err := hexStringToColorGo(test.arg) if b, ok := test.expect.(bool); ok && !b { c.Assert(err, qt.Not(qt.IsNil)) @@ -70,13 +70,18 @@ func TestColorToHexString(t *testing.T) { {color.White, "#ffffff"}, {color.Black, "#000000"}, {color.RGBA{R: 0x42, G: 0x87, B: 0xf5, A: 0xff}, "#4287f5"}, + + // 50% opacity. + // Note that the .Colors (dominant colors) received from the Image resource + // will always have an alpha value of 0xff. + {color.RGBA{R: 0x42, G: 0x87, B: 0xf5, A: 0x80}, "#4287f580"}, } { test := test c.Run(test.expect, func(c *qt.C) { c.Parallel() - result := ColorToHexString(test.arg) + result := ColorGoToHexString(test.arg) c.Assert(result, qt.Equals, test.expect) }) @@ -91,9 +96,9 @@ func TestAddColorToPalette(t *testing.T) { c.Assert(AddColorToPalette(color.White, palette), qt.HasLen, 2) - blue1, _ := hexStringToColor("34c3eb") - blue2, _ := hexStringToColor("34c3eb") - white, _ := hexStringToColor("fff") + blue1, _ := hexStringToColorGo("34c3eb") + blue2, _ := hexStringToColorGo("34c3eb") + white, _ := hexStringToColorGo("fff") c.Assert(AddColorToPalette(white, palette), qt.HasLen, 2) c.Assert(AddColorToPalette(blue1, palette), qt.HasLen, 3) @@ -104,10 +109,18 @@ func TestReplaceColorInPalette(t *testing.T) { c := qt.New(t) palette := color.Palette{color.White, color.Black} - offWhite, _ := hexStringToColor("fcfcfc") + offWhite, _ := hexStringToColorGo("fcfcfc") ReplaceColorInPalette(offWhite, palette) c.Assert(palette, qt.HasLen, 2) c.Assert(palette[0], qt.Equals, offWhite) } + +func TestColorLuminance(t *testing.T) { + c := qt.New(t) + c.Assert(hexStringToColor("#000000").Luminance(), qt.Equals, 0.0) + c.Assert(hexStringToColor("#768a9a").Luminance(), qt.Equals, 0.24361603589088263) + c.Assert(hexStringToColor("#d5bc9f").Luminance(), qt.Equals, 0.5261577672685374) + c.Assert(hexStringToColor("#ffffff").Luminance(), qt.Equals, 1.0) +} |