NUnit - EqualityAsserts

## Equality Asserts

These methods test whether the two arguments are equal. Overloaded methods are provided for common value types so that languages that don't automatically box values can use them directly.

    Assert.AreEqual( int expected, int actual );
    Assert.AreEqual( int expected, int actual, string message );
    Assert.AreEqual( int expected, int actual, string message,
                     params object[] parms );

    Assert.AreEqual( uint expected, uint actual );
    Assert.AreEqual( uint expected, uint actual, string message );
    Assert.AreEqual( uint expected, uint actual, string message,
                     params object[] parms );

    Assert.AreEqual( decimal expected, decimal actual );
    Assert.AreEqual( decimal expected, decimal actual, string message );
    Assert.AreEqual( decimal expected, decimal actual, string message,
                     params object[] parms );

    Assert.AreEqual( float expected, float actual, float tolerance );
    Assert.AreEqual( float expected, float actual, float tolerance,
                     string message );
    Assert.AreEqual( float expected, float actual, float tolerance,
                     string message, params object[] parms );

    Assert.AreEqual( double expected, double actual, double tolerance );
    Assert.AreEqual( double expected, double actual, double tolerance,
                     string message );
    Assert.AreEqual( double expected, double actual, double tolerance,
                     string message, params object[] parms );

    Assert.AreEqual( object expected, object actual );
    Assert.AreEqual( object expected, object actual, string message );
    Assert.AreEqual( object expected, object actual, string message,
                     params object[] parms );

    Assert.AreNotEqual( int expected, int actual );
    Assert.AreNotEqual( int expected, int actual, string message );
    Assert.AreNotEqual( int expected, int actual, string message,
                     params object[] parms );

    Assert.AreNotEqual( long expected, long actual );
    Assert.AreNotEqual( long expected, long actual, string message );
    Assert.AreNotEqual( long expected, long actual, string message,
                     params object[] parms );

    Assert.AreNotEqual( uint expected, uint actual );
    Assert.AreNotEqual( uint expected, uint actual, string message );
    Assert.AreNotEqual( uint expected, uint actual, string message,
                     params object[] parms );

    Assert.AreNotEqual( ulong expected, ulong actual );
    Assert.AreNotEqual( ulong expected, ulong actual, string message );
    Assert.AreNotEqual( ulong expected, ulong actual, string message,
                     params object[] parms );

    Assert.AreNotEqual( decimal expected, decimal actual );
    Assert.AreNotEqual( decimal expected, decimal actual, string message );
    Assert.AreNotEqual( decimal expected, decimal actual, string message,
                     params object[] parms );

    Assert.AreNotEqual( float expected, float actual );
    Assert.AreNotEqual( float expected, float actual, string message );
    Assert.AreNotEqual( float expected, float actual, string message,
                     params object[] parms );

    Assert.AreNotEqual( double expected, double actual );
    Assert.AreNotEqual( double expected, double actual, string message );
    Assert.AreNotEqual( double expected, double actual, string message,
                     params object[] parms );

    Assert.AreNotEqual( object expected, object actual );
    Assert.AreNotEqual( object expected, object actual, string message );
    Assert.AreNotEqual( object expected, object actual, string message,
                     params object[] parms );

#### Comparing Numerics of Different Types

The method overloads that compare two objects make special provision so that numeric values of different types compare as expected. This assert succeeds:

            Assert.AreEqual( 5, 5.0 );

#### Comparing Floating Point Values

Values of type float and double are normally compared using an additional argument that indicates a tolerance within which they will be considered as equal. Beginning with NUnit 2.4.4, the value of GlobalSettings.DefaultFloatingPointTolerance is used if a third argument is not provided. In earlier versions, or if the default has not been set, values are tested for exact equality.

Special values are handled so that the following Asserts succeed:

            Assert.AreEqual( double.PositiveInfinity, double.PositiveInfinity );
            Assert.AreEqual( double.NegativeInfinity, double.NegativeInfinity );
            Assert.AreEqual( double.NaN, double.NaN );

> Note: The last example above represents a change with NUnit 2.2.3. In earlier releases, the test would fail. We have made this change because the new behavior seems to be more useful in tests. To avoid confusion, we suggest using the new Assert.IsNaN method where appropriate.

#### Comparing Arrays and Collections

Since version 2.2, NUnit has been able to compare two single-dimensioned arrays. Beginning with version 2.4, multi-dimensioned arrays, nested arrays (arrays of arrays) and collections may be compared. Two arrays or collections will be treated as equal by Assert.AreEqual if they have the same dimensions and if each of the corresponding elements is equal.