public void Peek_SecondTime_ReturnsFirstElementFromBegining()
      {
          CustomQueue<int> queue = new CustomQueue<int>( new int[]{5, 11, 6, 5, 9});
          queue.Peek();
 
          Assert.AreEqual(5, queue.Peek());
      }
Esempio n. 2
0
        public static void Run()
        {
            CustomQueue<int> queue = new CustomQueue<int>();
            for (int i = 0; i < 24; i++)
                queue.Enqueue(i + 1);

            for (int i = 0; i < 24; i++)
                queue.Dequeue();

//            queue.Dequeue();
//            queue.Dequeue();
            queue.Enqueue(7);
            queue.Enqueue(8);
//            queue.Dequeue();
//            queue.Dequeue();
            queue.Enqueue(9);
            queue.Enqueue(10);
            queue.Dequeue();

            Console.WriteLine("For:");
            for (int i = 0; i < queue.Count; i++)
                Console.WriteLine(queue[i]);

            Console.WriteLine("Peek: {0}", queue.Peek());
            Console.WriteLine("Peek: {0}", queue.Peek());
            Console.WriteLine("Peek: {0}", queue.Peek());

            Console.WriteLine("Foreach:");
            foreach (int i in queue)
                Console.WriteLine(i);
        }
        static void Main(string[] args)
        {
            CustomQueue<int> queue = new CustomQueue<int>(9);
            queue.Enqueue(4);
            queue.Enqueue(3);
            queue.Enqueue(2);
            queue.Enqueue(1);
            queue.Enqueue(0);
            queue.Enqueue(-1);

            foreach (var a in queue)
                Console.WriteLine(a);
            Console.WriteLine("---------------");

            Console.WriteLine("Peek = {0}",queue.Peek());
            Console.WriteLine("---------------");

            Console.WriteLine("Dequeue = {0}", queue.Dequeue());
            Console.WriteLine("Dequeue = {0}", queue.Dequeue());
            Console.WriteLine("Dequeue = {0}", queue.Dequeue());
            Console.WriteLine("---------------");

            foreach (var a in queue)
                Console.WriteLine(a);
        
        }
        public void Enqueue_Int_AddsToQueue()
        {
            CustomQueue<int> queue = new CustomQueue<int>();
            queue.Enqueue(5);

            Assert.AreEqual(5, queue.Peek());
        }
Esempio n. 5
0
        static void QueueUsingTwoStacks()
        {
            CustomQueue queue = new CustomQueue();
            int         n     = int.Parse(Console.ReadLine());

            while (n > 0)
            {
                string Line  = Console.ReadLine();
                int    query = int.Parse(Line.Substring(0, 1));

                if (query == 1)
                {
                    int num = int.Parse(Line.Substring(2));
                    queue.Enqueue(num);
                }

                else if (query == 2)
                {
                    queue.Dequeue();
                }
                else
                {
                    if (queue.Count > 0)
                    {
                        Console.WriteLine(queue.Peek());
                    }
                }
                n--;
            }
        }
        public void Dequeue_OneTime_DeletesFirstElementFromBegining()
        {
            CustomQueue<int> queue = new CustomQueue<int>(new int[] { 5, 11, 6, 5, 9, 5 });
            queue.Dequeue();

            Assert.AreEqual(11, queue.Peek());
        }
Esempio n. 7
0
        public void Queue_PeekInEmptyQueue_InvalidOperationException()
        {
            CustomQueue <int> queue = new CustomQueue <int>();

            queue.Enqueue(1);
            queue.Dequeue();
            Assert.Throws <InvalidOperationException>(() => queue.Peek());
        }
        public int TestPeek(int[] elements)
        {
            CustomQueue <int> queue = new CustomQueue <int>(elements);

            queue.Pop();
            queue.Push(1);
            return(queue.Peek());
        }
        static void Main(string[] args)
        {
            CustomQueue<int> CQ = new CustomQueue<int>();
            CQ.Enqueue(1);
            CQ.Enqueue(2);
            CQ.Enqueue(3);
            CQ.Enqueue(4);
            CQ.Enqueue(5);            
            Console.WriteLine(CQ.Peek());
            int first = CQ.Dequeue();
            Console.WriteLine(CQ.Peek());
            foreach (int i in CQ)
                Console.Write(i + " ");
            Console.WriteLine();
            Console.WriteLine(CQ.Peek());

        }
