Ejemplo n.º 1
0
            public void BasicInsert(T?[] items, T?item, int index, int repeat)
            {
                SegmentedList <T?> list = new SegmentedList <T?>(items);

                for (int i = 0; i < repeat; i++)
                {
                    list.Insert(index, item);
                }

                Assert.True(list.Contains(item));                //"Expect it to contain the item."
                Assert.Equal(list.Count, items.Length + repeat); //"Expect to be the same."


                for (int i = 0; i < index; i++)
                {
                    Assert.Equal(list[i], items[i]); //"Expect to be the same."
                }

                for (int i = index; i < index + repeat; i++)
                {
                    Assert.Equal(list[i], item); //"Expect to be the same."
                }


                for (int i = index + repeat; i < list.Count; i++)
                {
                    Assert.Equal(list[i], items[i - repeat]); //"Expect to be the same."
                }
            }
Ejemplo n.º 2
0
            public void NonGenericIListBasicInsert(T?[] items, T?item, int index, int repeat)
            {
                SegmentedList <T?> list = new SegmentedList <T?>(items);
                IList _ilist            = list;

                for (int i = 0; i < repeat; i++)
                {
                    _ilist.Insert(index, item);
                }

                Assert.True(list.Contains(item));                //"Expected it to be true."
                Assert.Equal(list.Count, items.Length + repeat); //"Expected them to be equal."

                for (int i = 0; i < index; i++)
                {
                    Assert.Equal(list[i], items[i]); //"Expected them to be equal."
                }

                for (int i = index; i < index + repeat; i++)
                {
                    Assert.Equal((object?)list[i], item); //"Expected them to be equal."
                }


                for (int i = index + repeat; i < list.Count; i++)
                {
                    Assert.Equal(list[i], items[i - repeat]); //"Expected them to be equal."
                }
            }
Ejemplo n.º 3
0
            public void MultipleValues(T[] items, int times)
            {
                SegmentedList <T> list = new SegmentedList <T>(items);

                for (int i = 0; i < times; i++)
                {
                    list.Add(items[items.Length / 2]);
                }

                for (int i = 0; i < times + 1; i++)
                {
                    Assert.True(list.Contains(items[items.Length / 2])); //"Should contain item."
                    list.Remove(items[items.Length / 2]);
                }
                Assert.False(list.Contains(items[items.Length / 2])); //"Should not contain item"
            }
Ejemplo n.º 4
0
            public void NonExistingValues(T[] itemsX, T[] itemsY)
            {
                SegmentedList <T> list = new SegmentedList <T>(itemsX);

                for (int i = 0; i < itemsY.Length; i++)
                {
                    Assert.False(list.Contains(itemsY[i])); //"Should not contain item"
                }
            }
Ejemplo n.º 5
0
            public void BasicContains(T[] items)
            {
                SegmentedList <T> list = new SegmentedList <T>(items);

                for (int i = 0; i < items.Length; i++)
                {
                    Assert.True(list.Contains(items[i])); //"Should contain item."
                }
            }
Ejemplo n.º 6
0
            public void RemovedValues(T[] items)
            {
                SegmentedList <T> list = new SegmentedList <T>(items);

                for (int i = 0; i < items.Length; i++)
                {
                    list.Remove(items[i]);
                    Assert.False(list.Contains(items[i])); //"Should not contain item"
                }
            }
