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 InDelta for maps with a deltas map #1519

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

Conversation

julian776
Copy link

@julian776 julian776 commented Dec 17, 2023

Summary

Add functionality to compare a custom delta for each map value.

Changes

Include the function to compare each delta.

Motivation

These changes now let you compare each map value with its own custom delta, instead of having to use the same for all of them.

Example usage

func TestHardcodedValues(t *testing.T) {
	expexted := map[string]float64{
		"foo": 1.0,
		"bar": 7,
		"baz": math.NaN(),
	}

	actual := map[string]float64{
		"foo": 1.01,
		"bar": 7.99,
		"baz": math.NaN(),
	}

	deltas := map[interface{}]float64{
		"foo": 0.1,
		"bar": 1,
		"baz": 0.1,
	}

	assert.InMapDeltasMapValues(
		t,
		expexted,
		actual,
		deltas,
	)
}

Related issues

Incorporate functionality #1496.

@hendrywiranto
Copy link
Contributor

Hi,
I hate to break this to you but currently testify doesn't accept PR that expands the API as stated by this comment
#1500 (comment)

but I may be wrong, need to wait maintainer's response

@julian776
Copy link
Author

I wasn't aware of this, but no problem if that's the case.

@dolmen dolmen added pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require assert.InEpsilon About assert.InEpsilon and family enhancement labels Mar 7, 2024
@dolmen dolmen changed the title Implement custom delta comparison for each map value assert: add InDelta for maps with a deltas map Mar 7, 2024
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 pkg-require Change related to package testify/require
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants