示例#1
0
        public void TestFindIndex()
        {
            ImmutableSortedTreeList <int> .Builder list = ImmutableSortedTreeList.CreateBuilder <int>();
            var reference = new List <int>();

            for (int i = 0; i < 4 * 8 * 8; i++)
            {
                int item = Generator.GetInt32(list.Count + 1);
                list.Add(item);
                reference.Add(item);
            }

            reference.Sort();

            Assert.Throws <ArgumentNullException>(() => list.FindIndex(null !));
            Assert.Throws <ArgumentNullException>(() => list.FindIndex(0, null !));
            Assert.Throws <ArgumentNullException>(() => list.FindIndex(0, 0, null !));

            Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(-1, i => true));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(0, -1, i => true));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(0, list.Count + 1, i => true));

            Assert.Equal(-1, list.FindIndex(_ => false));

            for (int i = 0; i < list.Count; i++)
            {
                Predicate <int> predicate = value => value == i;
                Assert.Equal(reference.FindIndex(predicate), list.FindIndex(predicate));

                int firstIndex = list.FindIndex(predicate);
                Assert.Equal(reference.FindIndex(firstIndex + 1, predicate), list.FindIndex(firstIndex + 1, predicate));
            }

            ImmutableSortedTreeList <int> .Builder empty = ImmutableSortedTreeList.CreateBuilder <int>();
            Assert.Equal(-1, empty.FindIndex(i => true));
        }