Example #1
0
        public void ClearTest()
        {
            //clear an epty queue
            testQueue.Clear();
            Assert.AreEqual(0, testQueue.Size());

            //clear a queue with 2 items in it
            testQueue.Enqueue(item1);
            testQueue.Enqueue(item2);
            Assert.AreEqual(3, testQueue.Size());
            testQueue.Clear();
            Assert.AreEqual(0, testQueue.Size());
        }
        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();
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            MyQueue<int> queue = new MyQueue<int>();

            queue.Enqueue(5);
            queue.Enqueue(15);
            queue.Enqueue(-9999);
            queue.Enqueue(11);
            queue.Enqueue(135);

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

            Console.WriteLine(queue.ToString());
            Console.WriteLine();

            foreach (var elem in queue)
            {
                Console.WriteLine(elem);
            }
            Console.WriteLine();

            queue.Clear();

            Console.WriteLine(queue.Count);
            Console.WriteLine(queue.Dequeue());
        }
Example #4
0
        public void ClearTest()
        {
            object objectItem = new object();

            intQueue.Enqueue(5);
            stringQueue.Enqueue("test");
            objectQueue.Enqueue(objectItem);

            intQueue.Clear();
            stringQueue.Clear();
            objectQueue.Clear();

            Assert.IsTrue(intQueue.IsEmpty);
            Assert.IsTrue(stringQueue.IsEmpty);
            Assert.IsTrue(objectQueue.IsEmpty);
        }
        public void MyQueue_MultiThreaded_Support()
        {
            IQueue <int> myQueue = new MyQueue <int>();

            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 10000; i++)
            {
                //Thread t = new Thread(() =>
                //{
                ////////////
                //});
                //t.IsBackground = true;
                //t.Start();
                // thread pool

                tasks.Add(Task.Run(() =>
                {
                    myQueue.Enqueue(5);
                    myQueue.Dequeue();
                    myQueue.Enqueue(7);
                    myQueue.Clear();
                }));
            }

            Task.WaitAll(tasks.ToArray());
        }
Example #6
0
        public void QueueTest()
        {
            var q = new MyQueue <int>(1, 3, 5);

            CollectionAssert.AreEqual(new int[] { 1, 3, 5 }, q);

            q.Enqueue(7);
            CollectionAssert.AreEqual(new int[] { 1, 3, 5, 7 }, q);

            q.Dequeue();
            CollectionAssert.AreEqual(new int[] { 3, 5, 7 }, q);

            Assert.AreEqual(3, q.Count);

            q.Clear();
            Assert.AreEqual(0, q.Count);
            CollectionAssert.AreEqual(new int[] { }, q);

            for (int i = 0; i < 10; i++)
            {
                q.Enqueue(1);
            }

            CollectionAssert.AreEqual(new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, q);
        }
Example #7
0
        public int ClearElememtTest(int[] arr)
        {
            MyQueue <int> queue = new MyQueue <int>(arr);

            queue.Clear();
            return(queue.Count);
        }
Example #8
0
        public void MyQueue_IsEmpty()
        {
            MyQueue myQueue = ArrangeMyQueue();

            myQueue.Clear();

            Assert.Empty(myQueue);
        }
        public void MyQueue_Clear()
        {
            IQueue <int> myQueue = new MyQueue <int>();

            myQueue.Enqueue(5);
            myQueue.Enqueue(7);
            myQueue.Clear();

            Assert.AreEqual(myQueue.Count, 0);
        }
