Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToRemovePeekedEntries()
        public virtual void ShouldBeAbleToRemovePeekedEntries()
        {
            BoundedPriorityQueue <int> queue = new BoundedPriorityQueue <int>(_baseConfig, int?.longValue, _noPriority);

            assertEquals(OK, queue.Offer(1));
            assertEquals(OK, queue.Offer(2));
            assertEquals(OK, queue.Offer(3));
            assertEquals(3, queue.Count());
            assertEquals(6, queue.Bytes());

            assertTrue(queue.Peek().Present);
            assertTrue(queue.Peek().get().remove());
            assertEquals(2, queue.Count());
            assertEquals(5, queue.Bytes());

            assertTrue(queue.Peek().Present);
            assertTrue(queue.Peek().get().remove());
            assertEquals(1, queue.Count());
            assertEquals(3, queue.Bytes());

            assertTrue(queue.Peek().Present);
            assertTrue(queue.Peek().get().remove());
            assertEquals(0, queue.Count());
            assertEquals(0, queue.Bytes());

            assertFalse(queue.Peek().Present);
            try
            {
                queue.Peek().get().remove();
                fail();
            }
            catch (NoSuchElementException)
            {
            }
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveStablePriority()
        public virtual void ShouldHaveStablePriority()
        {
            int count      = 100;
            int priorities = 3;

            Config config = new Config(0, count, 0);
            BoundedPriorityQueue <Element> queue = new BoundedPriorityQueue <Element>(config, i => 0L, comparingInt(p => p.priority));

            IList <Element> insertionOrder = new List <Element>(count);

            for (int i = 0; i < count; i++)
            {
                insertionOrder.Add(new Element(this, _tlr.Next(priorities)));
            }

            Collections.shuffle(insertionOrder, _tlr);
            insertionOrder.ForEach(queue.offer);

            for (int p = 0; p < priorities; p++)
            {
                List <Element> filteredInsertionOrder = new List <Element>();
                foreach (Element element in insertionOrder)
                {
                    if (element.Priority == p)
                    {
                        filteredInsertionOrder.Add(element);
                    }
                }

                foreach (Element element in filteredInsertionOrder)
                {
                    assertEquals(element, queue.Poll());
                }
            }
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowMinCountDespiteSizeLimit()
        public virtual void ShouldAllowMinCountDespiteSizeLimit()
        {
            Config config = new Config(2, 5, 100);
            BoundedPriorityQueue <int> queue = new BoundedPriorityQueue <int>(config, int?.longValue, _noPriority);

            assertEquals(OK, queue.Offer(101));
            assertEquals(OK, queue.Offer(101));
            assertEquals(E_SIZE_EXCEEDED, queue.Offer(1));
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowMoreThanMaxBytes()
        public virtual void ShouldNotAllowMoreThanMaxBytes()
        {
            BoundedPriorityQueue <int> queue = new BoundedPriorityQueue <int>(_baseConfig, int?.longValue, _noPriority);

            assertEquals(E_SIZE_EXCEEDED, queue.Offer(101));
            assertEquals(OK, queue.Offer(99));
            assertEquals(OK, queue.Offer(1));
            assertEquals(E_SIZE_EXCEEDED, queue.Offer(1));
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowZeroSizedItemsDespiteSizeLimit()
        public virtual void ShouldAllowZeroSizedItemsDespiteSizeLimit()
        {
            BoundedPriorityQueue <int> queue = new BoundedPriorityQueue <int>(_baseConfig, int?.longValue, _noPriority);

            assertEquals(OK, queue.Offer(100));
            assertEquals(E_SIZE_EXCEEDED, queue.Offer(1));

            assertEquals(OK, queue.Offer(0));
            assertEquals(OK, queue.Offer(0));
        }
Пример #6
0
            public override int Compare(BoundedPriorityQueue <E> .StableElement o1, BoundedPriorityQueue <E> .StableElement o2)
            {
                int compare = ComparatorConflict.Compare(o1.element, o2.element);

                if (compare != 0)
                {
                    return(compare);
                }
                return(Long.compare(o1.seqNo, o2.seqNo));
            }
Пример #7
0
            internal StableElement(BoundedPriorityQueue <E> outerInstance, E element)
            {
                this._outerInstance = outerInstance;

                if (!InstanceFieldsInitialized)
                {
                    InitializeInstanceFields();
                    InstanceFieldsInitialized = true;
                }
                this.Element = element;
            }
Пример #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowMoreThanMaxCountDespiteZeroSize()
        public virtual void ShouldNotAllowMoreThanMaxCountDespiteZeroSize()
        {
            BoundedPriorityQueue <int> queue = new BoundedPriorityQueue <int>(_baseConfig, int?.longValue, _noPriority);

            assertEquals(OK, queue.Offer(0));
            assertEquals(OK, queue.Offer(0));
            assertEquals(OK, queue.Offer(0));
            assertEquals(OK, queue.Offer(0));
            assertEquals(OK, queue.Offer(0));

            assertEquals(E_COUNT_EXCEEDED, queue.Offer(0));
        }
Пример #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToPeekEntries()
        public virtual void ShouldBeAbleToPeekEntries()
        {
            BoundedPriorityQueue <int> queue = new BoundedPriorityQueue <int>(_baseConfig, int?.longValue, _noPriority);

            assertEquals(OK, queue.Offer(1));
            assertEquals(OK, queue.Offer(2));
            assertEquals(OK, queue.Offer(3));

//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            assertEquals(1, queue.Peek().map(Removable::get));
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            assertEquals(1, queue.Peek().map(Removable::get));
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            assertEquals(1, queue.Peek().map(Removable::get));

            assertEquals(3, queue.Count());
            assertEquals(6, queue.Bytes());
        }
Пример #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRespectPriority()
        public virtual void ShouldRespectPriority()
        {
            int    count  = 100;
            Config config = new Config(0, count, 0);
            BoundedPriorityQueue <int> queue = new BoundedPriorityQueue <int>(config, i => 0L, int?.compare);

            IList <int> list = new List <int>(count);

            for (int i = 0; i < count; i++)
            {
                list.Add(i);
            }

            Collections.shuffle(list, _tlr);
            list.ForEach(queue.offer);

            for (int i = 0; i < count; i++)
            {
                assertEquals(i, queue.Poll());
            }
        }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportTotalCountAndSize()
        public virtual void ShouldReportTotalCountAndSize()
        {
            BoundedPriorityQueue <int> queue = new BoundedPriorityQueue <int>(_baseConfig, int?.longValue, _noPriority);

            assertEquals(0, queue.Bytes());
            assertEquals(0, queue.Count());

            queue.Offer(10);
            assertEquals(1, queue.Count());
            assertEquals(10, queue.Bytes());

            queue.Offer(20);
            assertEquals(2, queue.Count());
            assertEquals(30, queue.Bytes());

            queue.Poll();
            assertEquals(1, queue.Count());
            assertEquals(20, queue.Bytes());

            queue.Poll();
            assertEquals(0, queue.Count());
            assertEquals(0, queue.Bytes());
        }
Пример #12
0
 internal Comparator(BoundedPriorityQueue <E> outerInstance, IComparer <E> comparator)
 {
     this._outerInstance     = outerInstance;
     this.ComparatorConflict = comparator;
 }