Skip to content

Commit

Permalink
feat: apply reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrywiranto committed Mar 6, 2024
1 parent fcd6ee4 commit 533650f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
4 changes: 3 additions & 1 deletion assert/assertions.go
Expand Up @@ -1537,10 +1537,12 @@ func InEpsilonMapValues(t TestingT, expected, actual interface{}, epsilon float6
h.Helper()
}
if expected == nil || actual == nil ||
reflect.TypeOf(actual).Kind() != reflect.Map ||
reflect.TypeOf(expected).Kind() != reflect.Map {
return Fail(t, "Arguments must be maps", msgAndArgs...)
}
if !IsType(t, expected, actual) {
return Fail(t, "Both values must be of the same type", msgAndArgs...)
}

actualMap := reflect.ValueOf(actual)
expectedMap := reflect.ValueOf(expected)
Expand Down
41 changes: 37 additions & 4 deletions assert/assertions_test.go
Expand Up @@ -1971,7 +1971,7 @@ func TestInEpsilonMapValues(t *testing.T) {
title string
expected interface{}
actual interface{}
f func(TestingT, bool, ...interface{}) bool
f BoolAssertionFunc
epsilon float64
}{
{
Expand Down Expand Up @@ -2005,7 +2005,7 @@ func TestInEpsilonMapValues(t *testing.T) {
f: False,
},
{
title: "With different map keys",
title: "Within epsilon with different map keys",
expected: map[string]float64{
"foo": 2.2,
"baz": 2.0,
Expand All @@ -2018,7 +2018,7 @@ func TestInEpsilonMapValues(t *testing.T) {
f: False,
},
{
title: "With different number of keys",
title: "Within epsilon with different number of map keys",
expected: map[string]float64{
"foo": 2.2,
"baz": 2.0,
Expand All @@ -2030,7 +2030,7 @@ func TestInEpsilonMapValues(t *testing.T) {
f: False,
},
{
title: "With zero value on expected",
title: "Within epsilon with zero value on expected",
expected: map[string]float64{
"foo": 0,
},
Expand Down Expand Up @@ -2087,6 +2087,39 @@ func TestInEpsilonMapValues(t *testing.T) {
epsilon: 0.1,
f: False,
},
{
title: "When expected and actual are not the same type",
expected: map[string]float64{
"foo": 2.1,
},
actual: map[string]string{
"foo": "2.0",
},
epsilon: 0.1,
f: False,
},
{
title: "When expected and actual map value are string",
expected: map[string]string{
"foo": "2.1",
},
actual: map[string]string{
"foo": "2.0",
},
epsilon: 0.1,
f: False,
},
{
title: "When expected and actual map value are struct",
expected: map[string]struct{}{
"foo": {},
},
actual: map[string]struct{}{
"foo": {},
},
epsilon: 0.1,
f: False,
},
} {
tc.f(t, InEpsilonMapValues(mockT, tc.expected, tc.actual, tc.epsilon), tc.title)
}
Expand Down

0 comments on commit 533650f

Please sign in to comment.