DefaultFloatingPointToleranceAttribute
Sets the tolerance used by default when checking the equality of floating point values
within the test assembly, fixture or method.
using NUnit.
Framework.
Constraints;
using NUnit.
Framework.
Interfaces;
using NUnit.
Framework.
Internal;
using System;
using System.
Runtime.
CompilerServices;
namespace NUnit.
Framework
{
[
AttributeUsage(
AttributeTargets.
Assembly |
AttributeTargets.
Class |
AttributeTargets.
Method,
AllowMultiple =
false,
Inherited =
true)]
public class DefaultFloatingPointToleranceAttribute :
NUnitAttribute,
IApplyToContext
{
[
System.
Runtime.
CompilerServices.
Nullable(
1)]
private readonly Tolerance _tolerance;
public DefaultFloatingPointToleranceAttribute(
double amount)
{
_tolerance =
new Tolerance(
amount);
}
[
System.
Runtime.
CompilerServices.
NullableContext(
1)]
public void ApplyToContext(
TestExecutionContext context)
{
context.
DefaultFloatingPointTolerance =
_tolerance;
}
}
}