コード例 #1
0
        public void TestEnumerator()
        {
            ImmutableTreeQueue <int> queue = ImmutableTreeQueue <int> .Empty;

            ImmutableTreeQueue <int> .Enumerator enumerator = queue.GetEnumerator();
            Assert.Equal(0, enumerator.Current);
            Assert.False(enumerator.MoveNext());
            Assert.Equal(0, enumerator.Current);
            Assert.False(enumerator.MoveNext());
            Assert.Equal(0, enumerator.Current);

            // Adding an item to the queue does not invalidate an enumerator
            CollectionAssert.EnumeratorNotInvalidated(queue, () => queue.Enqueue(1));

            queue      = queue.Enqueue(1);
            enumerator = queue.GetEnumerator();
            Assert.Equal(0, enumerator.Current);
            Assert.True(enumerator.MoveNext());
            Assert.Equal(1, enumerator.Current);

            // Reset has no effect due to boxing the value type
            ((IEnumerator <int>)enumerator).Reset();
            Assert.Equal(1, enumerator.Current);
            Assert.False(enumerator.MoveNext());
            Assert.Equal(1, enumerator.Current);
        }
コード例 #2
0
        public void TestClear()
        {
            ImmutableTreeQueue <int> queue = ImmutableTreeQueue <int> .Empty;

            Assert.Same(queue, queue.Clear());

            foreach (int item in Enumerable.Range(0, 10))
            {
                queue = queue.Enqueue(item);
            }

            Assert.NotEmpty(queue);
            Assert.Same(ImmutableTreeQueue <int> .Empty, queue.Clear());

            // Test through the IImmutableQueue<T> interface
            IImmutableQueue <int> immutableQueue = queue;

            Assert.NotEmpty(immutableQueue);
            Assert.Same(ImmutableTreeQueue <int> .Empty, immutableQueue.Clear());
        }