private IndexOfDelegate IndexOfDelegateFromType(IndexOfMethod methodType)
        {
            switch (methodType)
            {
            case (IndexOfMethod.IndexOfT):
                return((list, value) => list.IndexOf(value));

            case (IndexOfMethod.IndexOfTInt):
                return((list, value) => list.IndexOf(value, 0));

            case (IndexOfMethod.IndexOfTIntInt):
                return((list, value) => list.IndexOf(value, 0, list.Count));

            case (IndexOfMethod.LastIndexOfT):
                return((list, value) => list.LastIndexOf(value));

            case (IndexOfMethod.LastIndexOfTInt):
                return((list, value) => list.LastIndexOf(value, list.Count - 1));

            case (IndexOfMethod.LastIndexOfTIntInt):
                return((list, value) => list.LastIndexOf(value, list.Count - 1, list.Count));

            default:
                throw new Exception("Invalid IndexOfMethod");
            }
        }
        private IndexOfDelegate IndexOfDelegateFromType(IndexOfMethod methodType)
        {
            switch (methodType)
            {
            case (IndexOfMethod.IndexOf_T):
                return((PooledList <T> list, T value) => { return list.IndexOf(value); });

            case (IndexOfMethod.IndexOf_T_int):
                return((PooledList <T> list, T value) => { return list.IndexOf(value, 0); });

            case (IndexOfMethod.IndexOf_T_int_int):
                return((PooledList <T> list, T value) => { return list.IndexOf(value, 0, list.Count); });

            case (IndexOfMethod.LastIndexOf_T):
                return((PooledList <T> list, T value) => { return list.LastIndexOf(value); });

            case (IndexOfMethod.LastIndexOf_T_int):
                return((PooledList <T> list, T value) => { return list.LastIndexOf(value, list.Count - 1); });

            case (IndexOfMethod.LastIndexOf_T_int_int):
                return((PooledList <T> list, T value) => { return list.LastIndexOf(value, list.Count - 1, list.Count); });

            default:
                throw new Exception("Invalid IndexOfMethod");
            }
        }
示例#3
0
        public void IndexOf_OrderIsCorrect(
            IndexOfMethod indexOfMethod,
            int count,
            bool frontToBackOrder
            )
        {
            SegmentedList <T> list = GenericListFactory(count);
            SegmentedList <T> withoutDuplicates = list.ToSegmentedList();

            list.AddRange(list);
            IndexOfDelegate IndexOf = IndexOfDelegateFromType(indexOfMethod);

            Assert.All(
                Enumerable.Range(0, count),
                i =>
            {
                if (frontToBackOrder)
                {
                    Assert.Equal(i, IndexOf(list, withoutDuplicates[i]));
                }
                else
                {
                    Assert.Equal(count + i, IndexOf(list, withoutDuplicates[i]));
                }
            }
                );
        }
示例#4
0
        public void IndexOf_NonExistingValues(
            IndexOfMethod indexOfMethod,
            int count,
            bool frontToBackOrder
            )
        {
            _ = frontToBackOrder;
            SegmentedList <T> list = GenericListFactory(count);
            IEnumerable <T>   nonexistentValues = CreateEnumerable(
                EnumerableType.List,
                list,
                count: count,
                numberOfMatchingElements: 0,
                numberOfDuplicateElements: 0
                );
            IndexOfDelegate IndexOf = IndexOfDelegateFromType(indexOfMethod);

            Assert.All(
                nonexistentValues,
                nonexistentValue =>
            {
                Assert.Equal(-1, IndexOf(list, nonexistentValue));
            }
                );
        }
        public void IndexOf_NoDuplicates(IndexOfMethod indexOfMethod, int count, bool frontToBackOrder)
        {
            var list         = GenericListFactory(count);
            var expectedList = list.ToList();
            var indexOf      = IndexOfDelegateFromType(indexOfMethod);

            Assert.All(Enumerable.Range(0, count), i =>
            {
                Assert.Equal(i, indexOf(list, expectedList[i]));
            });
        }
        public void IndexOf_NonExistingValues(IndexOfMethod indexOfMethod, int count, bool frontToBackOrder)
        {
            var list = GenericListFactory(count);
            var nonexistentValues = CreateEnumerable(TestBase.EnumerableType.List, list, count, 0, 0);
            var indexOf           = IndexOfDelegateFromType(indexOfMethod);

            Assert.All(nonexistentValues, nonexistentValue =>
            {
                Assert.Equal(-1, indexOf(list, nonexistentValue));
            });
        }
        public void IndexOf_DefaultValue(IndexOfMethod indexOfMethod, int count, bool frontToBackOrder)
        {
            var defaultValue = default(T);
            var list         = GenericListFactory(count);
            var indexOf      = IndexOfDelegateFromType(indexOfMethod);

            while (list.Remove(defaultValue))
            {
                count--;
            }
            list.Add(defaultValue);
            Assert.Equal(count, indexOf(list, defaultValue));
        }
示例#8
0
        public void IndexOf_DefaultValue(IndexOfMethod indexOfMethod, int count, bool frontToBackOrder)
        {
            _ = frontToBackOrder;
            T?defaultValue             = default;
            SegmentedList <T?> list    = GenericListFactory(count) !;
            IndexOfDelegate    IndexOf = IndexOfDelegateFromType(indexOfMethod);

            while (list.Remove(defaultValue))
            {
                count--;
            }
            list.Add(defaultValue);
            Assert.Equal(count, IndexOf(list !, defaultValue !));
        }
        public void IndexOf_DefaultValue(IndexOfMethod indexOfMethod, int count, bool frontToBackOrder)
        {
            T defaultValue          = default;
            PooledList <T>  list    = GenericListFactory(count);
            IndexOfDelegate IndexOf = IndexOfDelegateFromType(indexOfMethod);

            while (list.Remove(defaultValue))
            {
                count--;
            }
            list.Add(defaultValue);
            Assert.Equal(count, IndexOf(list, defaultValue));

            list.Dispose();
        }