Beispiel #1
0
        public void TestRemove()
        {
            int[]       items = new[] { 0, 1, 2, 3 };
            Deque <int> deque = new Deque <int>(items);

            Assert.IsTrue(deque.Contains(0));
            Assert.IsTrue(deque.Remove(0));
            Assert.IsFalse(deque.Contains(0));
            Assert.AreEqual(1, deque.RemoveFront());
            Assert.AreEqual(3, deque.RemoveBack());

            deque.Clear();
            deque.AddRange(items);
            Assert.IsTrue(deque.Contains(2));
            deque.RemoveAt(2);
            Assert.IsFalse(deque.Contains(2));

            deque.Clear();
            deque.AddRange(items);

            foreach (var item in items)
            {
                Assert.IsTrue(deque.Contains(item));
            }

            deque.RemoveRange(1, 2);

            Assert.IsTrue(deque.Contains(0));
            Assert.IsFalse(deque.Contains(1));
            Assert.IsFalse(deque.Contains(2));
            Assert.IsTrue(deque.Contains(3));
        }
Beispiel #2
0
        public void Add_WillExpandIfNecessary()
        {
            var deque = new Deque <int>(2);

            Assert.AreEqual(2, deque.Capacity);
            deque.AddRange(new[] { 1, 2, 3, 4, 5 });
            Assert.AreEqual(8, deque.Capacity);
        }
Beispiel #3
0
        private void Traverse(IRenderingElement newElement)
        {
            var stack = new Deque <IRenderingElement>();

            stack.Push(newElement);
            while (stack.Any())
            {
                var element = stack.Poll();
                switch (element)
                {
                case Bounds e:
                    Add(e);
                    break;

                case GeneralPath e:
                    Add(e);
                    break;

                case LineElement lineElem:
                    var vec   = lineElem.SecondPoint - lineElem.FirstPoint;
                    var ortho = new WPF::Vector(-vec.Y, vec.X);
                    ortho.Normalize();
                    vec.Normalize();
                    ortho *= lineElem.Width / 2;      // stroke width
                    vec   *= lineElem.Width / 2;      // stroke rounded also makes line longer
                    Add(lineElem.FirstPoint - vec + ortho);
                    Add(lineElem.SecondPoint + vec + ortho);
                    Add(lineElem.FirstPoint - vec - ortho);
                    Add(lineElem.SecondPoint + vec - ortho);
                    break;

                case OvalElement oval:
                    Add(new Point(oval.Coord.X - oval.Radius, oval.Coord.Y));
                    Add(new Point(oval.Coord.X + oval.Radius, oval.Coord.Y));
                    Add(new Point(oval.Coord.X, oval.Coord.Y - oval.Radius));
                    Add(new Point(oval.Coord.X, oval.Coord.Y + oval.Radius));
                    break;

                case ElementGroup elementGroup:
                    stack.AddRange(elementGroup);
                    break;

                case MarkedElement e:
                    stack.Add(e.Element());
                    break;

                default:
                    // ignored from bounds calculation, we don't really
                    // care but log we skipped it
                    Trace.TraceWarning($"{element.GetType()} not included in bounds calculation");
                    break;
                }
            }
        }
Beispiel #4
0
        public void Add_CanAddACollectionOfItems()
        {
            var deque = new Deque <int>();
            var col   = new[] { 1, 2, 3, 4 };

            deque.AddRange(col);
            Assert.AreEqual(4, deque.Count);
            Assert.AreEqual(1, deque[0]);
            Assert.AreEqual(2, deque[1]);
            Assert.AreEqual(3, deque[2]);
            Assert.AreEqual(4, deque[3]);
        }
Beispiel #5
0
        public void Iterate_CanLoopWithForeach()
        {
            IQueue <int> queue = new Deque <int>();

            queue.AddRange(new[] { 1, 2, 3, 4, 5 });
            var idx = 1;

            foreach (var item in queue)
            {
                Assert.AreEqual(item, idx);
                idx++;
            }
        }
        public void DequeueRange_CanDequeueRangeFromQueue()
        {
            IQueue <int> queue = new Deque <int>(2);
            var          list  = new List <int>();

            8.Times(i => list.Add(i + 1));

            queue.AddRange(list);
            var result = queue.DequeueRange(16).ToList();

            8.Times(i => {
                Assert.AreEqual(result[i], list[i]);
            });
        }
        public void DequeueRange_CanDequeueFromQueue()
        {
            IQueue <int> queue = new Deque <int>(2);
            var          list  = new List <int>();

            8.Times(i => list.Add(i + 1));

            queue.AddRange(list);
            var result = queue.Dequeue();

            Assert.AreEqual(7, queue.Count);
            Assert.AreEqual(8, queue.Capacity);
            Assert.AreEqual(1, result);
        }
        public void DequeueRange_TakeCountIsSameAsDequeueRange()
        {
            IQueue <int> q1   = new Deque <int>(2);
            IQueue <int> q2   = new Deque <int>(2);
            var          list = new List <int>();

            8.Times(i => list.Add(i + 1));

            q1.AddRange(list);
            q2.AddRange(list);

            var r1 = q1.DequeueRange(16).ToList();
            var r2 = q2.Take(16).ToList();

            for (var idx = 0; idx < r1.Count; idx++)
            {
                Assert.AreEqual(r1[idx], r2[idx]);
            }

            Assert.AreEqual(0, q1.Count);
            Assert.AreEqual(8, q2.Count);
            Assert.AreEqual(q1.Capacity, q2.Capacity);
        }
