Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testPagingIterator()
        internal virtual void TestPagingIterator()
        {
            IEnumerator <int>    source = new RangeIterator(24);
            PagingIterator <int> pager  = new PagingIterator <int>(source, 10);

            assertEquals(0, pager.Page());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue(pager.HasNext());
            AssertPage(pager.NextPage(), 10, 0);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue(pager.HasNext());

            assertEquals(1, pager.Page());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue(pager.HasNext());
            AssertPage(pager.NextPage(), 10, 10);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue(pager.HasNext());

            assertEquals(2, pager.Page());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue(pager.HasNext());
            AssertPage(pager.NextPage(), 4, 20);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(pager.HasNext());

            pager.Page(1);
            assertEquals(1, pager.Page());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue(pager.HasNext());
            AssertPage(pager.NextPage(), 10, 10);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue(pager.HasNext());
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testCachingIterator()
        internal virtual void TestCachingIterator()
        {
            IEnumerator <int>     source  = new RangeIterator(8);
            CachingIterator <int> caching = new CachingIterator <int>(source);

            assertThrows(typeof(NoSuchElementException), caching.previous);
            assertThrows(typeof(NoSuchElementException), caching.current);

            // Next and previous
            assertEquals(0, caching.Position());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue(caching.HasNext());
            assertEquals(0, caching.Position());
            assertFalse(caching.HasPrevious());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(( int? )0, caching.Next());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue(caching.HasNext());
            assertTrue(caching.HasPrevious());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(( int? )1, caching.Next());
            assertTrue(caching.HasPrevious());
            assertEquals(( int? )1, caching.Current());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(( int? )2, caching.Next());
            assertEquals(( int? )2, caching.Current());
            assertEquals(( int? )3, ( int? )caching.Position());
            assertEquals(( int? )2, caching.Current());
            assertTrue(caching.HasPrevious());
            assertEquals(( int? )2, caching.Previous());
            assertEquals(( int? )2, caching.Current());
            assertEquals(( int? )2, ( int? )caching.Position());
            assertEquals(( int? )1, caching.Previous());
            assertEquals(( int? )1, caching.Current());
            assertEquals(( int? )1, ( int? )caching.Position());
            assertEquals(( int? )0, caching.Previous());
            assertEquals(( int? )0, ( int? )caching.Position());
            assertFalse(caching.HasPrevious());

            assertThrows(typeof(System.ArgumentException), () => caching.Position(-1), "Shouldn't be able to set a lower value than 0");

            assertEquals(( int? )0, caching.Current());
            assertEquals(0, caching.Position(3));

            assertThrows(typeof(NoSuchElementException), caching.current, "Shouldn't be able to call current() after a call to position(int)");

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue(caching.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(( int? )3, caching.Next());
            assertEquals(( int? )3, caching.Current());
            assertTrue(caching.HasPrevious());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(( int? )4, caching.Next());
            assertEquals(5, caching.Position());
            assertEquals(( int? )4, caching.Previous());
            assertEquals(( int? )4, caching.Current());
            assertEquals(( int? )4, caching.Current());
            assertEquals(4, caching.Position());
            assertEquals(( int? )3, caching.Previous());
            assertEquals(3, caching.Position());

            assertThrows(typeof(NoSuchElementException), () => caching.Position(9), "Shouldn't be able to set a position which is too big");

            assertEquals(3, caching.Position(8));
            assertTrue(caching.HasPrevious());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(caching.HasNext());

            assertThrows(typeof(NoSuchElementException), caching.next, "Shouldn't be able to go beyond last item");

            assertEquals(8, caching.Position());
            assertEquals(( int? )7, caching.Previous());
            assertEquals(( int? )6, caching.Previous());
            assertEquals(6, caching.Position(0));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(( int? )0, caching.Next());
        }