public void TestEnqueue() { int value = Generator.GetInt32(); var queue = ImmutableTreeQueue.Create <int>(); Assert.Empty(queue); // Enqueue doesn't change the original queue queue.Enqueue(value); Assert.Empty(queue); queue = queue.Enqueue(value); Assert.Single(queue); Assert.Equal(value, queue.Peek()); int[] expected = { value }; int[] actual = queue.ToArray(); Assert.Equal(expected, actual); // Test through the IImmutableQueue<T> interface IImmutableQueue <int> immutableQueue = queue; immutableQueue.Enqueue(Generator.GetInt32()); Assert.Equal(expected, immutableQueue); int nextValue = Generator.GetInt32(); immutableQueue = immutableQueue.Enqueue(nextValue); Assert.Equal(new[] { value, nextValue }, immutableQueue); }
public void TestMultipleElementQueue() { var values = new[] { Generator.GetInt32(), Generator.GetInt32(), Generator.GetInt32() }; var queue = ImmutableTreeQueue.Create(values); Assert.Equal(values, queue); }
public void TestSingleElementQueue() { var value = Generator.GetInt32(); var queue = ImmutableTreeQueue.Create(value); Assert.Equal(new[] { value }, queue); }
public void TestIEnumeratorT() { var queue = ImmutableTreeQueue.Create <int>(); IEnumerator <int> enumerator = queue.GetEnumerator(); 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); Assert.False(enumerator.MoveNext()); Assert.Equal(1, enumerator.Current); enumerator.Reset(); Assert.Equal(0, enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.Equal(1, enumerator.Current); enumerator.Reset(); Assert.Equal(0, enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.Equal(1, enumerator.Current); Assert.False(enumerator.MoveNext()); Assert.Equal(1, enumerator.Current); }
public void TestEmptyImmutableTreeQueue() { var queue = ImmutableTreeQueue.Create <int>(); Assert.Same(ImmutableTreeQueue <int> .Empty, queue); Assert.Empty(queue); }
public void TestQueueLikeBehavior() { var queue = ImmutableTreeQueue.Create <int>(); var reference = new Queue <int>(); for (int i = 0; i < 2 * 4 * 4; i++) { int item = Generator.GetInt32(); queue = queue.Enqueue(item); reference.Enqueue(item); } while (!queue.IsEmpty) { var expected = reference.Peek(); Assert.Equal(expected, queue.Peek()); Assert.Equal(expected, reference.Dequeue()); IImmutableQueue <int> immutableQueue = queue; queue = queue.Dequeue(out int value); Assert.Equal(expected, value); queue.Validate(ValidationRules.None); Assert.Equal(reference, queue); // Test through the IImmutableQueue<T> interface (initialized above) immutableQueue = immutableQueue.Dequeue(out value); Assert.Equal(expected, value); Assert.Equal(reference, immutableQueue); } Assert.Empty(queue); Assert.Empty(reference); }
public void TestEnqueueStaysPacked() { var queue = ImmutableTreeQueue.Create <int>(); for (int i = 0; i < 4 * 8 * 8; i++) { queue.Enqueue(i); } queue.Validate(ValidationRules.RequirePacked); }