Beispiel #1
0
        public void Dequeue_Branch_Test_3()
        {
            ArrayBasedQueue <int> queue = new ArrayBasedQueue <int>(1);

            queue.Enqueue(23);
            Assert.AreEqual(queue.Dequeue(), 23);
        }
Beispiel #2
0
        public void Dequeue_Branch_Test_1()
        {
            ArrayBasedQueue <int> queue = new ArrayBasedQueue <int>(10);

            Assert.That(() => queue.Dequeue(),
                        Throws.TypeOf <InvalidOperationException>()
                        .With.Message.EqualTo("There are no items in the queue."));
        }
Beispiel #3
0
        private static void Run()
        {
            int size  = 32;
            var queue = new ArrayBasedQueue <int>();

            for (int i = 1; i <= size; i++)
            {
                queue.Enqueue(i);
            }

            for (int i = 1; i <= size; i++)
            {
                int result = queue.Dequeue();
                Console.Write($"[{result}]");
            }
        }
Beispiel #4
0
        public void Clear_Branch_Test_1()
        {
            ArrayBasedQueue <int> queue = new ArrayBasedQueue <int>(10);

            queue.Enqueue(1);
            queue.Enqueue(2);

            queue.Clear();

            Assert.Multiple(() =>
            {
                Assert.IsTrue(queue.IsEmpty());
                Assert.IsFalse(queue.IsFull());
                Assert.That(() => queue.Dequeue(),
                            Throws.TypeOf <InvalidOperationException>()
                            .With.Message.EqualTo("There are no items in the queue."));
            });
        }
Beispiel #5
0
        public static void DequeueEmptyQueueThrowsInvalidOperationException()
        {
            // Arrange
            var       q         = new ArrayBasedQueue <int>(1);
            Exception?exception = null;

            // Act
            try
            {
                q.Dequeue();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // Assert
            Assert.AreEqual(expected: typeof(InvalidOperationException), actual: exception?.GetType());
        }
Beispiel #6
0
        public static void DequeueWorksCorrectly()
        {
            // Arrange
            var q = new ArrayBasedQueue <char>(3);

            q.Enqueue('A');
            q.Enqueue('B');
            q.Enqueue('C');
            var result = new StringBuilder();

            // Act
            for (int i = 0; i < 3; i++)
            {
                result.Append(q.Dequeue());
            }

            // Assert
            Assert.AreEqual(expected: "ABC", actual: result.ToString());
            Assert.IsTrue(q.IsEmpty(), "Queue is empty");
            Assert.IsFalse(q.IsFull(), "Queue is full");
        }