Example #10
0
        public void Clear_ClearQueue_QueueIsEmpty()
        {
            var queue = new MyQueue <int>();

            queue.Enqueue(3);
            queue.Enqueue(-2);

            queue.Clear();

            CollectionAssert.IsEmpty(queue);
        }
 internal void Close()
 {
     // Reset only vars that are not always set
     Hit = new Hit();
     if (AmmoSound)
     {
         TravelEmitter.StopSound(true);
         AmmoSound = false;
     }
     HitVelocity        = Vector3D.Zero;
     TracerBack         = Vector3D.Zero;
     TracerFront        = Vector3D.Zero;
     ClosestPointOnLine = Vector3D.Zero;
     Color             = Vector4.Zero;
     OnScreen          = Screen.None;
     Tracer            = TracerState.Off;
     Trail             = TrailState.Off;
     LifeTime          = 0;
     TracerSteps       = 0;
     TracerStep        = 0;
     DistanceToLine    = 0;
     TracerWidth       = 0;
     TrailWidth        = 0;
     TrailScaler       = 0;
     MaxTrajectory     = 0;
     ShotFade          = 0;
     ParentId          = ulong.MaxValue;
     Dirty             = false;
     AmmoSound         = false;
     HitSoundActive    = false;
     StartSoundActived = false;
     IsShrapnel        = false;
     HasTravelSound    = false;
     HitParticle       = ParticleState.None;
     Triggered         = false;
     Cloaked           = false;
     Active            = false;
     TrailActivated    = false;
     ShrinkInited      = false;
     Hitting           = false;
     Back            = false;
     LastStep        = false;
     DetonateFakeExp = false;
     TracerShrinks.Clear();
     GlowSteps.Clear();
     Offsets.Clear();
     //
     FiringWeapon  = null;
     PrimeEntity   = null;
     TriggerEntity = null;
     Ai            = null;
     AmmoDef       = null;
     System        = null;
 }
Example #12
0
        public void ClearTest()
        {
            MyQueue<int> actualInts = new MyQueue<int>();
            for (int i = 1; i <= 5; i++)
            {
                actualInts.Enqueue(i);
            }

            actualInts.Clear();

            Assert.AreEqual(0, actualInts.Count);
        }
Example #13
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());
        }
Example #14
0
        public void ClearElemTest()
        {
            //Arange
            MyQueue <int> queue = new MyQueue <int>(new[] { 1, 2, 3, 4, 5, 6, 7 });

            //Act
            queue.Clear();
            int count = queue.Count;

            //Assert
            Assert.AreEqual(0, count);
        }
        public void Clears_Queue()
        {
            var queue = new MyQueue <int> {
                1, 2, 3, 4, 5
            };
            int expected = 0;

            queue.Clear();
            int actual = queue.Count;

            Assert.AreEqual(expected, actual);
        }
Example #16
0
        public void ClearTest()
        {
            MyQueue <int> actualInts = new MyQueue <int>();

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

            actualInts.Clear();

            Assert.AreEqual(0, actualInts.Count);
        }
Example #17
0
        public static void Remove_All_Element_From_UserQueue_Return_0()
        {
            //arrange
            myCollection.Enqueue("First");
            myCollection.Enqueue("Second");
            myCollection.Enqueue("Third");

            //act
            myCollection.Clear();

            //assert
            Assert.AreEqual(0, myCollection.Count);
        }
Example #18
0
        private void button3_Click(object sender, EventArgs e)
        {
            queue.Clear();
            textBox2.Lines = queue.Printer();
            Random rand = new Random();

            for (int i = 0; i < 10; i++)
            {
                int k = rand.Next(-100, 101);
                queue.Push(k);
                textBox2.Lines = queue.Printer();
            }
        }
Example #19
0
        public void ClearTest(List <int> source)
        {
            var queue = new MyQueue <int>();

            foreach (var item in source)
            {
                queue.Enqueue(item);
            }

            queue.Clear();
            var result = queue.ToList().Count;

            Assert.That(result, Is.EqualTo(0));
        }
