using NUnit.Framework;
namespace System
{
///
/// A set of tests for comparing types.
///
/// The type that is passed to
/// as its generic parameter. The type being
/// compared against.
public abstract class ComparableTests
{
[Test, Description("A test to ensure that the IComparable.CompareTo(T) " +
"method returns a value less than 0 when the instance passed to it " +
"is less than the IComparable.")]
public void LessThanTest()
{
IComparable comparable = CreateComparable();
T item = CreateLessThanObject();
int value = comparable.CompareTo(item);
Assert.Greater(value, 0, "The comparison showed that the IComparable " +
"was not less than the object passed to the IComparable.CompareTo(T) " +
"method even though it was supposed to be.");
}
[Test, Description("A test to ensure that the IComparable.CompareTo(T) " +
"method returns a value equal to 0 when the instance passed to it " +
"is equal to the IComparable.")]
public void EqualToTest()
{
IComparable comparable = CreateComparable();
T item = CreateEqualObject();
int value = comparable.CompareTo(item);
Assert.AreEqual(value, 0, "The comparison showed that the IComparable " +
"was not equal to the object passed to the IComparable.CompareTo(T) " +
"method even though it was supposed to be.");
}
[Test, Description("A test to ensure that the IComparable.CompareTo(T) " +
"method returns a value greater than 0 when the instance passed to " +
"it is greater than the IComparable.")]
public void GreaterThanTest()
{
IComparable comparable = CreateComparable();
T item = CreateGreaterThanObject();
int value = comparable.CompareTo(item);
Assert.Less(value, 0, "The comparison showed that the IComparable " +
"was not greater than the object passed to the IComparable.CompareTo(T) " +
"method even though it was supposed to be.");
}
///
/// Creates the instance that is to be
/// tested. This method should always create a new
/// when this method is invoked and never
/// reuse instances.
///
/// The to test.
protected abstract IComparable CreateComparable();
///
/// Creates an instance that should be less than the
/// created by
///
///
/// The instance to be tested against.
protected abstract T CreateLessThanObject();
///
/// Creates an instance that should be equal to the
/// created by
///
///
/// The instance to be tested against.
protected abstract T CreateEqualObject();
///
/// Creates an instance that should be greater than the
/// created by
///
///
/// The instance to be tested against.
protected abstract T CreateGreaterThanObject();
}
}