Ejemplo n.º 1
0
        /// <summary>
        /// Internal test function.
        /// </summary>
        private static bool CheckTypedRangeSet(TypedRangeSet set, int expectedRanges,
                                               Tuple[] expected)
        {
            if (set.RangeCount != expectedRanges)
            {
                Debug.WriteLine("Expected " + expectedRanges + " ranges, got " +
                                set.RangeCount);
                return(false);
            }

            // Compare actual vs. expected. If we have more actual than expected we'll
            // throw on the array access.
            int expIndex = 0;

            foreach (TypedRangeSet.Tuple val in set)
            {
                if (val != expected[expIndex])
                {
                    Debug.WriteLine("Expected " + expected[expIndex] + ", got " + val);
                    return(false);
                }
                expIndex++;
            }

            // See if we have more expected than actual.
            if (expIndex != expected.Length)
            {
                Debug.WriteLine("Expected " + expected.Length + " elements, found " + expIndex);
                return(false);
            }

            // The count is maintained separately, so check it.
            if (set.Count != expected.Length)
            {
                Debug.WriteLine("Expected Count=" + expected.Length + ", got " + set.Count);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes unit tests.
        /// </summary>
        /// <returns>True if all goes well.</returns>
        public static bool Test()
        {
            bool result = true;

            TypedRangeSet one = new TypedRangeSet();

            one.Add(7, 100);
            one.Add(5, 100);
            one.Add(3, 100);
            one.Add(9, 100);
            one.Add(7, 100);
            one.Add(8, 100);
            one.Add(2, 100);
            one.Add(4, 100);
            result &= CheckTypedRangeSet(one, 2, new Tuple[] {
                new Tuple(2, 100),
                new Tuple(3, 100),
                new Tuple(4, 100),
                new Tuple(5, 100),
                new Tuple(7, 100),
                new Tuple(8, 100),
                new Tuple(9, 100)
            });

            one.Remove(2);
            one.Remove(9);
            one.Remove(4);
            result &= CheckTypedRangeSet(one, 3, new Tuple[] {
                new Tuple(3, 100),
                new Tuple(5, 100),
                new Tuple(7, 100),
                new Tuple(8, 100)
            });

            one.Clear();
            one.Add(1, 200);
            one.Add(3, 100);
            one.Add(7, 100);
            one.Add(5, 100);
            one.Add(9, 100);
            one.Add(6, 100);
            one.Add(8, 100);
            one.Add(6, 200);
            one.Add(2, 200);
            one.Add(4, 300);
            one.Add(4, 100);
            result &= CheckTypedRangeSet(one, 4, new Tuple[] {
                new Tuple(1, 200),
                new Tuple(2, 200),
                new Tuple(3, 100),
                new Tuple(4, 100),
                new Tuple(5, 100),
                new Tuple(6, 200),
                new Tuple(7, 100),
                new Tuple(8, 100),
                new Tuple(9, 100)
            });

            one.Add(6, 100);
            result &= CheckTypedRangeSet(one, 2, new Tuple[] {
                new Tuple(1, 200),
                new Tuple(2, 200),
                new Tuple(3, 100),
                new Tuple(4, 100),
                new Tuple(5, 100),
                new Tuple(6, 100),
                new Tuple(7, 100),
                new Tuple(8, 100),
                new Tuple(9, 100)
            });

            Debug.WriteLine("TypedRangeSet: test complete (ok=" + result + ")");
            return(result);
        }
Ejemplo n.º 3
0
 // IEnumerator<Tuple>
 public void Dispose()
 {
     mSet = null;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="set">TypedRangeSet to iterate over.</param>
 public TypedRangeSetIterator(TypedRangeSet set)
 {
     mSet = set;
     Reset();
 }