Skip to content

Commit faf9fed

Browse files
committed
resources/images: Fix TestColorLuminance on s390x
1 parent 11aa893 commit faf9fed

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

htesting/hqt/checkers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package hqt
1616
import (
1717
"errors"
1818
"fmt"
19+
"math"
1920
"reflect"
2021
"strings"
2122

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

42+
// IsSameFloat64 asserts that two float64 values are equal within a small delta.
43+
var IsSameFloat64 = qt.CmpEquals(cmp.Comparer(func(a, b float64) bool {
44+
return math.Abs(a-b) < 0.0001
45+
}))
46+
4147
type argNames []string
4248

4349
func (a argNames) ArgNames() []string {

resources/images/color_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"testing"
1919

2020
qt "github.com/frankban/quicktest"
21+
"github.com/gohugoio/hugo/htesting/hqt"
2122
)
2223

2324
func TestHexStringToColor(t *testing.T) {
@@ -119,8 +120,8 @@ func TestReplaceColorInPalette(t *testing.T) {
119120

120121
func TestColorLuminance(t *testing.T) {
121122
c := qt.New(t)
122-
c.Assert(hexStringToColor("#000000").Luminance(), qt.Equals, 0.0)
123-
c.Assert(hexStringToColor("#768a9a").Luminance(), qt.Equals, 0.24361603589088263)
124-
c.Assert(hexStringToColor("#d5bc9f").Luminance(), qt.Equals, 0.5261577672685374)
125-
c.Assert(hexStringToColor("#ffffff").Luminance(), qt.Equals, 1.0)
123+
c.Assert(hexStringToColor("#000000").Luminance(), hqt.IsSameFloat64, 0.0)
124+
c.Assert(hexStringToColor("#768a9a").Luminance(), hqt.IsSameFloat64, 0.24361603589088263)
125+
c.Assert(hexStringToColor("#d5bc9f").Luminance(), hqt.IsSameFloat64, 0.5261577672685374)
126+
c.Assert(hexStringToColor("#ffffff").Luminance(), hqt.IsSameFloat64, 1.0)
126127
}

0 commit comments

Comments
 (0)