public void TestRangeMinMaxTextWithSpaces()
        {
            // This is basically the exact same test as TestRangeMinMaxText but the input text has additional spaces
            string text;
            RangeMinMax range;

            List<string> items = new List<string> { "1", "5 - 7", "-1", "-1 - 5", "-6 - -5" };

            text = items[0];
            range = new RangeMinMax(text);
            Assert.AreEqual(1, range.Min, string.Format("Min '{0}'", text));
            Assert.AreEqual(1, range.Max, string.Format("Max '{0}'", text));

            text = items[1];
            range = new RangeMinMax(text);
            Assert.AreEqual(5, range.Min, string.Format("Min '{0}'", text));
            Assert.AreEqual(7, range.Max, string.Format("Max '{0}'", text));

            text = items[2];
            range = new RangeMinMax(text);
            Assert.AreEqual(-1, range.Min, string.Format("Min '{0}'", text));
            Assert.AreEqual(-1, range.Max, string.Format("Max '{0}'", text));

            text = items[3];
            range = new RangeMinMax(text);
            Assert.AreEqual(-1, range.Min, string.Format("Min '{0}'", text));
            Assert.AreEqual(5, range.Max, string.Format("Max '{0}'", text));

            text = items[4];
            range = new RangeMinMax(text);
            Assert.AreEqual(-6, range.Min, string.Format("Min '{0}'", text));
            Assert.AreEqual(-5, range.Max, string.Format("Max '{0}'", text));
        }
        public void TestRangeMinMaxText()
        {
            string text;
            RangeMinMax range;

            List<string> items = new List<string> { "1", "5-7", "-1", "-1-5", "-6--5" };

            text = items[0];
            range = new RangeMinMax(text);
            Assert.AreEqual(1, range.Min, string.Format("Min '{0}'", text));
            Assert.AreEqual(1, range.Max, string.Format("Max '{0}'", text));

            text = items[1];
            range = new RangeMinMax(text);
            Assert.AreEqual(5, range.Min, string.Format("Min '{0}'", text));
            Assert.AreEqual(7, range.Max, string.Format("Max '{0}'", text));

            text = items[2];
            range = new RangeMinMax(text);
            Assert.AreEqual(-1, range.Min, string.Format("Min '{0}'", text));
            Assert.AreEqual(-1, range.Max, string.Format("Max '{0}'", text));

            text = items[3];
            range = new RangeMinMax(text);
            Assert.AreEqual(-1, range.Min, string.Format("Min '{0}'", text));
            Assert.AreEqual(5, range.Max, string.Format("Max '{0}'", text));

            text = items[4];
            range = new RangeMinMax(text);
            Assert.AreEqual(-6, range.Min, string.Format("Min '{0}'", text));
            Assert.AreEqual(-5, range.Max, string.Format("Max '{0}'", text));
        }
        public void TestAddTwoValues()
        {
            RangeMinMax range = new RangeMinMax();
            range.Add(5);
            range.Add(8);

            Assert.AreEqual(5, range.Min, "Min");
            Assert.AreEqual(8, range.Max, "Max");
        }
        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");
        }
Exemplo n.º 5
0
        /// <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 &quot;5,1-3,8,10,15-18&quot;</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();
        }
 public void TestRangeMinMaxUsingMinMaxValues()
 {
     RangeMinMax range = new RangeMinMax(5, 9);
     Assert.AreEqual(5, range.Min, "Min");
     Assert.AreEqual(9, range.Max, "Max");
 }
 public void TestRangeMinMaxUsingListValues()
 {
     RangeMinMax range = new RangeMinMax(new List<int>{7, 9, 6});
     Assert.AreEqual(6, range.Min, "Min");
     Assert.AreEqual(9, range.Max, "Max");
 }