Class ComparisonConstraint
Abstract base class for constraints that compare values to determine if one is greater than, equal to or less than the other.
Inheritance
Inherited Members
Namespace: NUnit.Framework.Constraints
Assembly: nunit.framework.dll
Syntax
public abstract class ComparisonConstraint : Constraint, IConstraint, IResolveConstraint
Constructors
View SourceComparisonConstraint(object, string)
Initializes a new instance of the ComparisonConstraint class.
Declaration
protected ComparisonConstraint(object expected, string comparisonText)
Parameters
Type | Name | Description |
---|---|---|
object | expected | The value against which to make a comparison. |
string | comparisonText | The text indicating the type of comparison. |
Properties
View SourceDescription
The Description of what this constraint tests, for use in messages and in the ConstraintResult.
Declaration
public override string Description { get; }
Property Value
Type | Description |
---|---|
string |
Overrides
View SourcePercent
Switches the .Within() modifier to interpret its tolerance as a percentage that the actual values is allowed to deviate from the expected value.
Declaration
public ComparisonConstraint Percent { get; }
Property Value
Type | Description |
---|---|
ComparisonConstraint | Self |
Methods
View SourceApplyTo<TActual>(TActual)
Test whether the constraint is satisfied by a given value
Declaration
public override ConstraintResult ApplyTo<TActual>(TActual actual)
Parameters
Type | Name | Description |
---|---|---|
TActual | actual | The value to be tested |
Returns
Type | Description |
---|---|
ConstraintResult | A ConstraintResult |
Type Parameters
Name | Description |
---|---|
TActual |
Overrides
View SourcePerformComparison(ComparisonAdapter, object, object, Tolerance)
Protected function overridden by derived class to actually perform the comparison
Declaration
protected abstract bool PerformComparison(ComparisonAdapter comparer, object actual, object expected, Tolerance tolerance)
Parameters
Type | Name | Description |
---|---|---|
ComparisonAdapter | comparer | |
object | actual | |
object | expected | |
Tolerance | tolerance |
Returns
Type | Description |
---|---|
bool |
Using(IComparer)
Modifies the constraint to use an IComparer and returns self
Declaration
public ComparisonConstraint Using(IComparer comparer)
Parameters
Type | Name | Description |
---|---|---|
IComparer | comparer | The comparer used for comparison tests |
Returns
Type | Description |
---|---|
ComparisonConstraint | A constraint modified to use the given comparer |
Using<T>(IComparer<T>)
Modifies the constraint to use an IComparer<T> and returns self
Declaration
public ComparisonConstraint Using<T>(IComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
IComparer<T> | comparer | The comparer used for comparison tests |
Returns
Type | Description |
---|---|
ComparisonConstraint | A constraint modified to use the given comparer |
Type Parameters
Name | Description |
---|---|
T |
Using<T>(Comparison<T>)
Modifies the constraint to use a Comparison<T> and returns self
Declaration
public ComparisonConstraint Using<T>(Comparison<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
Comparison<T> | comparer | The comparer used for comparison tests |
Returns
Type | Description |
---|---|
ComparisonConstraint | A constraint modified to use the given comparer |
Type Parameters
Name | Description |
---|---|
T |
Within(object)
Set the tolerance for use in this comparison
Declaration
public ComparisonConstraint Within(object amount)
Parameters
Type | Name | Description |
---|---|---|
object | amount |
Returns
Type | Description |
---|---|
ComparisonConstraint |