Skip to content

Commit

Permalink
resources/images: Fix TestColorLuminance on s390x
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Apr 19, 2024
1 parent 11aa893 commit faf9fed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions htesting/hqt/checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package hqt
import (
"errors"
"fmt"
"math"
"reflect"
"strings"

Expand All @@ -38,6 +39,11 @@ var IsSameType qt.Checker = &typeChecker{
argNames: []string{"got", "want"},
}

// IsSameFloat64 asserts that two float64 values are equal within a small delta.
var IsSameFloat64 = qt.CmpEquals(cmp.Comparer(func(a, b float64) bool {
return math.Abs(a-b) < 0.0001
}))

type argNames []string

func (a argNames) ArgNames() []string {
Expand Down
9 changes: 5 additions & 4 deletions resources/images/color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"

qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/htesting/hqt"
)

func TestHexStringToColor(t *testing.T) {
Expand Down Expand Up @@ -119,8 +120,8 @@ func TestReplaceColorInPalette(t *testing.T) {

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)
c.Assert(hexStringToColor("#000000").Luminance(), hqt.IsSameFloat64, 0.0)
c.Assert(hexStringToColor("#768a9a").Luminance(), hqt.IsSameFloat64, 0.24361603589088263)
c.Assert(hexStringToColor("#d5bc9f").Luminance(), hqt.IsSameFloat64, 0.5261577672685374)
c.Assert(hexStringToColor("#ffffff").Luminance(), hqt.IsSameFloat64, 1.0)
}

0 comments on commit faf9fed

Please sign in to comment.