public void TestGetValuesWithThreeAdds() { RangeMinMax range = new RangeMinMax(); range.Add(5); range.Add(8); range.Add(7); // NOTE : we did NOT add a 6. List<int> expected = new List<int> { 5, 6, 7, 8 }; // NOTE : The 6 is expected because GetValues is intended to get all values within the Min to Max range // not just the values that were added. CollectionAssert.AreEqual(expected, range.GetValues(), "GetValues"); }
/// <summary> /// Parses a string comprising of a consolidated list of numbers and sorts the numbers into ascending order and returns the list. /// </summary> /// <param name="text">A string comprising a consolidated list of numbers. For example "5,1-3,8,10,15-18"</param> /// <returns>A list of integers in ascending order.</returns> public static List<int> ParseSortConsolidatedIntegerList(string text) { List<int> list = new List<int>(); string[] segments = text.Split(new char[] { ',' }); foreach (string segment in segments) { RangeMinMax range = new RangeMinMax(segment); list.AddRange(range.GetValues()); } return list.OrderBy(x => x).ToList(); }