public void TestMethod1()
        {
            MyQueue <int> intQueue = new MyQueue <int>();

            for (int i = 1; i <= 5; i++)
            {
                intQueue.Enqueue(i);
            }

            if (intQueue.Peek() != 1)
            {
                throw new Exception();
            }
            intQueue.Dequeue();
            if (intQueue.Peek() != 2)
            {
                throw new Exception();
            }
            if (intQueue.Count() != 4)
            {
                throw new Exception();
            }
            intQueue.Clear();
            if (intQueue.Count() != 0)
            {
                throw new Exception();
            }
            if (intQueue.Contains(1))
            {
                throw new Exception();
            }
        }
Пример #2
0
        private async void ThreadStack(Panel pnlCliente, PictureBox picProduct, Label lblTotal, Label lblRestante, int index, Label lblPower, ProgressBar progress)
        {
            try
            {
                while (true)   // metodo que faz o controle visual do que ocorre no mercado
                {
                    Random rand = new Random((int)DateTime.Now.Ticks & 0x0000FFFF);

                    int idleTime = rand.Next(1, 10000);

                    await Task.Delay(idleTime);                              //atrasa a execução da tarefa

                    MyQueue <Customer> customers = new MyQueue <Customer>(); // fila de clientes para cada caixa

                    for (int i = 0; i < rand.Next(2, 4); i++)
                    {
                        customers.Enqueue(new Customer());
                    }

                    int proFila = progress.Value + customers.Count() - 1;
                    SetControlPropertyValue(progress, "Value", proFila);

                    while (customers.Count() != 1)
                    {
                        runningTaskThread = Thread.CurrentThread;
                        Customer customer = customers.Peek();

                        SetControlPropertyValue(pnlCliente, "BackgroundImage", customer.CustomerPic);
                        SetControlPropertyValue(picProduct, "Image", customer.ProductsPic);
                        SetControlPropertyValue(lblTotal, "Text", "Total: " + customer.Purchase.Count.ToString());
                        SetControlPropertyValue(lblRestante, "Text", "Restantes: " + customer.Purchase.Count.ToString());
                        SetControlPropertyValue(lblPower, "ForeColor", Color.Lime);

                        for (int i = customer.Purchase.Count - 1; i >= 0; i--)
                        {
                            await Task.Delay(customer.Purchase[i].ProductTime);

                            customer.Purchase.RemoveAt(i);
                            SetControlPropertyValue(lblRestante, "Text", "Restantes: " + i.ToString());
                        }

                        SetControlPropertyValue(picProduct, "Image", customer.PaymentPic);
                        await Task.Delay(customer.PaymentTime);

                        SetControlPropertyValue(picProduct, "Image", null);
                        SetControlPropertyValue(pnlCliente, "BackgroundImage", null);
                        SetControlPropertyValue(lblTotal, "Text", "Total: ");
                        SetControlPropertyValue(lblRestante, "Text", "Restantes: ");
                        customers.Dequeue();
                        proFila = progressBarFila.Value - 1;
                        SetControlPropertyValue(progress, "Value", proFila);

                        Application.DoEvents();
                    }
                }
            }
            catch { return; }
        }
Пример #3
0
        public void TestMethodDeQueue()
        {
            MyQueue q = new MyQueue(5);

            q.Enqueue("a");
            q.Enqueue("b");
            q.Enqueue("c");
            q.Enqueue("d");
            q.Enqueue("e");
            Assert.AreEqual("a", q.Dequeue());
            Assert.AreEqual(4, q.Count());
            Assert.AreEqual("b", q.Dequeue());
            Assert.AreEqual(3, q.Count());
        }
Пример #4
0
        public void TestPeek()
        {
            //TestPush 3 items, checked Count
            MyQueue Q = new MyQueue(3);

            Q.Enqueue(1);
            Q.Enqueue(2);
            Q.Enqueue(3);
            Assert.AreEqual(3, Q.Peek());
            Assert.AreEqual(3, Q.Count());
        }
Пример #5
0
        public void TestMethodClear()
        {
            MyQueue q = new MyQueue(5);

            q.Enqueue("a");
            q.Enqueue("b");
            q.Enqueue("c");
            q.Enqueue("d");
            q.Enqueue("e");
            q.Clear();
            Assert.AreEqual(0, q.Count());
        }
Пример #6
0
        public void TestMethodPeek()
        {
            MyQueue q = new MyQueue(5);

            q.Enqueue("a");
            q.Enqueue("b");
            q.Enqueue("c");
            q.Enqueue("d");
            q.Enqueue("e");
            Assert.AreEqual("a", q.Peek());
            Assert.AreEqual(5, q.Count());
        }
Пример #7
0
        public void TestQueue()
        {
            Queue <int>   stdQueue = new Queue <int>();           // standard queue implemented by .NET
            MyQueue <int> ourQueue = new MyQueue <int>();         // our manually implemented queue

            // Test generates 100 random integers and adds to both queues
            Random r = new Random();

            for (int i = 0; i < 100; i++)
            {
                int randVal = r.Next();
                stdQueue.Enqueue(randVal);
                ourQueue.Enqueue(randVal);
            }

            // Test reading back half the added integers
            for (int i = 0; i < 50; i++)
            {
                Assert.AreEqual(stdQueue.Dequeue(), ourQueue.Dequeue());
                Assert.AreEqual(stdQueue.Count, ourQueue.Count());
            }

            // Test adding 50 more random integers
            for (int i = 0; i < 50; i++)
            {
                int randVal = r.Next();
                stdQueue.Enqueue(randVal);
                ourQueue.Enqueue(randVal);
            }

            // Test reading back all the remaining values
            for (int i = 0; i < 100; i++)
            {
                Assert.AreEqual(stdQueue.Dequeue(), ourQueue.Dequeue());
                Assert.AreEqual(stdQueue.Count, ourQueue.Count());
            }

            // Test queue is empty now
            Assert.AreEqual(true, ourQueue.IsEmpty());
        }
Пример #8
0
        public void TestQueue()
        {
            MyQueue q = new MyQueue(5);

            q.Enqueue("a");
            q.Enqueue("b");
            q.Enqueue("c");
            q.Enqueue("d");
            q.Enqueue("e");
            Assert.IsNotNull(q);
            Assert.IsInstanceOfType(q, typeof(MyQueue));
            Assert.AreEqual(5, q.Count());
        }
Пример #9
0
        static void Queue()
        {
            System.Console.WriteLine("\n=====   Queue   =====\n");

            //IMyQueue<int> queue = new MyArrayQueue<int>();
            IMyQueue <int> queue = new MyQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            Console.WriteLine(queue.ToString());

            Console.WriteLine(queue.Contains(10));

            Console.WriteLine(queue.Count());

            queue.Dequeue();

            Console.WriteLine(queue.Count());
        }