Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi Friends.
I am looking at this example of a Unit Test but the article doesn't explain what the 1 represents... Assert.Equal (expectedValue, sum, 1);
Thanks !!!
[Fact]
public void Task_Add_TwoNumber()
{
// Arrange
var num1 = 2.9;
var num2 = 3.1;
var expectedValue = 6;
// Act
var sum = MathOperation.Add(num1, num2);
//Assert
Assert.Equal(expectedValue, sum, 1);
}
When dealing with floating point numbers there's a chance that you'll encounter slightly inaccurate results due to how these numbers are stored in memory. Sometimes slight inaccuracy is tolerable, so this extra parameter (for Assert.Equal overloads that accept float/double that that predominantly affected by this) is to allow you to factor a small configurable margin of error when performing the comparison: