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); }
public static bool Populate(DropDownList dropDownList, string stateCode, string countyCode, string firstEntry, string firstEntryValue, string selectedValue = null, bool includeCode = false) { dropDownList.Items.Clear(); // handle the optional first (default) entry if (firstEntry != null) { if (firstEntryValue == null) { firstEntryValue = firstEntry; } dropDownList.AddItem(firstEntry, firstEntryValue, firstEntryValue == selectedValue); } if (IsNullOrWhiteSpace(stateCode) || IsNullOrWhiteSpace(countyCode)) { return(false); } var locals = GetNamesDictionary(stateCode, countyCode); if (locals.Count == 0) { return(false); } var comparer = new AlphanumericComparer(); foreach (var local in locals.OrderBy(kvp => kvp.Value, comparer)) { dropDownList.AddItem(local.Value + (includeCode ? $" ({local.Key})" : Empty), local.Key, local.Key == selectedValue); } return(true); }
/// <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); }
private IList <string> GetDistrictList(string proposedName, out bool hasDuplicates) { // break test string into non-generic words var nameWords = proposedName.SafeString() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Where(w => !GenericDistrictWords.Contains(w, StringComparer.OrdinalIgnoreCase)); // format a district list with potential conflicts highlighted in <em> tags var thereWereDuplicates = false; var comparer = new AlphanumericComparer(); var districtList = LocalDistricts.GetLocalsForCounty(StateCode, CountyCode) .Rows.Cast <DataRow>() .OrderBy(r => r.LocalDistrict(), comparer) .Select(r => // Use Format so line breaks can be inserted for readability // ReSharper disable once UseStringInterpolation Format("{0} ({1})", // Format parameter 0: // the district name, with any matching, non-generic words in <em> tags Join(" ", r.LocalDistrict() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(w => { if (!nameWords.Contains(w, StringComparer.OrdinalIgnoreCase)) { return(w); } thereWereDuplicates = true; return($"<em>{w}</em>"); })), r.LocalKey())).ToList(); hasDuplicates = thereWereDuplicates; return(districtList.Count == 0 ? null : districtList); }
private void ReportLocalReferendumsForAllLocals() { var comparer = new AlphanumericComparer(); var locals = _DataManager.GetDataSubset(new LocalFilter(), new RererendumOrderBy()) .GroupBy(r => r.LocalKey()) .OrderBy(g => g.First().LocalDistrict(), comparer) .ToList(); if (locals.Count == 0) { return; } var districtsOuter = new HtmlDiv().AddTo(ReportContainer, "districts-list print-current-state"); // ReSharper disable once PossibleNullReferenceException (new HtmlDiv().AddTo(districtsOuter, "accordion-header") as HtmlGenericControl).InnerHtml = "Local District Ballot Measures"; var districtsContainer = new HtmlDiv().AddTo(districtsOuter, "local-referendums-content accordion-content"); foreach (var local in locals) { var outer = new HtmlDiv().AddTo(districtsContainer, "referendums-list print-current-state no-print-closed"); // ReSharper disable once PossibleNullReferenceException (new HtmlDiv().AddTo(outer, "accordion-header") as HtmlGenericControl).InnerHtml = local.First().LocalDistrict(); var container = new HtmlDiv().AddTo(outer, "referendums-content accordion-content"); //CreateJurisdictionHeading(local.First() //.LocalDistrict()); foreach (var referendum in local) { ReportOneReferendum(container, referendum, true); } } }
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); }