From 94fc43e49c53d2b47d9d52e17f6ae2abe0be7f11 Mon Sep 17 00:00:00 2001 From: "hendry.wiranto" Date: Wed, 1 Nov 2023 23:37:51 +0700 Subject: [PATCH] run ./.ci.generate.sh --- assert/assertion_format.go | 8 ++++++++ assert/assertion_forward.go | 16 ++++++++++++++++ require/require.go | 22 ++++++++++++++++++++++ require/require_forward.go | 16 ++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/assert/assertion_format.go b/assert/assertion_format.go index 896cc7fd0..ff1c860a4 100644 --- a/assert/assertion_format.go +++ b/assert/assertion_format.go @@ -382,6 +382,14 @@ func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon fl return InEpsilon(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...) } +// InEpsilonMapValuesf is the same as InEpsilon, but it compares all values between two maps. Both maps must have exactly the same keys. +func InEpsilonMapValuesf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return InEpsilonMapValues(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...) +} + // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool { if h, ok := t.(tHelper); ok { diff --git a/assert/assertion_forward.go b/assert/assertion_forward.go index 8aaa25967..477035283 100644 --- a/assert/assertion_forward.go +++ b/assert/assertion_forward.go @@ -748,6 +748,22 @@ func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon return InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...) } +// InEpsilonMapValues is the same as InEpsilon, but it compares all values between two maps. Both maps must have exactly the same keys. +func (a *Assertions) InEpsilonMapValues(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return InEpsilonMapValues(a.t, expected, actual, epsilon, msgAndArgs...) +} + +// InEpsilonMapValuesf is the same as InEpsilon, but it compares all values between two maps. Both maps must have exactly the same keys. +func (a *Assertions) InEpsilonMapValuesf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return InEpsilonMapValuesf(a.t, expected, actual, epsilon, msg, args...) +} + // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { if h, ok := a.t.(tHelper); ok { diff --git a/require/require.go b/require/require.go index fde08337c..ab3111ee8 100644 --- a/require/require.go +++ b/require/require.go @@ -944,6 +944,28 @@ func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon flo t.FailNow() } +// InEpsilonMapValues is the same as InEpsilon, but it compares all values between two maps. Both maps must have exactly the same keys. +func InEpsilonMapValues(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.InEpsilonMapValues(t, expected, actual, epsilon, msgAndArgs...) { + return + } + t.FailNow() +} + +// InEpsilonMapValuesf is the same as InEpsilon, but it compares all values between two maps. Both maps must have exactly the same keys. +func InEpsilonMapValuesf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.InEpsilonMapValuesf(t, expected, actual, epsilon, msg, args...) { + return + } + t.FailNow() +} + // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { diff --git a/require/require_forward.go b/require/require_forward.go index 8fddd1f7a..d69b023fd 100644 --- a/require/require_forward.go +++ b/require/require_forward.go @@ -749,6 +749,22 @@ func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...) } +// InEpsilonMapValues is the same as InEpsilon, but it compares all values between two maps. Both maps must have exactly the same keys. +func (a *Assertions) InEpsilonMapValues(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + InEpsilonMapValues(a.t, expected, actual, epsilon, msgAndArgs...) +} + +// InEpsilonMapValuesf is the same as InEpsilon, but it compares all values between two maps. Both maps must have exactly the same keys. +func (a *Assertions) InEpsilonMapValuesf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + InEpsilonMapValuesf(a.t, expected, actual, epsilon, msg, args...) +} + // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok {