Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

New Post: Comparing object equivalence for dictionaries

$
0
0
I've been using ShouldBeEquivalentTo() to compare 2 dictionaries, which works fine.

What I want to be do is check that the keys are the same, while the values can be within a range (say within 1 %) through the assertion options. Is this possible?

At the moment I'm doing the following (both dictionaries are sorted by key):
foreach (var o in actual)
{
    expectedValues.Should().ContainKey(o.Key);
    o.Value.Should().BeInRange(oo.Value*0.99, oo.Value*1.01);
}
Which works but doesn't look very elegant...

Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>