public void Compare_NonGeneric_ForNonStrings_UsesToString(object x, object y) { var uut = new AlphanumericComparer(StringComparison.Ordinal); var expectedResult = uut.Compare(x.ToString(), y.ToString()); uut.Compare(x, y).ShouldBe(expectedResult); }
public void Compare_NonGeneric_ForStrings_MatchesGeneric(object x, object y) { var uut = new AlphanumericComparer(StringComparison.Ordinal); var expectedResult = uut.Compare(x, y); uut.Compare(x, y).ShouldBe(expectedResult); }
/// <summary> /// Compares two alphanumeric version numbers and returns a value /// indicating whether one is less than, equal to, or greater than the other. /// </summary> /// <param name="x">The first alphanumeric version number to compare.</param> /// <param name="y">The second alphanumeric version number to compare.</param> /// <returns>A signed integer that indicates the relative values of x and y.</returns> public int Compare(string x, string y) { // Validate parameters if (x == null) { throw new ArgumentNullException("x"); } if (y == null) { throw new ArgumentNullException("y"); } // Test for equality if (x == y) { return(0); } // Split the different parts of the number string[] xParts = x.Split('.'); string[] yParts = y.Split('.'); // Compare each parts AlphanumericComparer alphaNumComparer = new AlphanumericComparer(); for (int i = 0, n = Math.Max(xParts.Length, yParts.Length); i < n; i++) { // If the part at index i is not in y => x is greater if (i >= yParts.Length) { return(1); } // If the part at index i is not in x => y is greater if (i >= xParts.Length) { return(-1); } // Compare the two alphanumerical numbers int result = alphaNumComparer.Compare(xParts[i], yParts[i]); if (result != 0) { return(result); } } // The two numbers are equal (really??? I thought we tested for equality already!) System.Diagnostics.Debug.Fail("Not supposed to reach this code..."); return(0); }
public void Compare_Generic_ComparisonTypeIsIgnoreCase_IsCaseInsensitive(string x, string y, int expectedResult) { var uut = new AlphanumericComparer(StringComparison.OrdinalIgnoreCase); uut.Compare(x, y).ShouldBe(expectedResult); }
public void Compare_Generic_XIsEqualToY_Returns0(string x, string y) { var uut = new AlphanumericComparer(StringComparison.Ordinal); uut.Compare(x, y).ShouldBe(0); }
public void Compare_Generic_XIsGreaterThanY_Returns1(string x, string y) { var uut = new AlphanumericComparer(StringComparison.Ordinal); uut.Compare(x, y).ShouldBe(1); }
public void Compare_Generic_XIsLessThanY_ReturnsNegative1(string x, string y) { var uut = new AlphanumericComparer(StringComparison.Ordinal); uut.Compare(x, y).ShouldBe(-1); }