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;
namespace NUnit.Framework
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class DefaultFloatingPointToleranceAttribute : NUnitAttribute, IApplyToContext
{
private readonly Tolerance _tolerance;
public DefaultFloatingPointToleranceAttribute(double amount)
{
_tolerance = new Tolerance(amount);
}
public void ApplyToContext(TestExecutionContext context)
{
context.DefaultFloatingPointTolerance = _tolerance;
}
}
}