Class Tolerance
The Tolerance class generalizes the notion of a tolerance within which an equality test succeeds. Normally, it is used with numeric types, but it can be used with any type that supports taking a difference between two objects and comparing that difference to a value.
Inherited Members
Namespace: NUnit.Framework.Constraints
Assembly: nunit.framework.dll
Syntax
public sealed class Tolerance
Constructors
View SourceTolerance(object)
Constructs a linear tolerance of a specified amount
Declaration
public Tolerance(object amount)
Parameters
Type | Name | Description |
---|---|---|
object | amount |
Fields
View SourceDefault
Returns a default Tolerance object, equivalent to a default matching rules.
Declaration
public static readonly Tolerance Default
Field Value
Type | Description |
---|---|
Tolerance |
Exact
Returns an empty Tolerance object, equivalent to an exact match.
Declaration
public static readonly Tolerance Exact
Field Value
Type | Description |
---|---|
Tolerance |
Properties
View SourceAmount
Gets the magnitude of the current Tolerance instance.
Declaration
public object Amount { get; }
Property Value
Type | Description |
---|---|
object |
Days
Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of days.
Declaration
public Tolerance Days { get; }
Property Value
Type | Description |
---|---|
Tolerance |
HasVariance
Returns true if the current tolerance varies from exact and default. Indicating tolerance needs processing.
Declaration
public bool HasVariance { get; }
Property Value
Type | Description |
---|---|
bool |
Hours
Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of hours.
Declaration
public Tolerance Hours { get; }
Property Value
Type | Description |
---|---|
Tolerance |
IsUnsetOrDefault
Returns true if the current tolerance has not been set or is using the default.
Declaration
public bool IsUnsetOrDefault { get; }
Property Value
Type | Description |
---|---|
bool |
Milliseconds
Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of milliseconds.
Declaration
public Tolerance Milliseconds { get; }
Property Value
Type | Description |
---|---|
Tolerance |
Minutes
Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of minutes.
Declaration
public Tolerance Minutes { get; }
Property Value
Type | Description |
---|---|
Tolerance |
Mode
Gets the ToleranceMode for the current Tolerance
Declaration
public ToleranceMode Mode { get; }
Property Value
Type | Description |
---|---|
ToleranceMode |
Percent
Returns a new tolerance, using the current amount as a percentage.
Declaration
public Tolerance Percent { get; }
Property Value
Type | Description |
---|---|
Tolerance |
Seconds
Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of seconds.
Declaration
public Tolerance Seconds { get; }
Property Value
Type | Description |
---|---|
Tolerance |
Ticks
Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of clock ticks.
Declaration
public Tolerance Ticks { get; }
Property Value
Type | Description |
---|---|
Tolerance |
Ulps
Returns a new tolerance, using the current amount in Ulps
Declaration
public Tolerance Ulps { get; }
Property Value
Type | Description |
---|---|
Tolerance |
Methods
View SourceApplyToValue(object)
Apply the tolerance to an expected value and return a Tolerance.Range that represents the acceptable values.
Declaration
public Tolerance.Range ApplyToValue(object value)
Parameters
Type | Name | Description |
---|---|---|
object | value |
Returns
Type | Description |
---|---|
Tolerance.Range |
ToString()
Returns a string that represents the current object.
Declaration
public override string? ToString()
Returns
Type | Description |
---|---|
string | A string that represents the current object. |