Ejemplo n.º 7
0
            public void InsertRangeIEnumerable(T?[] itemsX, T?[] itemsY, int index, int repeat, Func <T?[], IEnumerable <T?> > constructIEnumerable)
            {
                SegmentedList <T?> list = new SegmentedList <T?>(constructIEnumerable(itemsX));

                for (int i = 0; i < repeat; i++)
                {
                    list.InsertRange(index, constructIEnumerable(itemsY));
                }

                foreach (T?item in itemsY)
                {
                    Assert.True(list.Contains(item));                               //"Should contain the item."
                }
                Assert.Equal(list.Count, itemsX.Length + (itemsY.Length * repeat)); //"Should have the same result."

                for (int i = 0; i < index; i++)
                {
                    Assert.Equal(list[i], itemsX[i]); //"Should have the same result."
                }

                for (int i = index; i < index + (itemsY.Length * repeat); i++)
                {
                    Assert.Equal(list[i], itemsY[(i - index) % itemsY.Length]); //"Should have the same result."
                }

                for (int i = index + (itemsY.Length * repeat); i < list.Count; i++)
                {
                    Assert.Equal(list[i], itemsX[i - (itemsY.Length * repeat)]); //"Should have the same result."
                }

                //InsertRange into itself
                list = new SegmentedList <T?>(constructIEnumerable(itemsX));
                list.InsertRange(index, list);

                foreach (T?item in itemsX)
                {
                    Assert.True(list.Contains(item));                      //"Should contain the item."
                }
                Assert.Equal(list.Count, itemsX.Length + (itemsX.Length)); //"Should have the same result."

                for (int i = 0; i < index; i++)
                {
                    Assert.Equal(list[i], itemsX[i]); //"Should have the same result."
                }

                for (int i = index; i < index + (itemsX.Length); i++)
                {
                    Assert.Equal(list[i], itemsX[(i - index) % itemsX.Length]); //"Should have the same result."
                }

                for (int i = index + (itemsX.Length); i < list.Count; i++)
                {
                    Assert.Equal(list[i], itemsX[i - (itemsX.Length)]); //"Should have the same result."
                }
            }
Ejemplo n.º 8
0
            public void ContainsNullWhenReference(T?[] items, T?value)
            {
                if ((object?)value != null)
                {
                    throw new ArgumentException("invalid argument passed to testcase");
                }

                SegmentedList <T?> list = new SegmentedList <T?>(items);

                list.Add(value);
                Assert.True(list.Contains(value)); //"Should contain item."
            }
Ejemplo n.º 9
0
            public void AddRemoveValues(T[] items)
            {
                SegmentedList <T> list = new SegmentedList <T>(items);

                for (int i = 0; i < items.Length; i++)
                {
                    list.Add(items[i]);
                    list.Remove(items[i]);
                    list.Add(items[i]);
                    Assert.True(list.Contains(items[i])); //"Should contain item."
                }
            }
Ejemplo n.º 10
0
        /// <summary>
        /// Helper function to create an HashSet fulfilling the given specific parameters. The function will
        /// create an HashSet using the Comparer constructor and then add values
        /// to it until it is full. It will begin by adding the desired number of matching,
        /// followed by random (deterministic) elements until the desired count is reached.
        /// </summary>
        protected IEnumerable <T> CreateSegmentedHashSet(IEnumerable <T>?enumerableToMatchTo, int count, int numberOfMatchingElements)
        {
            SegmentedHashSet <T> set = new SegmentedHashSet <T>(GetIEqualityComparer());
            int seed = 528;
            SegmentedList <T>?match = null;

            // Add Matching elements
            if (enumerableToMatchTo != null)
            {
                match = enumerableToMatchTo.ToSegmentedList();
                for (int i = 0; i < numberOfMatchingElements; i++)
                {
                    set.Add(match[i]);
                }
            }

            // Add elements to reach the desired count
            while (set.Count < count)
            {
                T toAdd = CreateT(seed++);
                while (set.Contains(toAdd) || (match != null && match.Contains(toAdd, GetIEqualityComparer()))) // Don't want any unexpectedly duplicate values
                {
                    toAdd = CreateT(seed++);
                }
                set.Add(toAdd);
            }

            // Validate that the Enumerable fits the guidelines as expected
            Debug.Assert(set.Count == count);
            if (match != null)
            {
                int actualMatchingCount = 0;
                foreach (T lookingFor in match)
                {
                    actualMatchingCount += set.Contains(lookingFor) ? 1 : 0;
                }
                Assert.Equal(numberOfMatchingElements, actualMatchingCount);
            }

            return(set);
        }