Esempio n. 10
0
        public void EmptyPeek_Test()
        {
            // ARRANGE
            var queue = new CustomQueue <int>();

            // ACT
            queue.Peek();
        }
Esempio n. 11
0
    private IEnumerator Work()
    {
        Working = true;

        while (workOrderQueue.Count > 0)
        {
            var workOrder = workOrderQueue.Peek();

            if (workOrder is RecruitmentWorkOrder)
            {
                var recruitmentCompleted = false;
                while (!recruitmentCompleted)
                {
                    if (populationManager.TryRecruit(workOrder as RecruitmentWorkOrder))
                    {
                        OnWorkOrderStarted?.Invoke();
                        yield return(WaitFor(workOrder.duration));

                        if (!pendingCancel)
                        {
                            Recruit(workOrder as RecruitmentWorkOrder);
                        }
                        else
                        {
                            populationManager.Cancel(workOrder as RecruitmentWorkOrder);
                        }

                        recruitmentCompleted = true;
                    }
                    else
                    {
                        recruitmentProcessStuck = true;
                        while (recruitmentProcessStuck)
                        {
                            yield return(null);
                        }
                    }
                }
            }
            else
            {
                OnWorkOrderStarted?.Invoke();
                yield return(WaitFor(workOrder.duration));
            }

            if (!pendingCancel)
            {
                workOrderQueue.Dequeue();
                OnWorkOrderQueueUpdated?.Invoke(workOrderQueue.GetReadonlyList());
            }
            else
            {
                pendingCancel = false;
            }
        }

        Working = false;
    }
Esempio n. 12
0
 public void CheckEnqueue()
 {
     CustomQueue<int> queue = new CustomQueue<int>();
     queue.EnQueue(2);
     int length = queue.Length;
     int element = queue.Peek();
     Assert.AreEqual(length, 1);
     Assert.AreEqual(2, element);
 }
Esempio n. 13
0
 public void PeekElementFromQueueTest()
 {
     CustomQueue<int> myQueue = new CustomQueue<int>();
     myQueue.Enqueue(new int[]{2, 12, 52, 82, 4, 2});
     myQueue.Dequeue();
     int actual = myQueue.Peek();
     int expected = 12;
     Assert.AreEqual(expected, actual);
 }
        public void Peek_FromThreeIntQueue_ReturnsFirstOne()
        {
            CustomQueue<int> queue = new CustomQueue<int>();
            queue.Enqueue(5);
            queue.Enqueue(6);
            queue.Enqueue(11);

            Assert.AreEqual(5, queue.Peek());
        }
        static void Main(string[] args)
        {
            WriteLine("Start Queue test");
            CustomQueue <int> queue = new CustomQueue <int>(new List <int> {
                0, 1, 2, 4, 5, -5, -8, 95
            });

            WriteLine("\nTest foreach");
            foreach (var i in queue)
            {
                Write($"{i} .. ");
            }

            queue.Enqueue(57);
            queue.Enqueue(-57);
            queue.Enqueue(0);

            WriteLine("\nTest Enqueue /57, -57, 0/");
            foreach (var i in queue)
            {
                Write($"{i} .. ");
            }

            WriteLine("\nTest Error when enumerate and modify");
            try {
                foreach (var i in queue)
                {
                    Write($"{i} .. ");
                    WriteLine($"Try to dequeue: {queue.Dequeue()}");
                }
            } catch (InvalidOperationException ex) {
                WriteLine(ex);
            }

            WriteLine("\nTest Dequeue 6 elements");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine("\nWrite after dequeue");
            foreach (var i in queue)
            {
                Write($"{i} .. ");
            }

            WriteLine("\nCheck Peek");
            WriteLine($"Peek: {queue.Peek()}");

            WriteLine("\nTest Clear");
            queue.Clear();
            WriteLine($"Count: {queue.Count}");

            ReadLine();
        }
