using MiscUtil;
using NUnit.Framework;
namespace System
{
///
/// A set of tests for testing types that overload the equality operators
/// (== or !=).
///
/// The type that is to be tested.
public abstract class EqualityOperatorTests
{
[Test, Description("A test to ensure the following code produces the " +
"proper result: X == Y")]
public void EqualTest()
{
{
bool result = Operator.Equal(CreateX(), CreateEqual());
Assert.True(result, "The result of the operation was not what " +
"was expected");
}
{
bool result = Operator.Equal(CreateX(), CreateNotEqual());
Assert.False(result, "The result of the operation was not what " +
"was expected");
}
}
[Test, Description("A test to ensure the following code produces the " +
"proper result: Y == X")]
public void FlippedEqualTest()
{
{
bool result = Operator.Equal(CreateEqual(), CreateX());
Assert.True(result, "The result of the operation was not what " +
"was expected");
}
{
bool result = Operator.Equal(CreateNotEqual(), CreateX());
Assert.False(result, "The result of the operation was not what " +
"was expected");
}
}
[Test, Description("A test to ensure the following code produces the " +
"proper result: X != Y")]
public void NotEqualTest()
{
{
bool result = Operator.NotEqual(CreateX(), CreateEqual());
Assert.False(result, "The result of the operation was not what " +
"was expected");
}
{
bool result = Operator.NotEqual(CreateX(), CreateNotEqual());
Assert.True(result, "The result of the operation was not what " +
"was expected");
}
}
[Test, Description("A test to ensure the following code produces the " +
"proper result: Y != X")]
public void FlippedNotEqualTest()
{
{
bool result = Operator.NotEqual(CreateEqual(), CreateX() );
Assert.False(result, "The result of the operation was not what " +
"was expected");
}
{
bool result = Operator.NotEqual(CreateNotEqual(), CreateX());
Assert.True(result, "The result of the operation was not what " +
"was expected");
}
}
///
/// Creates an operand to be tested (or 'X').
///
/// The instance to be tested.
protected abstract T CreateX();
///
/// Creates an instance of type that is equal
/// to the instance created by .
///
/// The instance to be tested.
protected abstract T CreateEqual();
///
/// Creates an instance of type that is not
/// equal to the instance created by .
///
/// The instance to be tested.
protected abstract T CreateNotEqual();
}
///
/// A set of tests for testing the overloaded operators of references types.
/// In other words, these tests take into account null values. This class
/// also derives from so that the
/// the tests provided by that class are implemented.
///
/// The reference type that is to be tested.
public abstract class ReferenceEqualityOperatorTests : EqualityOperatorTests where T : class
{
[Test, Description("A test to ensure the following code produces the " +
"proper result: X == null")]
public void NullEqualTest()
{
bool result = Operator.Equal(CreateX(), null);
Assert.False(result, "The result of the operation was not what " +
"was expected");
}
[Test, Description("A test to ensure the following code produces the " +
"proper result: null == Y")]
public void FlippedNullEqualTest()
{
bool result = Operator.Equal(null, CreateX());
Assert.False(result, "The result of the operation was not what " +
"was expected");
}
[Test, Description("A test to ensure the following code produces the " +
"proper result: X != null")]
public void NullNotEqualTest()
{
bool result = Operator.NotEqual(CreateX(), null);
Assert.True(result, "The result of the operation was not what " +
"was expected");
}
[Test, Description("A test to ensure the following code produces the " +
"proper result: null != Y")]
public void FlippedNullNotEqualTest()
{
bool result = Operator.NotEqual(null, CreateX());
Assert.True(result, "The result of the operation was not what " +
"was expected");
}
}
}