public void CanGetPosition()
        {
            var list = new ChunkedList <int>(20);

            list.AddRange(Enumerable.Range(0, 10).ToArray());

            var en = list.GetEnumerator();

            en.Position.ShouldEqual(-1);

            for (int i = 0; i < 5; i++)
            {
                en.MoveNext().ShouldBeTrue();
            }

            en.Position.ShouldEqual(4);

            for (int i = 0; i < 4; i++)
            {
                en.MoveNext().ShouldBeTrue();
            }

            en.Position.ShouldEqual(8);

            while (en.MoveNext())
            {
                ;
            }

            en.Position.ShouldEqual(9);
        }
        public void CanGetCount()
        {
            var list = new ChunkedList <int>(20);

            list.AddRange(Enumerable.Range(1, 10).ToArray());
            var en = list.GetEnumerator();

            en.Count.ShouldEqual(10);
        }
        public void CanStartFromIndexPastEnd()
        {
            var list = new ChunkedList <int>(20);

            list.AddRange(Enumerable.Range(0, 10).ToArray());
            var en = list.GetEnumerator();

            en.FromIndex(10).ShouldBeTrue();
            en.Current.ShouldEqual(9);
            en.MoveNext().ShouldBeFalse();
        }
        public void CantStartFromNegativeIndex()
        {
            var list = new ChunkedList <int>(20);

            list.AddRange(Enumerable.Range(1, 10).ToArray());
            var en = list.GetEnumerator();

            en.MoveNext().ShouldBeTrue();
            en.Current.ShouldEqual(1);
            en.FromIndex(-1).ShouldBeFalse();
            en.Current.ShouldEqual(1);
        }
        public void CanStartFromIndexInBeginningOfBucket()
        {
            var list = new ChunkedList <int>(20);

            list.AddRange(Enumerable.Range(0, 10).ToArray());
            var en = list.GetEnumerator();

            en.FromIndex(6).ShouldBeTrue();
            en.Current.ShouldEqual(5);
            en.MoveNext().ShouldBeTrue();
            en.Current.ShouldEqual(6);
        }
        public void CanSetToLast()
        {
            var list = new ChunkedList <int>();

            list.AddRange(Enumerable.Range(1, 10).ToArray());
            var en = list.GetEnumerator();

            en.FromLast();
            en.HasMore.ShouldBeFalse();
            en.MovePrev().ShouldBeTrue();
            en.Current.ShouldEqual(10);
        }
Ejemplo n.º 7
0
        public void CanRaiseListUpdatedForMultipleItem()
        {
            var evt  = new ManualResetEventSlim();
            var list = new ChunkedList <int>();

            list.ListUpdated += (sender, args) =>
            {
                args.Count.ShouldEqual(10);
                evt.Set();
            };
            Task.Run(() => list.AddRange(Enumerable.Range(0, 10).ToArray()));

            evt.Wait();
        }
        public void CanEnumerateItemsInMultipleBuckets()
        {
            var list = new ChunkedList <int>(20);

            list.AddRange(Enumerable.Range(0, 10).ToArray());

            int idx = 0;

            foreach (var item in list)
            {
                item.ShouldEqual(idx);
                idx++;
            }
        }
        public void CanReset()
        {
            var list = new ChunkedList <int>(20);

            list.AddRange(Enumerable.Range(1, 10).ToArray());
            var en = list.GetEnumerator();

            en.MoveNext().ShouldBeTrue();
            en.Current.ShouldEqual(1);
            en.Reset();
            en.Current.ShouldEqual(0);
            en.MoveNext().ShouldBeTrue();
            en.Current.ShouldEqual(1);
        }
        public void CanComparePositions()
        {
            var list = new ChunkedList <int>(20);

            list.AddRange(Enumerable.Range(1, 10).ToArray());
            var en  = list.GetEnumerator();
            var en2 = list.GetEnumerator();

            en.MoveNext().ShouldBeTrue();
            en2.MoveNext().ShouldBeTrue();

            en.AsComparable().IsPositionEqual(en2.AsComparable()).ShouldBeTrue();
            en2.MoveNext().ShouldBeTrue();
            en.AsComparable().IsPositionEqual(en2.AsComparable()).ShouldBeFalse();
        }
        public void CanIterateBackwardsUntilNoMoreItems()
        {
            var list = new ChunkedList <int>(20);

            list.AddRange(Enumerable.Range(1, 10).ToArray());
            var en = list.GetEnumerator();

            en.FromLast();
            int idx = 10;

            while (en.MovePrev())
            {
                en.Current.ShouldEqual(idx);
                idx--;
            }
        }
        public void CanEnumerateBackwards()
        {
            var list = new ChunkedList <int>();

            list.AddRange(Enumerable.Range(1, 10).ToArray());
            var en = list.GetEnumerator();

            en.FromLast();
            en.HasMore.ShouldBeFalse();

            for (int i = 10; i > 0; i--)
            {
                en.MovePrev().ShouldBeTrue();
                en.Current.ShouldEqual(i);
            }
        }
        public void CanSetToFirst()
        {
            var list = new ChunkedList <int>();

            list.AddRange(Enumerable.Range(1, 10).ToArray());
            var en = list.GetEnumerator();

            while (en.HasMore)
            {
                en.MoveNext();
            }

            en.FromFirst();
            en.HasMore.ShouldBeTrue();
            en.MoveNext().ShouldBeTrue();
            en.Current.ShouldEqual(1);
        }
        public void CanCloneEnumerator()
        {
            var list = new ChunkedList <int>(20);

            list.AddRange(Enumerable.Range(0, 10).ToArray());

            var en = list.GetEnumerator();

            for (int i = 0; i < 5; i++)
            {
                en.MoveNext().ShouldBeTrue();
                en.Current.ShouldEqual(i);
            }

            en = en.Clone();
            for (int i = 5; i < 10; i++)
            {
                en.MoveNext().ShouldBeTrue();
                en.Current.ShouldEqual(i);
            }
        }
Ejemplo n.º 15
0
        public void CanAddRangeWithOneBucket()
        {
            var list = new ChunkedList <int>(40);            // 10 of Int32

            list.AddRange(Enumerable.Range(0, 10).ToArray());

            list.BucketCount.ShouldEqual(1);
            list.IsEmpty.ShouldBeFalse();
            list.Count.ShouldEqual(10);

            var buckets = list.Buckets;

            buckets.ShouldNotBeNull();
            buckets.Count.ShouldEqual(1);

            var bucket = list.Buckets[0];

            bucket.Buffer.ShouldNotBeNull();
            bucket.Buffer.Length.ShouldEqual(10);
            bucket.FreeSpace.ShouldEqual(0);
            bucket.Index.ShouldEqual(10);
            bucket.IsEmpty.ShouldBeFalse();
        }
Ejemplo n.º 16
0
        public void CanAddRange()
        {
            var list = new ChunkedList <int>(20);            // 5 of Int32

            list.AddRange(Enumerable.Range(0, 10).ToArray());

            list.BucketCount.ShouldEqual(2);
            list.IsEmpty.ShouldBeFalse();
            list.Count.ShouldEqual(10);

            var buckets = list.Buckets;

            buckets.ShouldNotBeNull();
            buckets.Count.ShouldEqual(2);

            foreach (var bucket in buckets)
            {
                bucket.Buffer.ShouldNotBeNull();
                bucket.Buffer.Length.ShouldEqual(5);
                bucket.FreeSpace.ShouldEqual(0);
                bucket.Index.ShouldEqual(5);
                bucket.IsEmpty.ShouldBeFalse();
            }
        }