Table of Contents

Class EqualConstraint

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

EqualConstraint is able to compare an actual value with the expected value provided in its constructor. Two objects are considered equal if both are null, or if both have the same value. NUnit has special semantics for some object types.

public class EqualConstraint : Constraint, IConstraint, IResolveConstraint
Inheritance
EqualConstraint
Implements
Inherited Members

Constructors

EqualConstraint(object)

Initializes a new instance of the EqualConstraint class.

public EqualConstraint(object expected)

Parameters

expected object

The expected value.

Properties

AsCollection

Flag the constraint to compare arrays as collections and return self.

public EqualConstraint AsCollection { get; }

Property Value

EqualConstraint

CaseInsensitive

Gets a value indicating whether to compare case insensitive.

public bool CaseInsensitive { get; }

Property Value

bool

true if comparing case insensitive; otherwise, false.

ClipStrings

Gets a value indicating whether or not to clip strings.

public bool ClipStrings { get; }

Property Value

bool

true if set to clip strings otherwise, false.

Days

Causes the tolerance to be interpreted as a TimeSpan in days.

public EqualConstraint Days { get; }

Property Value

EqualConstraint

Self

Description

The Description of what this constraint tests, for use in messages and in the ConstraintResult.

public override string Description { get; }

Property Value

string

FailurePoints

Gets the failure points.

public IList<NUnitEqualityComparer.FailurePoint> FailurePoints { get; }

Property Value

IList<NUnitEqualityComparer.FailurePoint>

The failure points.

Hours

Causes the tolerance to be interpreted as a TimeSpan in hours.

public EqualConstraint Hours { get; }

Property Value

EqualConstraint

Self

IgnoreCase

Flag the constraint to ignore case and return self.

public EqualConstraint IgnoreCase { get; }

Property Value

EqualConstraint

Milliseconds

Causes the tolerance to be interpreted as a TimeSpan in milliseconds.

public EqualConstraint Milliseconds { get; }

Property Value

EqualConstraint

Self

Minutes

Causes the tolerance to be interpreted as a TimeSpan in minutes.

public EqualConstraint Minutes { get; }

Property Value

EqualConstraint

Self

NoClip

Flag the constraint to suppress string clipping and return self.

public EqualConstraint NoClip { get; }

Property Value

EqualConstraint

Percent

Switches the .Within() modifier to interpret its tolerance as a percentage that the actual _values is allowed to deviate from the expected value.

public EqualConstraint Percent { get; }

Property Value

EqualConstraint

Self

Seconds

Causes the tolerance to be interpreted as a TimeSpan in seconds.

public EqualConstraint Seconds { get; }

Property Value

EqualConstraint

Self

Ticks

Causes the tolerance to be interpreted as a TimeSpan in clock ticks.

public EqualConstraint Ticks { get; }

Property Value

EqualConstraint

Self

Tolerance

Gets the tolerance for this comparison.

public Tolerance Tolerance { get; }

Property Value

Tolerance

The tolerance.

Ulps

Switches the .Within() modifier to interpret its tolerance as a distance in representable _values (see remarks).

public EqualConstraint Ulps { get; }

Property Value

EqualConstraint

Self.

Remarks

Ulp stands for "unit in the last place" and describes the minimum amount a given value can change. For any integers, an ulp is 1 whole digit. For floating point _values, the accuracy of which is better for smaller numbers and worse for larger numbers, an ulp depends on the size of the number. Using ulps for comparison of floating point results instead of fixed tolerances is safer because it will automatically compensate for the added inaccuracy of larger numbers.

Methods

ApplyTo<TActual>(TActual)

Test whether the constraint is satisfied by a given value

public override ConstraintResult ApplyTo<TActual>(TActual actual)

Parameters

actual TActual

The value to be tested

Returns

ConstraintResult

True for success, false for failure

Type Parameters

TActual

Using(IComparer)

Flag the constraint to use the supplied IComparer object.

public EqualConstraint Using(IComparer comparer)

Parameters

comparer IComparer

The IComparer object to use.

Returns

EqualConstraint

Self.

Using(IEqualityComparer)

Flag the constraint to use the supplied IEqualityComparer object.

public EqualConstraint Using(IEqualityComparer comparer)

Parameters

comparer IEqualityComparer

The IComparer object to use.

Returns

EqualConstraint

Self.

Using<T>(IComparer<T>)

Flag the constraint to use the supplied IComparer object.

public EqualConstraint Using<T>(IComparer<T> comparer)

Parameters

comparer IComparer<T>

The IComparer object to use.

Returns

EqualConstraint

Self.

Type Parameters

T

Using<T>(IEqualityComparer<T>)

Flag the constraint to use the supplied IEqualityComparer object.

public EqualConstraint Using<T>(IEqualityComparer<T> comparer)

Parameters

comparer IEqualityComparer<T>

The IComparer object to use.

Returns

EqualConstraint

Self.

Type Parameters

T

Using<T>(Comparison<T>)

Flag the constraint to use the supplied Comparison object.

public EqualConstraint Using<T>(Comparison<T> comparer)

Parameters

comparer Comparison<T>

The IComparer object to use.

Returns

EqualConstraint

Self.

Type Parameters

T

Within(object)

Flag the constraint to use a tolerance when determining equality.

public EqualConstraint Within(object amount)

Parameters

amount object

Tolerance value to be used

Returns

EqualConstraint

Self.