nunitv2/doc/equalityAsserts.html

190 строки
7.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<!-- Standard Head Part -->
<head>
<title>NUnit - EqualityAsserts</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-US">
<link rel="stylesheet" type="text/css" href="nunit.css">
<link rel="shortcut icon" href="favicon.ico">
</head>
<!-- End Standard Head Part -->
<body>
<!-- Standard Header for NUnit.org -->
<div id="header">
<a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
<div id="nav">
<a href="http://www.nunit.org">NUnit</a>
<a class="active" href="index.html">Documentation</a>
</div>
</div>
<!-- End of Header -->
<div id="content">
<h2>Equality Asserts</h2>
<p>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.</p>
<div class="code" style="width: 36em" >
<pre>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 );</pre>
</div>
<h4>Comparing Numerics of Different Types</h4>
<p>The method overloads that compare two objects make special provision so that numeric
values of different types compare as expected. This assert succeeds:
<pre> Assert.AreEqual( 5, 5.0 );</pre>
</p>
<h4>Comparing Floating Point Values</h4>
<p>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
<b>GlobalSettings.DefaultFloatingPointTolerance</b> 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.
<p>Special values are handled so that the following Asserts succeed:</p>
<pre> Assert.AreEqual( double.PositiveInfinity, double.PositiveInfinity );
Assert.AreEqual( double.NegativeInfinity, double.NegativeInfinity );
Assert.AreEqual( double.NaN, double.NaN );</pre>
<blockquote><i><b>Note:</b> 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.</i></blockquote>
<h4>Comparing Arrays and Collections</h4>
<p>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.</p>
</div>
</div>
<!-- Submenu -->
<div id="subnav">
<ul>
<li><a href="index.html">NUnit 2.5</a></li>
<ul>
<li><a href="getStarted.html">Getting&nbsp;Started</a></li>
<li><a href="assertions.html">Assertions</a></li>
<ul>
<li><a href="classicModel.html">Classic&nbsp;Model</a></li>
<ul>
<li id="current"><a href="equalityAsserts.html">Equality&nbsp;Asserts</a></li>
<li><a href="identityAsserts.html">Identity&nbsp;Asserts</a></li>
<li><a href="conditionAsserts.html">Condition&nbsp;Tests</a></li>
<li><a href="comparisonAsserts.html">Comparison&nbsp;Asserts</a></li>
<li><a href="typeAsserts.html">Type&nbsp;Asserts</a></li>
<li><a href="exceptionAsserts.html">Exception&nbsp;Tests</a></li>
<li><a href="utilityAsserts.html">Utility&nbsp;Methods</a></li>
<li><a href="stringAssert.html">String&nbsp;Assert</a></li>
<li><a href="collectionAssert.html">Collection&nbsp;Assert</a></li>
<li><a href="fileAssert.html">File&nbsp;Assert</a></li>
<li><a href="directoryAssert.html">Directory&nbsp;Assert</a></li>
</ul>
<li><a href="constraintModel.html">Constraint&nbsp;Model</a></li>
</ul>
<li><a href="attributes.html">Attributes</a></li>
<li><a href="nunit-console.html">Console&nbsp;Runner</a></li>
<li><a href="nunit-gui.html">Gui&nbsp;Runner</a></li>
<li><a href="features.html">Other&nbsp;Features</a></li>
<li><a href="releaseNotes.html">Release&nbsp;Notes</a></li>
<li><a href="samples.html">Samples</a></li>
<li><a href="license.html">License</a></li>
</ul>
</ul>
</div>
<!-- End of Submenu -->
<!-- Standard Footer for NUnit.org -->
<div id="footer">
Copyright &copy; 2008 Charlie Poole. All Rights Reserved.
</div>
<!-- End of Footer -->
</body>
</html>