[1146] | 1 | <!-- saved from url=(0014)about:internet --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
---|
| 2 | <html>
|
---|
| 3 | <!-- Standard Head Part -->
|
---|
| 4 | <head>
|
---|
| 5 | <title>NUnit - EqualityAsserts</title>
|
---|
| 6 | <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
---|
| 7 | <meta http-equiv="Content-Language" content="en-US">
|
---|
| 8 | <link rel="stylesheet" type="text/css" href="nunit.css">
|
---|
| 9 | <link rel="shortcut icon" href="favicon.ico">
|
---|
| 10 | </head>
|
---|
| 11 | <!-- End Standard Head Part -->
|
---|
| 12 |
|
---|
| 13 | <body>
|
---|
| 14 |
|
---|
| 15 | <!-- Standard Header for NUnit.org -->
|
---|
| 16 | <div id="header">
|
---|
| 17 | <a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
|
---|
| 18 | <div id="nav">
|
---|
| 19 | <a href="http://www.nunit.org">NUnit</a>
|
---|
| 20 | <a class="active" href="index.html">Documentation</a>
|
---|
| 21 | </div>
|
---|
| 22 | </div>
|
---|
| 23 | <!-- End of Header -->
|
---|
| 24 |
|
---|
| 25 | <div id="content">
|
---|
| 26 |
|
---|
| 27 | <h2>Equality Asserts</h2>
|
---|
| 28 |
|
---|
| 29 | <p>These methods test whether the two arguments are equal. Overloaded
|
---|
| 30 | methods are provided for common value types so that languages that don't
|
---|
| 31 | automatically box values can use them directly.</p>
|
---|
| 32 |
|
---|
| 33 | <div class="code" style="width: 36em" >
|
---|
| 34 | <pre>Assert.AreEqual( int expected, int actual );
|
---|
| 35 | Assert.AreEqual( int expected, int actual, string message );
|
---|
| 36 | Assert.AreEqual( int expected, int actual, string message,
|
---|
| 37 | params object[] parms );
|
---|
| 38 |
|
---|
| 39 | Assert.AreEqual( uint expected, uint actual );
|
---|
| 40 | Assert.AreEqual( uint expected, uint actual, string message );
|
---|
| 41 | Assert.AreEqual( uint expected, uint actual, string message,
|
---|
| 42 | params object[] parms );
|
---|
| 43 |
|
---|
| 44 | Assert.AreEqual( decimal expected, decimal actual );
|
---|
| 45 | Assert.AreEqual( decimal expected, decimal actual, string message );
|
---|
| 46 | Assert.AreEqual( decimal expected, decimal actual, string message,
|
---|
| 47 | params object[] parms );
|
---|
| 48 |
|
---|
| 49 | Assert.AreEqual( float expected, float actual, float tolerance );
|
---|
| 50 | Assert.AreEqual( float expected, float actual, float tolerance,
|
---|
| 51 | string message );
|
---|
| 52 | Assert.AreEqual( float expected, float actual, float tolerance,
|
---|
| 53 | string message, params object[] parms );
|
---|
| 54 |
|
---|
| 55 | Assert.AreEqual( double expected, double actual, double tolerance );
|
---|
| 56 | Assert.AreEqual( double expected, double actual, double tolerance,
|
---|
| 57 | string message );
|
---|
| 58 | Assert.AreEqual( double expected, double actual, double tolerance,
|
---|
| 59 | string message, params object[] parms );
|
---|
| 60 |
|
---|
| 61 | Assert.AreEqual( object expected, object actual );
|
---|
| 62 | Assert.AreEqual( object expected, object actual, string message );
|
---|
| 63 | Assert.AreEqual( object expected, object actual, string message,
|
---|
| 64 | params object[] parms );
|
---|
| 65 |
|
---|
| 66 | Assert.AreNotEqual( int expected, int actual );
|
---|
| 67 | Assert.AreNotEqual( int expected, int actual, string message );
|
---|
| 68 | Assert.AreNotEqual( int expected, int actual, string message,
|
---|
| 69 | params object[] parms );
|
---|
| 70 |
|
---|
| 71 | Assert.AreNotEqual( long expected, long actual );
|
---|
| 72 | Assert.AreNotEqual( long expected, long actual, string message );
|
---|
| 73 | Assert.AreNotEqual( long expected, long actual, string message,
|
---|
| 74 | params object[] parms );
|
---|
| 75 |
|
---|
| 76 | Assert.AreNotEqual( uint expected, uint actual );
|
---|
| 77 | Assert.AreNotEqual( uint expected, uint actual, string message );
|
---|
| 78 | Assert.AreNotEqual( uint expected, uint actual, string message,
|
---|
| 79 | params object[] parms );
|
---|
| 80 |
|
---|
| 81 | Assert.AreNotEqual( ulong expected, ulong actual );
|
---|
| 82 | Assert.AreNotEqual( ulong expected, ulong actual, string message );
|
---|
| 83 | Assert.AreNotEqual( ulong expected, ulong actual, string message,
|
---|
| 84 | params object[] parms );
|
---|
| 85 |
|
---|
| 86 | Assert.AreNotEqual( decimal expected, decimal actual );
|
---|
| 87 | Assert.AreNotEqual( decimal expected, decimal actual, string message );
|
---|
| 88 | Assert.AreNotEqual( decimal expected, decimal actual, string message,
|
---|
| 89 | params object[] parms );
|
---|
| 90 |
|
---|
| 91 | Assert.AreNotEqual( float expected, float actual );
|
---|
| 92 | Assert.AreNotEqual( float expected, float actual, string message );
|
---|
| 93 | Assert.AreNotEqual( float expected, float actual, string message,
|
---|
| 94 | params object[] parms );
|
---|
| 95 |
|
---|
| 96 | Assert.AreNotEqual( double expected, double actual );
|
---|
| 97 | Assert.AreNotEqual( double expected, double actual, string message );
|
---|
| 98 | Assert.AreNotEqual( double expected, double actual, string message,
|
---|
| 99 | params object[] parms );
|
---|
| 100 |
|
---|
| 101 | Assert.AreNotEqual( object expected, object actual );
|
---|
| 102 | Assert.AreNotEqual( object expected, object actual, string message );
|
---|
| 103 | Assert.AreNotEqual( object expected, object actual, string message,
|
---|
| 104 | params object[] parms );</pre>
|
---|
| 105 | </div>
|
---|
| 106 |
|
---|
| 107 | <h4>Comparing Numerics of Different Types</h4>
|
---|
| 108 |
|
---|
| 109 | <p>The method overloads that compare two objects make special provision so that numeric
|
---|
| 110 | values of different types compare as expected. This assert succeeds:
|
---|
| 111 | <pre> Assert.AreEqual( 5, 5.0 );</pre>
|
---|
| 112 | </p>
|
---|
| 113 |
|
---|
| 114 | <h4>Comparing Floating Point Values</h4>
|
---|
| 115 |
|
---|
| 116 | <p>Values of type float and double are normally compared using an additional
|
---|
| 117 | argument that indicates a tolerance within which they will be considered
|
---|
| 118 | as equal. Beginning with NUnit 2.4.4, the value of
|
---|
| 119 | <b>GlobalSettings.DefaultFloatingPointTolerance</b> is used if a third argument
|
---|
| 120 | is not provided. In earlier versions, or if the default has not been set,
|
---|
| 121 | values are tested for exact equality.
|
---|
| 122 |
|
---|
| 123 | <p>Special values are handled so that the following Asserts succeed:</p>
|
---|
| 124 |
|
---|
| 125 | <pre> Assert.AreEqual( double.PositiveInfinity, double.PositiveInfinity );
|
---|
| 126 | Assert.AreEqual( double.NegativeInfinity, double.NegativeInfinity );
|
---|
| 127 | Assert.AreEqual( double.NaN, double.NaN );</pre>
|
---|
| 128 |
|
---|
| 129 | <blockquote><i><b>Note:</b> The last example above represents a change with NUnit 2.2.3.
|
---|
| 130 | In earlier releases, the test would fail. We have made this change
|
---|
| 131 | because the new behavior seems to be more useful in tests. To avoid confusion,
|
---|
| 132 | we suggest using the new Assert.IsNaN method where appropriate.</i></blockquote>
|
---|
| 133 |
|
---|
| 134 | <h4>Comparing Arrays and Collections</h4>
|
---|
| 135 |
|
---|
| 136 | <p>Since version 2.2, NUnit has been able to compare two single-dimensioned arrays.
|
---|
| 137 | Beginning with version 2.4, multi-dimensioned arrays, nested arrays (arrays of arrays)
|
---|
| 138 | and collections may be compared. Two arrays or collections will be treated as equal
|
---|
| 139 | by Assert.AreEqual if they have the same dimensions and if each of the corresponding
|
---|
| 140 | elements is equal.</p>
|
---|
| 141 |
|
---|
| 142 | </div>
|
---|
| 143 | </div>
|
---|
| 144 |
|
---|
| 145 | <!-- Submenu -->
|
---|
| 146 | <div id="subnav">
|
---|
| 147 | <ul>
|
---|
| 148 | <li><a href="index.html">NUnit 2.5.10</a></li>
|
---|
| 149 | <ul>
|
---|
| 150 | <li><a href="getStarted.html">Getting Started</a></li>
|
---|
| 151 | <li><a href="assertions.html">Assertions</a></li>
|
---|
| 152 | <ul>
|
---|
| 153 | <li id="current"><a href="equalityAsserts.html">Equality Asserts</a></li>
|
---|
| 154 | <li><a href="identityAsserts.html">Identity Asserts</a></li>
|
---|
| 155 | <li><a href="conditionAsserts.html">Condition Asserts</a></li>
|
---|
| 156 | <li><a href="comparisonAsserts.html">Comparison Asserts</a></li>
|
---|
| 157 | <li><a href="typeAsserts.html">Type Asserts</a></li>
|
---|
| 158 | <li><a href="exceptionAsserts.html">Exception Asserts</a></li>
|
---|
| 159 | <li><a href="utilityAsserts.html">Utility Methods</a></li>
|
---|
| 160 | <li><a href="stringAssert.html">String Assert</a></li>
|
---|
| 161 | <li><a href="collectionAssert.html">Collection Assert</a></li>
|
---|
| 162 | <li><a href="fileAssert.html">File Assert</a></li>
|
---|
| 163 | <li><a href="directoryAssert.html">Directory Assert</a></li>
|
---|
| 164 | </ul>
|
---|
| 165 | <li><a href="constraintModel.html">Constraints</a></li>
|
---|
| 166 | <li><a href="attributes.html">Attributes</a></li>
|
---|
| 167 | <li><a href="runningTests.html">Running Tests</a></li>
|
---|
| 168 | <li><a href="extensibility.html">Extensibility</a></li>
|
---|
| 169 | <li><a href="releaseNotes.html">Release Notes</a></li>
|
---|
| 170 | <li><a href="samples.html">Samples</a></li>
|
---|
| 171 | <li><a href="license.html">License</a></li>
|
---|
| 172 | </ul>
|
---|
| 173 | </ul>
|
---|
| 174 | </div>
|
---|
| 175 | <!-- End of Submenu -->
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | <!-- Standard Footer for NUnit.org -->
|
---|
| 179 | <div id="footer">
|
---|
| 180 | Copyright © 2010 Charlie Poole. All Rights Reserved.
|
---|
| 181 | </div>
|
---|
| 182 | <!-- End of Footer -->
|
---|
| 183 |
|
---|
| 184 | </body>
|
---|
| 185 | </html>
|
---|