예제 #1
0
        public void EmptyQueueContains()
        {
            // Arrange
            var emptyQueue = new ADTQueue <int>();
            // Act
            bool result = emptyQueue.Contains(1);

            // Assert
            Assert.AreEqual(false, result);
        }
예제 #2
0
        public void QueueDequeueFail()
        {
            // Arrange
            var emptyQueue = new ADTQueue <int>();
            // Act
            int result = emptyQueue.Dequeue();

            // Assert
            Assert.Fail();
        }
예제 #3
0
        public void QueuePeekFail()
        {
            // Arrange
            var emptyQueue = new ADTQueue <int>();
            // Act
            int result = emptyQueue.Peek();

            // Assert
            Assert.Fail();
        }
예제 #4
0
        public void QueuePeekSuccess()
        {
            // Arrange
            var notEmptyQueue = new ADTQueue <int>()
                                .Enqueue(1)
                                .Enqueue(2)
                                .Enqueue(3);
            // Act
            int result = notEmptyQueue.Peek();

            // Assert
            Assert.AreEqual(1, result);
        }
예제 #5
0
        public void NotEmptyQueueNotContains()
        {
            // Arrange
            var notEmptyQueue = new ADTQueue <int>()
                                .Enqueue(1)
                                .Enqueue(2)
                                .Enqueue(3);
            // Act
            bool result = notEmptyQueue.Contains(4);

            // Assert
            Assert.AreEqual(false, result);
        }
예제 #6
0
        static void Main()
        {
            var test = new ADTQueue<string>();

            test.Enqueue("Alfa");
            test.Enqueue("Beta");
            test.Enqueue("Gama");
            test.Enqueue("Delta");

            var count = test.Count;
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine(test.Peek());
                test.Dequeue();
            }

            Console.ReadKey();
        }
예제 #7
0
    public static void Main(string[] args)
    {
        ADTQueue <int> testQueue = new ADTQueue <int>();

        Debug.Assert(testQueue.Count == 0, "The queue count is not 0!");

        Console.WriteLine("Fill the queue with integers!");
        Console.WriteLine(new string('-', 30));

        List <int> userData = FunctionsCollection.ReadIntListInRangeUptoEmptyLine();

        for (int i = 0; i < userData.Count; i++)
        {
            testQueue.Enqueue(userData[i]);
        }

        Debug.Assert(testQueue.Count == userData.Count, "The queue count is not equal to the number of values entered!");
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("The queue count is: {0}", testQueue.Count);

        Console.WriteLine(new string('-', 30));
        try
        {
            Console.WriteLine("Read first item by Peak(): {0}", testQueue.Peek());
        }
        catch (InvalidOperationException)
        {
            Console.WriteLine("The queue is empty so Peek() throws an InvalidOperationException!");
        }

        Console.WriteLine(new string('-', 30));
        Console.WriteLine("Read the queue by using Dequeue():");
        for (int i = testQueue.Count - 1; i >= 0; i--)
        {
            Console.WriteLine("{0} : {1}", i, testQueue.Dequeue());
        }

        Debug.Assert(testQueue.Count == 0, "The queue count is not 0!");
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("The queue count is: {0}", testQueue.Count);
    }