Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert: Add new assertion InEpsilonMapValues #1500

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hendrywiranto
Copy link
Contributor

Summary

Add new assertion InEpsilonMapValues which is the same as InEpsilon, but it compares all values between two maps.

Changes

  • Add new assertion InEpsilonMapValues

Motivation

Quoting #1497

To be consistent with InDeltaMapValues package could provide InEpsilonMapValues

Example

expected := map[string]float64{
	"foo": 2.2,
	"baz": 2.0,
}
actual := map[string]float64{
	"foo": 2.1,
	"baz": 2.1,
}
InEpsilonMapValues(mockT, expected, actual, 0.06, "InEpsilonMapValues example")

Related issues

Closes #1497

assert/assertions.go Show resolved Hide resolved
@hendrywiranto hendrywiranto force-pushed the feat-InEpsilonMap branch 2 times, most recently from 3494db0 to 94fc43e Compare November 1, 2023 17:06
@Antonboom
Copy link

Antonboom commented Nov 3, 2023

@hendrywiranto, hi!

I am not maintainer of testify and cannot approve or decline your MR.
But LGTM.

(cc) @dolmen

@hendrywiranto
Copy link
Contributor Author

@hendrywiranto, hi!

I am not maintainer of testify and cannot approve or decline your MR. But LGTM.

(cc) @dolmen

Yep I know, thanks for replying tho
Looks like the checks failure is a widespread issue and being handled here #1504

@dolmen
Copy link
Collaborator

dolmen commented Nov 5, 2023

FYI, my focus is on fixing bugs, not on extending the API to have even more code to maintain.

@hendrywiranto hendrywiranto force-pushed the feat-InEpsilonMap branch 2 times, most recently from 08cacbc to 550dbac Compare February 22, 2024 14:32
@dolmen dolmen added pkg-assert Change related to package testify/assert assert.InEpsilon About assert.InEpsilon and family labels Mar 6, 2024
}
if expected == nil || actual == nil ||
reflect.TypeOf(actual).Kind() != reflect.Map ||
reflect.TypeOf(expected).Kind() != reflect.Map {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the check of the kind of actual.

Instead, just check the kind of expected and check that actual has the same type with call IsType(t, expected, actual, msgAndArgs...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for review, kindly please check again

title string
expected interface{}
actual interface{}
f func(TestingT, bool, ...interface{}) bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f func(TestingT, bool, ...interface{}) bool
f BoolAssertionFunc

actual: nil,
epsilon: 0.1,
f: False,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests with map[string]string and map[string]struct{}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert.InEpsilon About assert.InEpsilon and family enhancement pkg-assert Change related to package testify/assert
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proposal: new assertionInEpsilonMapValues
3 participants