1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// ****************************************************************
// Copyright 2011, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org
// ****************************************************************
using System;
namespace NUnit.Framework.Constraints
{
/// <summary>
/// Tests whether a value is greater than the value supplied to its constructor
/// </summary>
public class GreaterThanConstraint : ComparisonConstraint
{
/// <summary>
/// The value against which a comparison is to be made
/// </summary>
private object expected;
/// <summary>
/// Initializes a new instance of the <see cref="T:GreaterThanConstraint"/> class.
/// </summary>
/// <param name="expected">The expected value.</param>
public GreaterThanConstraint(object expected) : base(expected)
{
this.expected = expected;
}
/// <summary>
/// Write the constraint description to a MessageWriter
/// </summary>
/// <param name="writer">The writer on which the description is displayed</param>
public override void WriteDescriptionTo(MessageWriter writer)
{
writer.WritePredicate("greater than");
writer.WriteExpectedValue(expected);
}
/// <summary>
/// Test whether the constraint is satisfied by a given value
/// </summary>
/// <param name="actual">The value to be tested</param>
/// <returns>True for success, false for failure</returns>
public override bool Matches(object actual)
{
this.actual = actual;
if (expected == null || actual == null)
throw new ArgumentException("Cannot compare using a null reference");
return comparer.Compare(actual, expected) > 0;
}
}
}
|