Example #20
0
        private static void MyQueueFunctionality()
        {
            var queue = new MyQueue <int>();

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

            Console.WriteLine($"Peek result: {queue.Peek()}");
            Console.WriteLine($"Dequeue result: {queue.Dequeue()}");

            Console.WriteLine("Iteration result:");
            foreach (var item in queue)
            {
                Console.WriteLine(item);
            }

            queue.Clear();
            Console.WriteLine($"Queue was cleared and it's size: {queue.Count}");
        }
        public void TestMethod2()
        {
            MyQueue <Computer> computers = new MyQueue <Computer>();

            computers.Enqueue(new Computer(10234, "HP-Pavilion"));
            computers.Enqueue(new Computer(0, "Test"));
            computers.Enqueue(new Computer(228, "ASUS"));

            if (!computers.Contains(new Computer(0, "Test")))
            {
                throw new Exception();
            }
            if (!computers.Peek().Equals(new Computer(10234, "HP-Pavilion")))
            {
                throw new Exception();
            }
            computers.Clear();
            computers.Enqueue(new Computer(228, "ASUS"));
            if (!computers.Contains(new Computer(228, "ASUS")))
            {
                throw new Exception();
            }
        }
Example #22
0
 public void Clear()
 {
     m_queue.Clear();
     m_lastTimeStamp = MyTimeSpan.Zero;
 }
Example #23
0
        static void Main(string[] args)
        {
            MyQueue <int>    numbers = new MyQueue <int>();
            MyQueue <string> strings = new MyQueue <string>(8);

            char[]         charArray = { 'H', 'i', ',', 'g', 'u', 'y', 's', '!' };
            MyQueue <char> chars     = new MyQueue <char>(charArray);

            Console.WriteLine("String count: ");
            Console.WriteLine(strings.Count);
            strings.Enqueue("one");
            strings.Enqueue("two");
            strings.Enqueue("three");
            strings.Enqueue("fore");
            strings.Enqueue("five");
            strings.Enqueue("six");
            strings.Enqueue("seven");
            strings.Enqueue("eight");
            Console.WriteLine("String queue after adding 8 string: ");
            foreach (var elem in strings)
            {
                Console.Write(elem + " ");
            }
            Console.WriteLine("\nIs 'three' contain in string queue:\n" + strings.Contains("three"));
            Console.WriteLine(strings.Peek());
            strings.Enqueue("nine");
            Console.WriteLine("Queue + 'nine':");
            foreach (var elem in strings)
            {
                Console.Write(elem + " ");
            }
            Console.WriteLine("Remove and return firs element:");
            Console.WriteLine("\n" + strings.Dequeue() + "\n");

            foreach (var elem in strings)
            {
                Console.Write(elem + " ");
            }
            Console.WriteLine("Count of queue:\n" + strings.Count);

            strings.Enqueue("ten");
            strings.Enqueue("eleven");
            Console.WriteLine("Queue + 'ten' and 'eleven':");
            foreach (var elem in strings)
            {
                Console.Write(elem + " ");
            }
            Console.WriteLine("\nChar array: ");
            foreach (var elem in chars)
            {
                Console.Write(elem);
            }

            chars.Clear();
            Console.WriteLine("Char count after Clearing: \n" + chars.Count);
            numbers.Enqueue(1);
            numbers.Enqueue(2);
            numbers.Enqueue(3);
            numbers.Enqueue(4);
            numbers.Enqueue(5);
            numbers.Enqueue(6);
            numbers.Enqueue(7);
            numbers.Enqueue(8);
            numbers.Enqueue(9);
            numbers.Enqueue(10);
            numbers.Enqueue(11);
            Console.WriteLine("Adding 11 elements in queue numbers: \n");
            foreach (var elem in numbers)
            {
                Console.Write(elem);
            }
            //Array array1 = numbers.ToArray();
            //Array array2 = strings.ToArray();
            //Console.WriteLine("\n" + array1.GetType());
            //Console.WriteLine("\n" + array2.GetType());
            Console.ReadKey();
        }
