public void NormalComparer() { var original = StringComparer.Ordinal; var subject = new ReverseComparer <string>(original); Assert.AreEqual(original.Compare("x", "y"), subject.Compare("y", "x")); Assert.AreEqual(0, subject.Compare("x", "x")); }
public void Simple() { var comparer = new ReverseComparer<int>(); Assert.AreEqual(comparer.Compare(2, 3), 1); Assert.AreEqual(comparer.Compare(3, 2), -1); Assert.AreEqual(comparer.Compare(0, 0), 0); Assert.AreEqual(comparer.Compare(0, 1), 1); Assert.AreEqual(comparer.Compare(1, 0), -1); }
public void Simple() { var comparer = new ReverseComparer <int>(); Assert.AreEqual(comparer.Compare(2, 3), 1); Assert.AreEqual(comparer.Compare(3, 2), -1); Assert.AreEqual(comparer.Compare(0, 0), 0); Assert.AreEqual(comparer.Compare(0, 1), 1); Assert.AreEqual(comparer.Compare(1, 0), -1); }
public void ReverseComparerReturnsZeroWhenFirstItemEqualsSecondItem() { var comparer = new ReverseComparer <int>(Comparer <int> .Default); int first = 1; int second = 1; int result = comparer.Compare(first, second); Assert.AreEqual(0, result); }
public void ReverseComparerReturnsPositiveOneWhenFirstItemIsLessThanSecondItem() { var comparer = new ReverseComparer <int>(Comparer <int> .Default); int first = 1; int second = 2; int result = comparer.Compare(first, second); Assert.AreEqual(1, result); }
public void CustomComparer_LessThan() { // Arrange var comparer = new CustomIntComparer(); var reversedComparer = new ReverseComparer <int>(comparer); // Act-Assert (Precondition) Assert.Equal(-2, comparer.Compare(1, 2)); // Act-Assert Assert.Equal(2, reversedComparer.Compare(1, 2)); }
public void ReverseDefaultIntegerComparer_LessThan() { // Arrange var comparer = Comparer <int> .Default; var reversedComparer = new ReverseComparer <int>(comparer); // Act-Assert (Precondition) Assert.Equal(-1, comparer.Compare(1, 2)); // Act-Assert Assert.Equal(1, reversedComparer.Compare(1, 2)); }
public void ReverseDefaultStringComparer_WithNull_GreaterThan() { // Arrange var comparer = Comparer <string> .Default; var reversedComparer = new ReverseComparer <string>(comparer); // Act-Assert (Precondition) Assert.Equal(1, comparer.Compare("A", null)); // Act-Assert Assert.Equal(-1, reversedComparer.Compare("A", null)); }
public void ReverseDefaultStringComparer_WithNull_LessEqual() { // Arrange var comparer = Comparer <string> .Default; var reversedComparer = new ReverseComparer <string>(comparer); // Act-Assert (Precondition) Assert.Equal(0, comparer.Compare(null, null)); // Act-Assert Assert.Equal(0, reversedComparer.Compare(null, null)); }
public void CustomComparer_Limits_GreaterThan() { // Arrange var comparer = new CustomIntComparerLimits(); var reversedComparer = new ReverseComparer <int>(comparer); // Act-Assert (Precondition) Assert.Equal(int.MaxValue, comparer.Compare(2, 1)); // Act-Assert Assert.Equal(int.MinValue, reversedComparer.Compare(2, 1)); }
public void Test_ReverseComparer_EqualTo() { // Arrange. IComparer <int> baseComparer = Comparer <int> .Default; IComparer <int> reverseComparer = new ReverseComparer <int>(baseComparer); // Act. int result = baseComparer.Compare(2, 2); int reversedResult = reverseComparer.Compare(2, 2); // Assert. Assert.Equal(result, reversedResult); Assert.Equal(0, result); Assert.Equal(0, reversedResult); }
public void Test_ReverseComparer_GreaterThan() { // Arrange. IComparer <int> baseComparer = Comparer <int> .Default; IComparer <int> reverseComparer = new ReverseComparer <int>(baseComparer); // Act. int result = baseComparer.Compare(2, 1); int reversedResult = reverseComparer.Compare(2, 1); // Assert. Assert.NotEqual(result, reversedResult); Assert.True(result > 0); Assert.True(reversedResult < 0); }