-
Notifications
You must be signed in to change notification settings - Fork 158
DefaultFloatingPointTolerance Attribute
Mikkel Nylander Bundgaard edited this page Jul 22, 2018
·
3 revisions
The DefaultFloatingPointToleranceAttribute is used to indicate that
comparisons of values of types float
and double
- within the test method,
class, or assembly marked with the attribute - should use the tolerance
specified in the constructor unless a specific tolerance is given for the
comparison.
[TestFixture]
[DefaultFloatingPointTolerance(1)]
public class ToleranceTest
{
[Test]
public void ComparisonUsingDefaultFloatingPointToleranceFromFixture()
{
// Passes due to the DefaultFloatingPointToleranceAttribute from the fixture.
Assert.That(1f, Is.EqualTo(2));
}
[Test]
public void ComparisonOfIntegersDoNotUseTolerance()
{
// Fails as DefaultFloatingPointTolerance only effects comparisons
// of floats and doubles.
Assert.That(1, Is.EqualTo(2));
}
[Test]
public void ComparisonUsingSpecificTolerance()
{
// Fails as 1 is not equal to 2 using the speficied tolerance 0.
Assert.That(1f, Is.EqualTo(2).Within(0));
}
[Test]
[DefaultFloatingPointTolerance(2)]
public void ComparisonUsingDefaultFloatingPointToleranceFromTest()
{
// Passes due to the DefaultFloatingPointTolerance from the test.
Assert.That(2f, Is.EqualTo(4));
}
}
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0
-
NUnit
-
Release Notes
-
License
- Getting Started
- Writing Tests
- Running Tests
- Extending NUnit
- Technical Notes
-
Release Notes
- NUnit Xamarin Runners
- VS Test Adapter
- VS Test Generator
- NUnit Analyzers