public void NumericUtility_CompressRange_1() { int[] array = { 1, 2, 3, 5, 6, 7 }; Assert.AreEqual("1-3, 5-7", NumericUtility.CompressRange(array)); Assert.AreEqual(string.Empty, NumericUtility.CompressRange(null)); }
private static string CompressIfPossible ( [NotNull] IEnumerable <string> numbers ) { string[] array1 = numbers.ToArray(); if (array1.All(n => n.IsPositiveInteger())) { int[] array2 = array1.Select(NumericUtility.ParseInt32).ToArray(); Array.Sort(array2); return(NumericUtility.CompressRange(array2)); } return(StringUtility.Join(", ", array1)); }
public void NumericUtility_CompressRange_2() { int[] array = new int[0]; Assert.AreEqual(string.Empty, NumericUtility.CompressRange(array)); }
/// <summary> /// Describe the database. /// </summary> public string Describe() { StringBuilder result = new StringBuilder(); result.AppendFormat ( "Name: {0}", Name.ToVisibleString() ); result.AppendLine(); result.AppendFormat ( "Description: {0}", Description.ToVisibleString() ); result.AppendLine(); if (!ReferenceEquals(LogicallyDeletedRecords, null)) { result.Append("Logically deleted records: "); result.AppendLine(NumericUtility.CompressRange ( LogicallyDeletedRecords )); } if (!ReferenceEquals(PhysicallyDeletedRecords, null)) { result.Append("Physically deleted records: "); result.AppendLine(NumericUtility.CompressRange ( PhysicallyDeletedRecords )); } if (!ReferenceEquals(NonActualizedRecords, null)) { result.Append("Non-actualized records: "); result.AppendLine(NumericUtility.CompressRange ( NonActualizedRecords )); } if (!ReferenceEquals(LockedRecords, null)) { result.Append("Locked records: "); result.AppendLine(NumericUtility.CompressRange ( LockedRecords )); } result.AppendFormat("Max MFN: {0}", MaxMfn); result.AppendLine(); result.AppendFormat("Read-only: {0}", ReadOnly); result.AppendLine(); result.AppendFormat ( "Database locked: {0}", DatabaseLocked ); result.AppendLine(); return(result.ToString()); }