-
Notifications
You must be signed in to change notification settings - Fork 30
Description
We would like to add a new feature while comparing two json objects containing floating numbers as values. We would like to compare the floating numbers with some margin of error.
Let’s take an example:
jsonA and jsonB two json objects that contain as values floating numbers with 9 decimal values.
Thus, this unit test fails because json1 and jsonB are differents at the ninth decimal value.
We would like to be able to consider jsonA and JsonB equal if their floating numbers values are equal at the eighth decimal value.
So, we want to have a feature that allows us to control the approximate equality of floating numbers.
Like for instance something like this for absolute tolerance:
jsonA.Should().BeEquivalentTo(jsonB, options => options.Using<double>(d => d.Subject.Should().BeApproximately(d.Expectation, 1e-8, false)).WhenTypeIs<double>());
And for relative tolerance:
jsonA.Should().BeEquivalentTo(jsonB, options => options.Using<double>(d => d.Subject.Should().BeApproximately(d.Expectation, 1e-8, true)).WhenTypeIs<double>());
note : We will be happy to contribute adding this feature by a pull request 😀.
