public void Enqueue_ReturnsTrue() { var queue = new DynamicQueue<int>(); queue.Enqueue(10); queue.Enqueue(100); queue.Enqueue(200); //should be three items in the queue Assert.IsTrue(queue.CurrentSize == 3); }
static void Main(string[] args) { DynamicQueue<int> queue = new DynamicQueue<int>(); queue.Enqueue(5); queue.Enqueue(31); queue.Enqueue(100); Console.WriteLine(queue.Contains(101)); Console.WriteLine(queue.Peek()); Console.WriteLine(queue.Peek()); Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Peek()); queue.Enqueue(666); Console.WriteLine(queue.Dequeue()); }
public void IsEmpty_ReturnsFalse() { var queue = new DynamicQueue<int>(); queue.Enqueue(29); var result = queue.IsEmpty(); Assert.IsTrue(result == false); }
public void Clear_NonEmptyQueue_CurrentSizeIsZero() { var queue = new DynamicQueue<int>(); queue.Enqueue(10); queue.Clear(); Assert.IsTrue(queue.CurrentSize == 0); }
public void Enqueue(T element) { if (_tail - _head == Size) { var queue = new DynamicQueue(_head); while (NonEmpty) { queue.Enqueue(Dequeue()); } queue.Enqueue(element); _boundedBuffer._q = queue; } else { _queue[_tail & Mask] = element; _tail += 1; } }
static void Main(string[] args) { DynamicQueue<int> queue = new DynamicQueue<int>(); Console.WriteLine("Enqueue first number: 5"); queue.Enqueue(5); Console.WriteLine("Enqueue first number: 6"); queue.Enqueue(6); Console.WriteLine("Enqueue first number: 7"); queue.Enqueue(7); Console.WriteLine("Enqueue first number: 8"); queue.Enqueue(8); Console.WriteLine("Current count is: {0}", queue.Count()); Console.WriteLine("Check first enqueued element: {0}", queue.Peek()); Console.WriteLine("Dequeue element"); var element = queue.Dequeue(); Console.WriteLine("The dequeued element is: {0}", element); Console.WriteLine("Queue count after dequeuing an element: {0}", queue.Count()); }
public void TestContains_ValueIsContained() { DynamicQueue <int> queue = new DynamicQueue <int>(); for (int i = 1; i <= 5; i++) { queue.Enqueue(i); } Assert.AreEqual(true, queue.Contains(5)); }
public void TestEnqueue() { DynamicQueue <int> queue = new DynamicQueue <int>(); for (int i = 1; i <= 5; i++) { queue.Enqueue(i); } Assert.AreEqual(5, queue.Count); Assert.AreEqual(1, queue.Peek()); }
public void Dequeue_ReturnsItems() { var queue = new DynamicQueue<int>(); queue.Enqueue(10); queue.Enqueue(100); queue.Enqueue(200); //should be three items in the queue Assert.IsTrue(queue.CurrentSize == 3); var item = queue.Dequeue(); //dequeued item should be 10 Assert.IsTrue(item == 10); //items in the queue should be 2 Assert.IsTrue(queue.CurrentSize == 2); item = queue.Dequeue(); //dequeued item should be 100 Assert.IsTrue(item == 100); //items in the queue should be 1 Assert.IsTrue(queue.CurrentSize == 1); item = queue.Dequeue(); //dequeued item should be 200 Assert.IsTrue(item == 200); //items in the queue should be 0 and queue is empty Assert.IsTrue(queue.CurrentSize ==0); Assert.IsTrue(queue.IsEmpty() == true); }
public void TestDequeue_NonEmptyQueue() { DynamicQueue <int> queue = new DynamicQueue <int>(); int[] arr = new int[5]; for (int i = 1; i <= 5; i++) { queue.Enqueue(i); arr[i - 1] = i; } int value = 0; for (int i = 0; i < 5; i++) { value = queue.Dequeue(); Assert.AreEqual(arr[i], value); } Assert.AreEqual(0, queue.Count); }