Table of Contents

Class Tolerance

Namespace
NUnit.Framework.Constraints
Assembly
nunit.framework.dll

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.

public sealed class Tolerance
Inheritance
Tolerance
Inherited Members

Constructors

Tolerance(object)

Constructs a linear tolerance of a specified amount

public Tolerance(object amount)

Parameters

amount object

Fields

Default

Returns a default Tolerance object, equivalent to a default matching rules.

public static readonly Tolerance Default

Field Value

Tolerance

Exact

Returns an empty Tolerance object, equivalent to an exact match.

public static readonly Tolerance Exact

Field Value

Tolerance

Properties

Amount

Gets the magnitude of the current Tolerance instance.

public object Amount { get; }

Property Value

object

Days

Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of days.

public Tolerance Days { get; }

Property Value

Tolerance

HasVariance

Returns true if the current tolerance varies from exact and default. Indicating tolerance needs processing.

public bool HasVariance { get; }

Property Value

bool

Hours

Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of hours.

public Tolerance Hours { get; }

Property Value

Tolerance

IsUnsetOrDefault

Returns true if the current tolerance has not been set or is using the default.

public bool IsUnsetOrDefault { get; }

Property Value

bool

Milliseconds

Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of milliseconds.

public Tolerance Milliseconds { get; }

Property Value

Tolerance

Minutes

Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of minutes.

public Tolerance Minutes { get; }

Property Value

Tolerance

Mode

Gets the ToleranceMode for the current Tolerance

public ToleranceMode Mode { get; }

Property Value

ToleranceMode

Percent

Returns a new tolerance, using the current amount as a percentage.

public Tolerance Percent { get; }

Property Value

Tolerance

Seconds

Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of seconds.

public Tolerance Seconds { get; }

Property Value

Tolerance

Ticks

Returns a new tolerance with a TimeSpan as the amount, using the current amount as a number of clock ticks.

public Tolerance Ticks { get; }

Property Value

Tolerance

Ulps

Returns a new tolerance, using the current amount in Ulps

public Tolerance Ulps { get; }

Property Value

Tolerance

Methods

ApplyToValue(object)

Apply the tolerance to an expected value and return a Tolerance.Range that represents the acceptable values.

public Tolerance.Range ApplyToValue(object value)

Parameters

value object

Returns

Tolerance.Range

ToString()

Returns a string that represents the current object.

public override string? ToString()

Returns

string

A string that represents the current object.