Beispiel #9
0
        public void TestAdd()
        {
            Deque<int> deque = new Deque<int>();

            Assert.IsTrue(deque.IsEmpty);

            int item = 1;

            Assert.IsFalse(deque.Contains(item));
            deque.Add(item);

            int actualBack;
            actualBack = deque[0];

            Assert.IsTrue(deque.Contains(item));
            Assert.AreEqual(item, actualBack);

            int itemNewBack = 2;
            Assert.IsFalse(deque.Contains(itemNewBack));
            deque.AddBack(itemNewBack);

            Assert.IsTrue(deque.Contains(itemNewBack));
            actualBack = deque[1];
            Assert.AreEqual(itemNewBack, actualBack);

            actualBack = deque.RemoveBack();
            Assert.AreEqual(itemNewBack, actualBack);

            int itemNewFront = -1;
            Assert.IsFalse(deque.Contains(itemNewFront));
            deque.AddFront(itemNewFront);

            int actualFront;
            Assert.IsTrue(deque.Contains(itemNewFront));

            actualFront = deque[0];
            Assert.AreEqual(itemNewFront, actualFront);

            actualFront = deque.RemoveFront();
            Assert.AreEqual(itemNewFront, actualFront);

            int[] itemRange = new[] { 3, 4, 5, 6 };
            int offset = deque.Count;
            deque.AddRange(itemRange);

            foreach (var itm in itemRange)
            {
                Assert.AreEqual(itm, deque[offset]);
                offset++;
            }

            int[] itemBackRange = new[] { 7, 8, 9, 10 };
            offset = deque.Count;
            deque.AddBackRange(itemBackRange);
            foreach (var itm in itemBackRange)
            {
                Assert.AreEqual(itm, deque[offset]);
                offset++;
            }

            int[] itemFrontRange = new[] { 3, 4, 5, 6 };
            deque.AddFrontRange(itemFrontRange);

            for (int i = 0; i < itemFrontRange.Length; i++)
            {
                var itm = itemFrontRange[i];
                Assert.AreEqual(itm, deque[i]);
            }
        }
Beispiel #10
0
        public void TestRemove()
        {
            int[] items = new[] { 0, 1, 2, 3 };
            Deque<int> deque = new Deque<int>(items);

            Assert.IsTrue(deque.Contains(0));
            Assert.IsTrue(deque.Remove(0));
            Assert.IsFalse(deque.Contains(0));
            Assert.AreEqual(1, deque.RemoveFront());
            Assert.AreEqual(3, deque.RemoveBack());

            deque.Clear();
            deque.AddRange(items);
            Assert.IsTrue(deque.Contains(2));
            deque.RemoveAt(2);
            Assert.IsFalse(deque.Contains(2));

            deque.Clear();
            deque.AddRange(items);

            foreach (var item in items)
            {
                Assert.IsTrue(deque.Contains(item));
            }

            deque.RemoveRange(1, 2);

            Assert.IsTrue(deque.Contains(0));
            Assert.IsFalse(deque.Contains(1));
            Assert.IsFalse(deque.Contains(2));
            Assert.IsTrue(deque.Contains(3));
        }
Beispiel #11
0
        public void TestAdd()
        {
            Deque <int> deque = new Deque <int>();

            Assert.IsTrue(deque.IsEmpty);

            int item = 1;

            Assert.IsFalse(deque.Contains(item));
            deque.Add(item);

            int actualBack;

            actualBack = deque[0];

            Assert.IsTrue(deque.Contains(item));
            Assert.AreEqual(item, actualBack);

            int itemNewBack = 2;

            Assert.IsFalse(deque.Contains(itemNewBack));
            deque.AddBack(itemNewBack);

            Assert.IsTrue(deque.Contains(itemNewBack));
            actualBack = deque[1];
            Assert.AreEqual(itemNewBack, actualBack);

            actualBack = deque.RemoveBack();
            Assert.AreEqual(itemNewBack, actualBack);

            int itemNewFront = -1;

            Assert.IsFalse(deque.Contains(itemNewFront));
            deque.AddFront(itemNewFront);

            int actualFront;

            Assert.IsTrue(deque.Contains(itemNewFront));

            actualFront = deque[0];
            Assert.AreEqual(itemNewFront, actualFront);

            actualFront = deque.RemoveFront();
            Assert.AreEqual(itemNewFront, actualFront);

            int[] itemRange = new[] { 3, 4, 5, 6 };
            int   offset    = deque.Count;

            deque.AddRange(itemRange);

            foreach (var itm in itemRange)
            {
                Assert.AreEqual(itm, deque[offset]);
                offset++;
            }

            int[] itemBackRange = new[] { 7, 8, 9, 10 };
            offset = deque.Count;
            deque.AddBackRange(itemBackRange);
            foreach (var itm in itemBackRange)
            {
                Assert.AreEqual(itm, deque[offset]);
                offset++;
            }

            int[] itemFrontRange = new[] { 3, 4, 5, 6 };
            deque.AddFrontRange(itemFrontRange);

            for (int i = 0; i < itemFrontRange.Length; i++)
            {
                var itm = itemFrontRange[i];
                Assert.AreEqual(itm, deque[i]);
            }
        }