I wrote some unit tests for the utility library when I came across a test that I would expect a crash that actually passed. Is there a problem with comparing two float
variables compared to one float?
variable float?
and one variable float
.
I use the latest versions of both NUnit (2.6.0.12051) and FluentAssertions (1.7.1), and below is an abbreviated code illustrating the problem:
using FluentAssertions; using FluentAssertions.Assertions; using NUnit.Framework; namespace CommonUtilities.UnitTests { [TestFixture] public class FluentAssertionsFloatAssertionTest { [Test] public void TestFloatEquality() { float expected = 3.14f; float notExpected = 1.0f; float actual = 3.14f; actual.Should().BeApproximately(expected, 0.1f); actual.Should().BeApproximately(notExpected, 0.1f);
As you can see from my comments, in TestFloatEquality()
both A and B will fail (just comment out the first failed test to go to the second).
In TestNullableFloatEquality()
however, D passes, but C fails. I would expect C to fail too. And just to mention this, if I add assertions using NUnit:
Assert.AreEqual(expected, actual);
those pass and fail as expected.
So, to the question: Is this a bug in FluentAssertions or am I missing something due to a comparison with a null value?
source share