Search Results for

    Show / Hide Table of Contents

    ClassicAssert.AreEqual

    ClassicAssert.AreEqual tests whether the two arguments are equal.

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

    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:

    ClassicAssert.AreEqual(5, 5.0);
    

    Comparing Floating Point Values

    Values of type float and double are compared using an additional argument that indicates a tolerance within which they will be considered as equal.

    Special values are handled so that the following Asserts succeed:

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

    Comparing Arrays and Collections

    NUnit is able to compare single-dimensioned arrays, multi-dimensioned arrays, nested arrays (arrays of arrays) and collections. Two arrays or collections are considered equal if they have the same dimensions and if each pair of corresponding elements is equal.

    NUnit 3.0 adds the ability to compare generic collections and dictionaries.

    See Also

    • Equal Constraint
    • DefaultFloatingPointTolerance Attribute
    • Edit this page
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0