Example #24
0
        static void Main(string[] args)
        {
            MyQueue <Car> myCar = new MyQueue <Car>();

            myCar.ClearEvent   += Show_FromCar_Clear;
            myCar.DequeueEvent += Show_FromCar;
            myCar.EnqueueEvent += Show_FromCar;

            Console.WriteLine(new string('-', 50));

            myCar.Enqueue(new Car("Tesla X", 3000000));
            myCar.Enqueue(new Car("Tesla Model 3", 2500000));
            myCar.Enqueue(new Car("BMW", 3000000));
            myCar.Enqueue(new Car("Roadster", 10000000));



            Console.Write("--foreach");
            Console.WriteLine(new string('-', 50));

            foreach (var item in myCar)
            {
                Console.WriteLine(item.Name + "  " + item.Price);
            }

            Console.Write("--Peek");
            Console.WriteLine(new string('-', 50));

            Console.WriteLine(myCar.Peek().Name);

            Console.Write("--Dequeue");
            Console.WriteLine(new string('-', 50));

            Console.WriteLine(myCar.Dequeue().Name);
            Console.WriteLine(myCar.Dequeue().Name);

            Console.Write("--Clear");
            Console.WriteLine(new string('-', 50));

            myCar.Clear();

            Console.WriteLine(new string('-', 50));

            #region MyQueue<int> Проверка на совместимость с int
            MyQueue <int> my = new MyQueue <int>();

            my.ClearEvent   += Show_Message;
            my.DequeueEvent += Show_Message;
            my.EnqueueEvent += Show_Message;

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

            int a = my.Dequeue();
            Console.WriteLine(a);

            int a1 = my.Dequeue();
            Console.WriteLine(a1);

            Console.WriteLine(new string('-', 100));

            foreach (var item in my)
            {
                Console.WriteLine(item);
            }

            my.Enqueue(1);
            my.Enqueue(2);
            my.Clear();

            foreach (var item in my)
            {
                Console.WriteLine(item);
            }


            my.ClearEvent   -= Show_Message;
            my.DequeueEvent -= Show_Message;
            my.EnqueueEvent -= Show_Message;
        }