Esempio n. 16
0
 public void PeekTestMethod()
 {
     intQueue.Enqueue(1);
     intQueue.Enqueue(2);
     intQueue.Enqueue(3);
     intQueue.Enqueue(4);
     intQueue.Enqueue(5);
     intQueue.Dequeue();
     Assert.AreEqual(intQueue.Peek(), 2);
 }
        public void CustomQueue_Peek_Test()
        {
            CustomQueue<int> queue = new CustomQueue<int>(1);
            queue.Enqueue(1);
            queue.Enqueue(2);

            var item = queue.Peek();

            Assert.AreEqual(1, item);
        }
        public void Peek_Test()
        {
            int[] array = new int[] { 0, 1, 2, 3, 4 };
            CustomQueue<int> queue = new CustomQueue<int>(array);

            int actual = queue.Peek();
            int expected = 0;

            Assert.AreEqual(expected, actual);
        }
        public void Peek_CorrectParamsSting_ReturnsFirstValue()
        {
            string[]             arr   = { "af", "re", "lo" };
            CustomQueue <string> queue = new CustomQueue <string>(arr);

            string expected = "af";

            string actual = queue.Peek();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 20
0
        public void Peek_GetFirstItemWithoutReturn_Return10()
        {
            queue = new CustomQueue <int>(new int[] { 10, 20, 30 });

            // Get first without return: 10
            var res = queue.Peek();

            Assert.Equal(10, res);

            // Get first without return: 10
            res = queue.Peek();
            Assert.Equal(10, res);

            // Get first and return: 10
            res = queue.Dequeue();
            Assert.Equal(10, res);

            // Get first and return: 20
            res = queue.Dequeue();
            Assert.Equal(20, res);
        }
Esempio n. 21
0
    static void Main()
    {
        CustomQueue<int> testQueue = new CustomQueue<int>();

        testQueue.Enqueue(1);
        testQueue.Enqueue(2);
        testQueue.Enqueue(3);

        Console.WriteLine("Queue Lenght: {0}", testQueue.Count);
        Console.WriteLine("Dequeued Item: {0}", testQueue.Dequeue());
        Console.WriteLine("Dequeued Item: {0}", testQueue.Dequeue());
        Console.WriteLine("Peeking at Item: {0}", testQueue.Peek());
    }
        static void Main(string[] args) {
            WriteLine("Start Queue test");
            CustomQueue<int> queue = new CustomQueue<int>(new List<int> {
                0, 1, 2, 4, 5, -5, -8, 95
            });
            
            WriteLine("\nTest foreach");
            foreach(var i in queue) {
                Write($"{i} .. ");
            }

            queue.Enqueue(57);
            queue.Enqueue(-57);
            queue.Enqueue(0);

            WriteLine("\nTest Enqueue /57, -57, 0/");
            foreach (var i in queue) {
                Write($"{i} .. ");
            }

            WriteLine("\nTest Error when enumerate and modify");
            try {
                foreach(var i in queue) {
                    Write($"{i} .. ");
                    WriteLine($"Try to dequeue: {queue.Dequeue()}");
                }
            } catch(InvalidOperationException ex) {
                WriteLine(ex);
            }

            WriteLine("\nTest Dequeue 6 elements");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine($"Dequeue: {queue.Dequeue()}");
            WriteLine("\nWrite after dequeue");
            foreach (var i in queue) {
                Write($"{i} .. ");
            }

            WriteLine("\nCheck Peek");
            WriteLine($"Peek: {queue.Peek()}");

            WriteLine("\nTest Clear");
            queue.Clear();
            WriteLine($"Count: {queue.Count}");

            ReadLine();
        }
Esempio n. 23
0
        public void Enqueue_ThreeStringElementsInQueueAndDequeue()
        {
            var stack = new CustomQueue <String>();

            stack.Enqueue("Natasha");
            stack.Enqueue("Skeet");
            stack.Enqueue("PashaFast");
            stack.Dequeue();


            string pashafast = "Skeet";

            Assert.AreEqual(pashafast, stack.Peek());
        }
        public void TestMethodsEnqueuDequeuPeek(int[] expectedArray, int expectedPeek)
        {
            CustomQueue<int> customQueue = new CustomQueue<int>();
            var customIter = customQueue.GetEnumerator();
            Queue<int> queue = new Queue<int>();
            customQueue.Enqueue(1);
            customQueue.Enqueue(2);
            customQueue.Enqueue(4);
            customQueue.Enqueue(8);
            customQueue.Enqueue(9);
            customQueue.Dequeue();
            Assert.AreEqual(customQueue.Peek(), expectedPeek);
            int[] array = customQueue.ToArray();
            CollectionAssert.AreEqual(expectedArray, array);

        }
Esempio n. 25
0
        public void GeneralFunctionalityBCLTypesInt()
        {
            CustomQueue <int> customQueue = new CustomQueue <int>();

            customQueue.Add(5);
            customQueue.Add(15);
            Assert.AreEqual(customQueue, new[] { 5, 15 });

            customQueue.Get();
            Assert.AreEqual(customQueue, new[] { 15 });

            Assert.AreEqual(customQueue.Peek(), 15);
            Assert.AreEqual(customQueue.Count, 1);
            Assert.IsTrue(customQueue.Contains(15));
            Assert.IsFalse(customQueue.Contains(5));
        }
        static void Main(string[] args)
        {
            /*var test = new CounterEvent();
            var timer = new EventNumber(1,test);
            var timer2 = new EventNumber(2,test);
            test.StartEvent(3);

            Console.WriteLine("\nFibonacci");
            foreach (var number in Fibonacci.GetNumbers(5))
            {
                Console.WriteLine(number);
            }

            */

            var qqq = new CustomQueue<int>();
            qqq.Enqueue(112);
            qqq.Enqueue(14);
            qqq.Enqueue(1);
            qqq.Enqueue(662);
            qqq.Enqueue(909);
            qqq.Enqueue(112);
            qqq.Enqueue(5555);

            Console.WriteLine("QueueElements:");
            foreach (var q in qqq)
            {
                Console.WriteLine(q);
            }
            Console.WriteLine("Dequeue");
            Console.WriteLine(qqq.Dequeue());
             Console.WriteLine(qqq.Dequeue());
            Console.WriteLine("QueueElements:");
            foreach (var q in qqq)
            {
                Console.WriteLine(q);
            }
            Console.WriteLine("Peek:");
            Console.WriteLine(qqq.Peek());
            Console.WriteLine("QueueElements:");
            foreach (var q in qqq)
            {
                Console.WriteLine(q);
            }
            Console.ReadKey();
        }
 public void TestQueue()
 {
     var queue = new CustomQueue<int>();
     int[] ar = {1,2,3,4,5};
     foreach (var e in ar)
     {
         queue.Enqueue(e);
     }
     Assert.AreEqual(1, queue.Peek());
     int i = 0;
     foreach(var e in queue)
     {
         Assert.AreEqual(e, ar[i++]);
     }
     for(i=0;i<ar.Length;i++)
     {
         Assert.AreEqual(queue.Dequeue(), ar[i]);
     }
 }
        static void Main(string[] args)
        {
            CustomQueue<int> q = new CustomQueue<int>(20);
            for (int i = 0; i<20; i++)
            {
                q.Enqueue(i);
            }
            for (int i = 0; i<10; i++)
                Console.WriteLine(q.Dequeue());
            for (int i = 100; i < 110; i++)
            {
                q.Enqueue(i);
            }

            Console.WriteLine("Enqueued");
            foreach (int a in q)
            {
                Console.WriteLine(a);
            }
            Console.WriteLine(q.Peek());
        }
Esempio n. 29
0
        public void GeneralFunctionalityWithArrayList()
        {
            CustomQueue <ArrayList> customQueue = new CustomQueue <ArrayList>();

            customQueue.Add(new ArrayList()
            {
                2
            });
            customQueue.Add(new ArrayList()
            {
                "Hello"
            });
            Assert.AreEqual(customQueue, new[] { new ArrayList()
                                                 {
                                                     2
                                                 }, new ArrayList()
                                                 {
                                                     "Hello"
                                                 } });

            customQueue.Get();
            Assert.AreEqual(customQueue, new[] { new ArrayList()
                                                 {
                                                     "Hello"
                                                 } });

            Assert.AreEqual(customQueue.Peek(), new ArrayList()
            {
                "Hello"
            });
            Assert.AreEqual(customQueue.Count, 1);
            Assert.IsFalse(customQueue.Contains(new ArrayList()
            {
                "Hello"
            }));
            Assert.IsFalse(customQueue.Contains(new ArrayList()
            {
                2
            }));
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            CustomQueue<int> userQueue = new CustomQueue<int>();

            Console.WriteLine("Was created. Count = "+userQueue.Count);
            userQueue.Enqueue(1);
            userQueue.Enqueue(2);
            userQueue.Enqueue(3);
            userQueue.Enqueue(4);
            userQueue.Enqueue(5);

            foreach (var item in userQueue)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("Was enqueued. Count = " + userQueue.Count);

            Console.WriteLine("\nDequeued: " + userQueue.Dequeue());      
            Console.WriteLine("Dequeued: " + userQueue.Dequeue()); 
            Console.WriteLine("\n Result:");
            foreach (var item in userQueue)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("Was dequeued. Count = " + userQueue.Count);

            Console.WriteLine(userQueue.Peek());
            Console.WriteLine("Was peeked. Count = " + userQueue.Count);

            Console.WriteLine("\nCtor with IEnumerable:");
            int[] array = new int[] { 5, 6, 7, 8, 9 };
            CustomQueue<int> userQueue2 = new CustomQueue<int>(array);
            foreach (var item in userQueue2)
            {
                Console.WriteLine(item);
            }
            Console.ReadLine();
        }
 public void Peek_FromEmptyQueue_ThrowsException()
 {
     CustomQueue<int> queue = new CustomQueue<int>();
     queue.Peek();
 }
 public void Peek_GivenArray_ReturnsFirstElementOfGivenQueue()
 {
     var queue = new CustomQueue<int>(new[] { 1, 2, 3, 4, 5 });
     var firstElement = queue.Peek();
     Assert.AreEqual(1, firstElement);
 }
Esempio n. 33
0
 public void PeekElementFromEmptyQueue_ShouldThrownException()
 {
     CustomQueue<int> myQueue = new CustomQueue<int>();
     myQueue.Peek();
 }
 public void Peek_GivenEmptyQueue_ThrownInvalidOperationException()
 {
     var queue = new CustomQueue<int>(new int[] {});
     queue.Peek();
 }
Esempio n. 35
0
 public void CheckPeek()
 {
     CustomQueue<double> queue = new CustomQueue<double>();
     queue.EnQueue(3.14);
     queue.EnQueue(6.78);
     double element = queue.Peek();
     Assert.AreEqual(3.14, element);
     Assert.AreEqual(2, queue.Length);
 }
 public void Peek_EmptyQueue_InvalidOperationException()
 {
     CustomQueue<int> queue = new CustomQueue<int>();
     queue.Peek();
 }
 public void Enqueue_GivenSix_ReturnsSixWhenDequeuePreviousElements()
 {
     var queue = new CustomQueue<int>(new[] { 1, 2, 3, 4, 5 });
     queue.Enqueue(6);
     for (int i = 0; i < 5; i++)
     {
         queue.Dequeue();
     }
     var lastElement = queue.Peek();
     Assert.AreEqual(6, lastElement);
 }