File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ package hqt
16
16
import (
17
17
"errors"
18
18
"fmt"
19
+ "math"
19
20
"reflect"
20
21
"strings"
21
22
@@ -38,6 +39,11 @@ var IsSameType qt.Checker = &typeChecker{
38
39
argNames : []string {"got" , "want" },
39
40
}
40
41
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
+
41
47
type argNames []string
42
48
43
49
func (a argNames ) ArgNames () []string {
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import (
18
18
"testing"
19
19
20
20
qt "github.com/frankban/quicktest"
21
+ "github.com/gohugoio/hugo/htesting/hqt"
21
22
)
22
23
23
24
func TestHexStringToColor (t * testing.T ) {
@@ -119,8 +120,8 @@ func TestReplaceColorInPalette(t *testing.T) {
119
120
120
121
func TestColorLuminance (t * testing.T ) {
121
122
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 )
126
127
}
You can’t perform that action at this time.
0 commit comments