Example #25
0
        static void Main(string[] args)
        {
            MyQueue <int> newQueue = new MyQueue <int>();

            newQueue.DoClear   += (obj, arg) => Console.WriteLine("Queue cleared.");
            newQueue.DoDequeue += (obj, arg) => Console.WriteLine("Dequeue elem : {0}", arg.data);
            newQueue.DoEnqueue += (obj, arg) => Console.WriteLine("Enqueue elem : {0}", arg.data);

            newQueue.Enqueue(1);
            newQueue.Enqueue(2);
            newQueue.Enqueue(3);
            newQueue.Enqueue(4);

            Console.WriteLine(newQueue.Contains(2));
            Console.WriteLine(newQueue.Contains(10));

            Console.WriteLine(newQueue.ToString());

            newQueue.Dequeue();
            Console.WriteLine(newQueue.ToString());

            int[] newArray = newQueue.ToArray();

            Console.WriteLine("\nQueue:");
            foreach (int elem in newQueue)
            {
                Console.Write(elem + " ");
            }

            Console.WriteLine();
            Console.WriteLine("\nArray:");
            foreach (int elem in newArray)
            {
                Console.Write(elem + " ");
            }
            Console.WriteLine();

            try
            {
                newQueue.CopyTo(null, 0);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }

            try
            {
                int[] newArray1 = new int[1];
                newQueue.CopyTo(newArray1, -1);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }

            try
            {
                int[] newArray1 = new int[1];
                newQueue.CopyTo(newArray1, 0);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }

            newQueue.Clear();

            try
            {
                newQueue.Dequeue();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Example #26
0
        static void Main(string[] args)
        {
            string    test1 = "The implementation done with integers";
            string    test2 = "the implementation done with characters";
            const int ONE   = 1;
            const int TWO   = 2;
            const int THREE = 3;
            const int FOUR  = 4;
            const int FIVE  = 5;

            const char SONE   = '1';
            const char STWO   = '2';
            const char STHREE = '3';
            const char SFOUR  = '4';
            const char SFIVE  = '5';



            int size   = 0;
            int choice = 0;

            Queue <int>   q   = new Queue <int>();
            MyQueue <int> mq  = new MyQueue <int>(ref q);
            List <int>    lst = new List <int>();

            Queue <char>   s    = new Queue <char>();
            MyQueue <char> sq   = new MyQueue <char>(ref s);
            List <char>    slst = new List <char>();


            mq.Add(ONE);
            mq.Add(TWO);
            lst.Add(THREE);
            mq.ChangeImpl(ref lst);
            mq.Add(FOUR);
            mq.Add(FIVE);

            Console.WriteLine("{0}", test1);

            size = mq.size();

            for (int i = 0; i < size; i++)
            {
                Console.Write("{0}", mq.Get());
                mq.Remove();
            }

            mq.Clear();
            Console.WriteLine();
            Console.WriteLine("{0}", test2);

            sq.Add(SONE);
            sq.Add(STWO);
            slst.Add(STHREE);
            sq.ChangeImpl(ref slst);
            sq.Add(SFOUR);
            sq.Add(SFIVE);

            size = sq.size();

            for (int i = 0; i < size; i++)
            {
                Console.Write("{0}", sq.Get());
                sq.Remove();
            }

            sq.Clear();

            Console.WriteLine();
            Console.ReadLine();
        }   // end main
Example #27
0
        static void Main(string[] args)
        {
            MyLinkedList <int>    myLLInt       = new MyLinkedList <int>();
            MyLinkedList <Person> myLLPerson    = new MyLinkedList <Person>();
            MyStack <Person>      myStackPerson = new MyStack <Person>();
            Person vasya = new Person(12345, 32, "Vasya", "Netanya");
            Person moshe = new Person(54321, 29, "Moshe", "Lod");
            Person helen = new Person(32323, 43, "Helen", "Rehovot");
            Person shir  = new Person(67895, 16, "Shir", "Netanya");

            Person[] arrayPersons = new Person[4] {
                vasya, moshe, helen, shir
            };
            Console.WriteLine();
            Console.WriteLine("----------------------MyLinkedList<int> verification -----------------------");
            Console.WriteLine("----------- AddTail, AddHead, AddAfter, AddBefore verifications-----------");
            myLLInt.AddTail(25);
            myLLInt.AddHead(20);
            myLLInt.AddHead(15);
            myLLInt.AddAfter(myLLInt.Tail, 30);
            myLLInt.AddAfter(myLLInt.Tail.Prev, 27);
            myLLInt.AddBefore(myLLInt.Head, 10);
            myLLInt.AddAfter(myLLInt.Head.Next, 17);

            Console.WriteLine(myLLInt.ToString());
            Console.WriteLine();
            Console.WriteLine("---------------Contains, Find verifications -------------");
            Node <int> node = myLLInt.Head;

            for (int i = 0; i < myLLInt.Count; i++)
            {
                Console.WriteLine("Contains " + node.Data + " verification: " + myLLInt.Contains(node.Data));
                Console.WriteLine("Find " + node.Data + " verification: " + myLLInt.Find(node.Data).Equals(node));
                node = node.Next;
            }
            Console.WriteLine();
            Console.WriteLine("----------------- Remove verification ---------------------");
            myLLInt.RemoveHead();
            myLLInt.RemoveTail();
            myLLInt.Remove(myLLInt.Head.Next);
            myLLInt.Remove(myLLInt.Tail.Prev);
            Console.WriteLine(myLLInt);
            Console.WriteLine();
            Console.WriteLine("----------------- CopyTo verification --------------------");
            int[] arr = new int[7];
            myLLInt.CopyTo(arr, 2);
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(arr[i]);
            }
            Console.WriteLine();
            Console.WriteLine("---------------------foreach--LinkedList<Person>-----------------");

            myLLPerson.AddHead(vasya);
            myLLPerson.AddTail(moshe);
            myLLPerson.AddTail(helen);

            foreach (Person prs in myLLPerson)
            {
                Console.WriteLine(prs);
            }
            Console.WriteLine();
            Console.WriteLine("---------------------foreach--LinkedList<int>-----------------");
            foreach (int num in myLLInt)
            {
                Console.WriteLine(num);
            }
            Console.WriteLine();
            Console.WriteLine("--------------------- Stack Verification<Person>----------------");

            myStackPerson = fillMyStack(arrayPersons, myStackPerson);
            Console.WriteLine();
            Console.WriteLine("----------------------Peek() Pop() Verification-----------------");

            Console.WriteLine();
            int iterations = myStackPerson.Count;

            for (int i = 0; i < iterations; i++)
            {
                Console.WriteLine("Person: " + myStackPerson.Peek() + " : "
                                  + myStackPerson.Peek().Equals(myStackPerson.Pop()));
            }
            Console.WriteLine();
            Console.WriteLine("------------------------Capacity, Constructor with IEnumerable, foreach-----------------");
            myStackPerson = new MyStack <Person>(arrayPersons);
            myStackPerson = fillMyStack(arrayPersons, myStackPerson);
            myStackPerson = fillMyStack(arrayPersons, myStackPerson);

            Console.WriteLine("Count: " + myStackPerson.Count);
            foreach (Person person in myStackPerson)
            {
                Console.WriteLine(person);
            }

            Console.WriteLine();
            Console.WriteLine("------------------------Clear()-----------------------------");
            myStackPerson.Clear();
            foreach (Person person in myStackPerson)
            {
                Console.WriteLine(person);
            }
            myStackPerson.Push(vasya);
            myStackPerson.Push(moshe);
            foreach (Person person in myStackPerson)
            {
                Console.WriteLine(person);
            }



            /*Console.Writeln("----------------TrimExcees verification--------------");
             * Console.WriteLine("Capacity: " + myStackPerson.Capacity);
             * myStackPerson.TrimExcees();
             * Console.WriteLine("Capacity: " + myStackPerson.Capacity);*/
            //Console.WriteLine(myStackPerson.Peek());

            Console.WriteLine("----------------------Queue: Constructors verification-----------------------------------------------");
            Console.WriteLine();

            MyQueue <Person> myQ = new MyQueue <Person>(arrayPersons);

            foreach (Person prs in myQ)
            {
                Console.WriteLine(prs);
            }
            Console.WriteLine("MyQ - Count: " + myQ.Count + " Capacity: " + myQ.Capacity);
            MyQueue <Person> myQ2 = new MyQueue <Person>(3);
            MyQueue <int>    myQ3 = new MyQueue <int>();

            Console.WriteLine("MyQ2 - Count: " + myQ2.Count + " Capacity: " + myQ2.Capacity);
            Console.WriteLine("MyQ3 - Count: " + myQ3.Count + " Capacity: " + myQ3.Capacity);

            Console.WriteLine();
            Console.WriteLine("----------------------Queue: Enqueue, dequeue, peek, increasing capacity, treemExcees verification----------");
            Console.WriteLine();

            Console.WriteLine("---------MyQ2--------");
            Console.WriteLine("MyQ2 - Count: " + myQ2.Count + " Capacity: " + myQ2.Capacity);
            foreach (Person prs in arrayPersons)
            {
                myQ2.Enqueue(prs);
            }
            foreach (Person prs in myQ2)
            {
                Console.WriteLine(prs);
            }
            Console.WriteLine("MyQ2 - Count: " + myQ2.Count + " Capacity: " + myQ2.Capacity);
            Console.WriteLine("---------MyQ--------");
            Console.WriteLine("MyQ - Count: " + myQ.Count + " Capacity: " + myQ.Capacity);
            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine("Iteration#" + i);
                Console.WriteLine("Peek/Enqueue/Dequeue: " + myQ.Peek());
                myQ.Enqueue(myQ.Dequeue());
                foreach (Person prs in myQ)
                {
                    Console.WriteLine(prs);
                }
                Console.WriteLine("MyQ - Count: " + myQ.Count + " Capacity: " + myQ.Capacity);
                Console.WriteLine();
            }
            Console.WriteLine("Vasya was added, capacity has to be changed");
            myQ.Enqueue(vasya);
            Console.WriteLine("MyQ - Count: " + myQ.Count + " Capacity: " + myQ.Capacity);
            myQ.TrimExcees();
            Console.WriteLine("TreemExcees -> MyQ - Count: " + myQ.Count + " Capacity: " + myQ.Capacity);
            Console.WriteLine();
            Console.WriteLine("----------------------Queue: Clear verification----------");
            Console.WriteLine();
            Console.WriteLine("MyQ - Count: " + myQ.Count + " Capacity: " + myQ.Capacity);
            foreach (Person prs in myQ)
            {
                Console.WriteLine(prs);
            }
            myQ.Clear();
            Console.WriteLine("MyQ - Count: " + myQ.Count + " Capacity: " + myQ.Capacity);
            foreach (Person prs in myQ)
            {
                Console.WriteLine(prs);
            }


            Console.ReadKey();
        }
