using MiscUtil; using NUnit.Framework; namespace System { /// /// A set of tests for testing types that overload the relational operators: /// less than (<), (>)>, less than or equal to (<)=, or /// greater than or equal to (>=). /// /// The type that is to be tested. public abstract class RelationalOperatorTests { [Test, Description("A test to ensure the following code produces the " + "proper result: X < Y")] public void LessThanTest() { { bool result = Operator.LessThan(CreateX(), CreateLessThan()); Assert.False(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.LessThan(CreateX(), CreateEqual()); Assert.False(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.LessThan(CreateX(), CreateGreaterThan()); 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 FlippedLessThanTest() { { bool result = Operator.LessThan(CreateLessThan(), CreateX()); Assert.True(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.LessThan(CreateEqual(), CreateX()); Assert.False(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.LessThan(CreateGreaterThan(), 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 GreaterThanTest() { { bool result = Operator.GreaterThan(CreateX(), CreateLessThan()); Assert.True(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.GreaterThan(CreateX(), CreateEqual()); Assert.False(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.GreaterThan(CreateX(), CreateGreaterThan()); 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 FlippedGreaterThanTest() { { bool result = Operator.GreaterThan(CreateLessThan(), CreateX()); Assert.False(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.GreaterThan(CreateEqual(), CreateX()); Assert.False(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.GreaterThan(CreateGreaterThan(), CreateX()); 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: X <= Y")] public void LessThanOrEqualToTest() { { bool result = Operator.LessThanOrEqual(CreateX(), CreateLessThan()); Assert.False(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.LessThanOrEqual(CreateX(), CreateEqual()); Assert.True(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.LessThanOrEqual(CreateX(), CreateGreaterThan()); 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 FlippedLessThanOrEqualToTest() { { bool result = Operator.LessThanOrEqual(CreateLessThan(), CreateX()); Assert.True(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.LessThanOrEqual(CreateEqual(), CreateX()); Assert.True(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.LessThanOrEqual(CreateGreaterThan(), 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 GreaterThanOrEqualToTest() { { bool result = Operator.GreaterThanOrEqual(CreateX(), CreateLessThan()); Assert.True(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.GreaterThanOrEqual(CreateX(), CreateEqual()); Assert.True(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.GreaterThanOrEqual(CreateX(), CreateGreaterThan()); 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 FlippedGreaterThanOrEqualToTest() { { bool result = Operator.GreaterThanOrEqual(CreateLessThan(), CreateX()); Assert.False(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.GreaterThanOrEqual(CreateEqual(), CreateX()); Assert.True(result, "The result of the operation was not what " + "was expected."); } { bool result = Operator.GreaterThanOrEqual(CreateGreaterThan(), 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 the less than. /// /// protected abstract T CreateLessThan(); /// /// 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 greater /// than the instance created by . /// /// The instance to be tested. protected abstract T CreateGreaterThan(); } }