public void MyQueue_2_Enqueue_5_DequeueIsOkAfter3Enqueue() { // Arrange IMyQueue <string> stack = DSBuilder.CreateMyQueue(); string expected = "a"; // Act stack.Enqueue("a"); stack.Enqueue("b"); stack.Enqueue("c"); string actual = stack.Dequeue(); // Assert Assert.AreEqual(expected, actual); }
public void MyQueue_2_Enqueue_2_GetFrontIsOkAfter1Enqueue() { // Arrange IMyQueue <string> stack = DSBuilder.CreateMyQueue(); string expected = "a"; // Act stack.Enqueue("a"); string actual = stack.GetFront(); // Assert Assert.AreEqual(expected, actual); }
public void MyQueue_2_Enqueue_1_IsEmptyReturnsFalse() { // Arrange IMyQueue <string> stack = DSBuilder.CreateMyQueue(); bool expected = false; // Act stack.Enqueue("a"); bool actual = stack.IsEmpty(); // Assert Assert.AreEqual(expected, actual); }
public void Put(TKey key, TValue value) { if (_dict.Count == _size) { var valToRemove = _queue.Dequeue(); _dict.Remove(valToRemove.Key); } if (_dict.ContainsKey(key)) { var temp = _dict[key]; _queue.Dequeue(temp); _dict.Remove(key); } var node = new MyNode <TKey, TValue>() { Key = key, Value = value, }; _dict.Add(key, node); _queue.Enqueue(node); }
public void MyQueue_4_Dequeue_2_IsEmptyReturnsTrueAfterGetFrontOnOneElement() { // Arrange IMyQueue <string> stack = DSBuilder.CreateMyQueue(); bool expected = true; // Act stack.Enqueue("a"); stack.Dequeue(); bool actual = stack.IsEmpty(); // Assert Assert.AreEqual(expected, actual); }
public void MyQueue_3_GetBack_2_IsEmptyReturnsFalseAfterGetBackOnOneElement() { // Arrange IMyQueue <string> stack = DSBuilder.CreateMyQueue(); bool expected = false; // Act stack.Enqueue("a"); stack.GetBack(); bool actual = stack.IsEmpty(); // Assert Assert.AreEqual(expected, actual); }
static void Test(IMyQueue <int> queue) { foreach (int i in Enumerable.Range(0, 9)) { queue.Enqueue(i); } Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Peek()); foreach (int i in Enumerable.Repeat(2, 5)) { queue.Enqueue(i); } try { while (true) { Console.WriteLine(queue.Dequeue()); } } catch (InvalidOperationException) { Console.WriteLine("Queue is empty"); } }