public void Peek_Branch_Test_1() { ArrayBasedQueue <int> queue = new ArrayBasedQueue <int>(1); Assert.That(() => queue.Peek(), Throws.TypeOf <InvalidOperationException>() .With.Message.EqualTo("There are no items in the queue.")); }
public void Enqueue_Branch_Test_2() { ArrayBasedQueue <int> queue = new ArrayBasedQueue <int>(2); queue.Enqueue(1); Assert.Multiple(() => { Assert.AreEqual(queue.Peek(), 1); Assert.IsFalse(queue.IsFull()); Assert.IsFalse(queue.IsEmpty()); }); }
public static void PeekEmptyQueueThrowsInvalidOperationException() { // Arrange var q = new ArrayBasedQueue <int>(1); Exception?exception = null; // Act try { q.Peek(); } catch (Exception ex) { exception = ex; } // Assert Assert.AreEqual(expected: typeof(InvalidOperationException), actual: exception?.GetType()); }
public static void PeekWorksCorrectly() { // Arrange var q = new ArrayBasedQueue <int>(2); q.Enqueue(1); q.Enqueue(2); int peeked = 0; // Act for (int i = 0; i < 3; i++) { peeked = q.Peek(); } // Assert Assert.AreEqual(expected: 1, actual: peeked); Assert.IsFalse(q.IsEmpty(), "Queue is empty"); Assert.IsTrue(q.IsFull(), "Queue is full"); }