public void EqualRangeTest() { int[] data = { 1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6 }; IList <int> lst = new List <int>(); using (IInputIterator <int> inputIterator = new InputIterator <int>(data)) { KeyValuePair <int, int> result = Algorithm.EqualRange(inputIterator, 4); int lowerBound = result.Key; int upperBound = result.Value; int count = upperBound - lowerBound; using (IInputIterator <int> inputIterator2 = new RangeInputIterator <int>(data, lowerBound, count)) { using (IOutputIterator <int> outputIterator = new BackInsertIterator <int>(lst)) { Algorithm.Copy(inputIterator2, outputIterator); } } } Assert.IsTrue(lst.Count() == 3); Assert.IsTrue(lst[0] == 4 && lst[1] == 4 && lst[2] == 4); }
public void RangeIteratorTest2() { int[] data = { 1, 2, 3, 4 }; int[] output = new int[2]; using (IInputIterator <int> inputIterator = new RangeInputIterator <int>(data, 1, 2)) { int index = 0; while (!inputIterator.IsEnd()) { output[index] = inputIterator.Read(); inputIterator.MoveNext(); ++index; } Assert.IsTrue(output[0] == 2 && output[1] == 3); } }
public void BoundTest() { int[] data = { 1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6 }; IList <int> lst = new List <int>(); using (IInputIterator <int> inputIterator = new InputIterator <int>(data)) { ICursor cursor = inputIterator as ICursor; Algorithm.LowerBound(inputIterator, 4); int lowerBoundIndex = cursor.GetPosition(); inputIterator.Begin(); Algorithm.UpperBound(inputIterator, 4); int upperBoundIndex = cursor.GetPosition(); int count = upperBoundIndex - lowerBoundIndex; using (IInputIterator <int> inputIterator2 = new RangeInputIterator <int>(data, lowerBoundIndex, count)) { using (IOutputIterator <int> outputIterator = new BackInsertIterator <int>(lst)) { Algorithm.Copy(inputIterator2, outputIterator); } } } Assert.IsTrue(lst.Count() == 3); Assert.IsTrue(lst[0] == 4 && lst[1] == 4 && lst[2] == 4); }