Skip to content

Commit 533650f

Browse files
committed
feat: apply reviews
1 parent fcd6ee4 commit 533650f

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

assert/assertions.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,10 +1537,12 @@ func InEpsilonMapValues(t TestingT, expected, actual interface{}, epsilon float6
15371537
h.Helper()
15381538
}
15391539
if expected == nil || actual == nil ||
1540-
reflect.TypeOf(actual).Kind() != reflect.Map ||
15411540
reflect.TypeOf(expected).Kind() != reflect.Map {
15421541
return Fail(t, "Arguments must be maps", msgAndArgs...)
15431542
}
1543+
if !IsType(t, expected, actual) {
1544+
return Fail(t, "Both values must be of the same type", msgAndArgs...)
1545+
}
15441546

15451547
actualMap := reflect.ValueOf(actual)
15461548
expectedMap := reflect.ValueOf(expected)

assert/assertions_test.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ func TestInEpsilonMapValues(t *testing.T) {
19711971
title string
19721972
expected interface{}
19731973
actual interface{}
1974-
f func(TestingT, bool, ...interface{}) bool
1974+
f BoolAssertionFunc
19751975
epsilon float64
19761976
}{
19771977
{
@@ -2005,7 +2005,7 @@ func TestInEpsilonMapValues(t *testing.T) {
20052005
f: False,
20062006
},
20072007
{
2008-
title: "With different map keys",
2008+
title: "Within epsilon with different map keys",
20092009
expected: map[string]float64{
20102010
"foo": 2.2,
20112011
"baz": 2.0,
@@ -2018,7 +2018,7 @@ func TestInEpsilonMapValues(t *testing.T) {
20182018
f: False,
20192019
},
20202020
{
2021-
title: "With different number of keys",
2021+
title: "Within epsilon with different number of map keys",
20222022
expected: map[string]float64{
20232023
"foo": 2.2,
20242024
"baz": 2.0,
@@ -2030,7 +2030,7 @@ func TestInEpsilonMapValues(t *testing.T) {
20302030
f: False,
20312031
},
20322032
{
2033-
title: "With zero value on expected",
2033+
title: "Within epsilon with zero value on expected",
20342034
expected: map[string]float64{
20352035
"foo": 0,
20362036
},
@@ -2087,6 +2087,39 @@ func TestInEpsilonMapValues(t *testing.T) {
20872087
epsilon: 0.1,
20882088
f: False,
20892089
},
2090+
{
2091+
title: "When expected and actual are not the same type",
2092+
expected: map[string]float64{
2093+
"foo": 2.1,
2094+
},
2095+
actual: map[string]string{
2096+
"foo": "2.0",
2097+
},
2098+
epsilon: 0.1,
2099+
f: False,
2100+
},
2101+
{
2102+
title: "When expected and actual map value are string",
2103+
expected: map[string]string{
2104+
"foo": "2.1",
2105+
},
2106+
actual: map[string]string{
2107+
"foo": "2.0",
2108+
},
2109+
epsilon: 0.1,
2110+
f: False,
2111+
},
2112+
{
2113+
title: "When expected and actual map value are struct",
2114+
expected: map[string]struct{}{
2115+
"foo": {},
2116+
},
2117+
actual: map[string]struct{}{
2118+
"foo": {},
2119+
},
2120+
epsilon: 0.1,
2121+
f: False,
2122+
},
20902123
} {
20912124
tc.f(t, InEpsilonMapValues(mockT, tc.expected, tc.actual, tc.epsilon), tc.title)
20922125
}

0 commit comments

Comments
 (0)