Trying to learn FluentAssertions, but have a weird result from Should().Be(new Wotsit ())
I'm trying to learn TTD and I wrote a test to compare pseudo-tuple classes after multiplication.
The results seem identical, but it counts as a failure.
What did I do wrong? My C# ability is decent, but I'm new to TTD and FluentAssertions
7 Replies
hmm... it seems to be an issue with me initialising the variable inside should be. result.Should().BeEquivelentTo(expected); works
Urgh! Expected property result.Blue to be 0.04, but found 0.04000000000000001.
I really should just use three seperate result.Blue.Should().BeApproximately(0.04, tolerence);
I know doubles are slightly inprecise compared to decimals
You can tell fluentassertions to use different behaviour for doubled
Fluent Assertions
Object graph comparison
Thank you, I'll check it when I wake up.
And you could also apply that globally using the static AssertionOptions
But I can’t quite remember the syntax for that
That'll be worth trying, non-decimals/ints rarely match perfectly.
Yeah, I mainly use it with time, when I’m asserting against the creation date of something returned from my api. Obviously it is approximately DateTime.UtcNow but +- how long the request took
So I allow 1 second of tolerance