Unit Testing and xUnit

Ronald Rex 1,671 Reputation points
2023-07-24T13:42:23.0466667+00:00

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);  
        }  
Developer technologies | C#
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.
0 comments No comments
{count} votes

Answer accepted by question author
  1. P a u l 10,766 Reputation points
    2023-07-24T16:43:44.8733333+00:00

    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:

    User's image

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.