Example #28
0
 public void Clear()
 {
     using (lock_Queue.AcquireExclusiveUsing())
         Queue.Clear();
 }
Example #29
0
        /// <summary>
        /// Starts checking path against the geometry of the closest planet.
        /// </summary>
        /// <param name="displacement">Destination - current postion</param>
        private void Start(ref Vector3 displacement)
        {
            using (m_lock.AcquireExclusiveUsing())
            {
                if ((CurrentState & State.Running) != 0)
                {
                    return;
                }
                CurrentState |= State.Running;

                m_displacement = displacement;

                m_cells.Clear();

                Vector3D gridCentre = m_grid.GetCentre();
                double   distSq;
                gravcomp = MyPlanetExtensions.GetClosestPlanet(gridCentre, out distSq);

                if (gravcomp == null)
                {
                    //m_logger.debugLog("No planets found", "Start()", Logger.severity.TRACE);
                    CurrentState = State.Clear;
                    return;
                }

                if (distSq > gravcomp.MaximumRadius * gravcomp.MaximumRadius)
                {
                    //m_logger.debugLog("Outside maximum radius of closest planet", "Start()", Logger.severity.TRACE);

                    // gravity test
                    // TODO: it might be worthwhile to perform gravity test against multiple planets
                    Path.From = gridCentre;
                    Path.To   = gridCentre + displacement;

                    Vector3D closestPoint = Path.ClosestPoint(gravcomp.WorldMatrix.Translation);
                    if (closestPoint != Path.From && closestPoint != Path.To)
                    {
                        //float gravityAtClose = ClosestPlanet.GetGravityMultiplier(closestPoint) - MinGravityAvoid;
                        float gravityAtClose = gravComp.GetGravityMultiplier(closestPoint) - MinGravityAvoid;
                        //if (gravityAtClose > 0f && gravityAtClose > ClosestPlanet.GetGravityMultiplier(Path.From) && gravityAtClose > ClosestPlanet.GetGravityMultiplier(Path.To))
                        if (gravityAtClose > 0f && gravityAtClose > gravComp.GetGravityMultiplier(Path.From) && gravityAtClose > gravComp.GetGravityMultiplier(Path.To))
                        {
                            ObstructionPoint = closestPoint;
                            CurrentState     = State.BlockedGravity;
                            return;
                        }
                    }

                    CurrentState = State.Clear;
                    return;
                }

                Vector3 direction;
                Vector3.Normalize(ref displacement, out direction);
                direction = Vector3.Transform(direction, m_grid.WorldMatrixNormalizedInv.GetOrientation());

                GridCellCache.GetCellCache(m_grid).ForEach(cell => {
                    Vector3I rejected;
                    Vector3.Reject(cell, direction).ApplyOperation(x => (int)Math.Round(x), out rejected);

                    if (m_cellsUnique.Add(rejected))
                    {
                        m_cells.Enqueue(rejected);
                    }
                });

                m_cellsUnique.Clear();

                DoTests.Enqueue(TestPath);
            }
        }