Exemplo n.º 1
0
        public void Test_previous()
        {
            StringCharacterEnumerator fixture = new StringCharacterEnumerator("fixture");

            assertEquals(false, fixture.MovePrevious());
            assertTrue(fixture.MoveNext());
            assertEquals('i', fixture.Current);
            assertTrue(fixture.MoveNext());
            assertEquals('x', fixture.Current);
            assertTrue(fixture.MoveNext());
            assertEquals('t', fixture.Current);
            assertTrue(fixture.MoveNext());
            assertEquals('u', fixture.Current);
            assertTrue(fixture.MoveNext());
            assertEquals('r', fixture.Current);
            assertTrue(fixture.MoveNext());
            assertEquals('e', fixture.Current);
            assertEquals(false, fixture.MoveNext());
            assertEquals(false, fixture.MoveNext());
            assertEquals(false, fixture.MoveNext());
            assertEquals(6, fixture.Index);
            //assertTrue(fixture.MovePrevious());
            assertEquals('e', fixture.Current);
            assertEquals(6, fixture.Index);
            assertTrue(fixture.MovePrevious());
            assertEquals('r', fixture.Current);
            assertEquals(5, fixture.Index);
            assertTrue(fixture.MovePrevious());
            assertEquals('u', fixture.Current);
            assertEquals(4, fixture.Index);
            assertTrue(fixture.MovePrevious());
            assertEquals('t', fixture.Current);
            assertEquals(3, fixture.Index);
            assertTrue(fixture.MovePrevious());
            assertEquals('x', fixture.Current);
            assertEquals(2, fixture.Index);
            assertTrue(fixture.MovePrevious());
            assertEquals('i', fixture.Current);
            assertEquals(1, fixture.Index);
            assertTrue(fixture.MovePrevious());
            assertEquals('f', fixture.Current);
            assertEquals(0, fixture.Index);
            assertEquals(false, fixture.MovePrevious());
            assertEquals(0, fixture.Index);

            StringCharacterEnumerator it1 =
                new StringCharacterEnumerator("testing", 2, 4, 4);

            assertTrue(it1.MovePrevious());
            assertEquals("Wrong previous char1", 't', it1.Current);
            assertTrue(it1.MovePrevious());
            assertEquals("Wrong previous char2", 's', it1.Current);
            assertTrue("Wrong previous char3",
                       it1.MovePrevious() == false);
            assertTrue("Wrong previous char4",
                       it1.MovePrevious() == false);
            assertEquals("Wrong index", 2, it1.Index);
            assertEquals("Wrong current char", 's', it1.Current);
        }
Exemplo n.º 2
0
        public void Test_setIndexI()
        {
            StringCharacterEnumerator it1 = new StringCharacterEnumerator("testing", 2,
                                                                          4, 4);

            it1.Index = 2;
            assertEquals("Wrong result1", 's', it1.Current);
            assertTrue(it1.MoveNext());
            char result = it1.Current;

            assertTrue("Wrong next char: " + result, result == 't');
            try
            {
                it1.Index = 6;
                fail("Assert 3: No ArgumentOutOfRangeException");
            }
            catch (ArgumentOutOfRangeException)
            {
                // expected
            }

            assertFalse("Wrong result2", it1.TrySetIndex(6));
            //assertTrue("Wrong result2", it1.SetIndex(6) == CharacterIterator.Done);
            //assertTrue(it1.MovePrevious());
            assertEquals("Wrong previous char", 'n', it1.Current);
            assertTrue(it1.MovePrevious());
            assertEquals("Wrong previous char", 'i', it1.Current);
        }
Exemplo n.º 3
0
        public void Test_hashCode()
        {
            StringCharacterEnumerator it1 = new StringCharacterEnumerator("testing", 2,
                                                                          4, 4);
            StringCharacterEnumerator it2 = new StringCharacterEnumerator("xxstinx", 2,
                                                                          4, 4);

            assertTrue("Hash is equal", it1.GetHashCode() != it2.GetHashCode());
            StringCharacterEnumerator it3 = new StringCharacterEnumerator("testing", 2,
                                                                          4, 2);

            assertTrue("Hash equal1", it1.GetHashCode() != it3.GetHashCode());
            it3 = new StringCharacterEnumerator("testing", 0, 6, 4);
            assertTrue("Hash equal2", it1.GetHashCode() != it3.GetHashCode());
            it3 = new StringCharacterEnumerator("testing", 2, 3, 4);
            assertTrue("Hash equal3", it1.GetHashCode() != it3.GetHashCode());
            it3 = new StringCharacterEnumerator("froging", 2, 4, 4);
            assertTrue("Hash equal4", it1.GetHashCode() != it3.GetHashCode());

            StringCharacterEnumerator sci0 = new StringCharacterEnumerator("fixture");

            assertEquals(sci0.GetHashCode(), sci0.GetHashCode());

            StringCharacterEnumerator sci1 = new StringCharacterEnumerator("fixture");

            assertEquals(sci0.GetHashCode(), sci1.GetHashCode());

            sci1.MoveNext();
            sci0.MoveNext();
            assertEquals(sci0.GetHashCode(), sci1.GetHashCode());
        }
Exemplo n.º 4
0
        public void Test_setIndex()
        {
            StringCharacterEnumerator fixture = new StringCharacterEnumerator("fixture");

            while (fixture.MoveNext())
            {
                // empty
            }
            assertEquals("fixture".Length - 1, fixture.Index);
            fixture.Index = 0;
            assertEquals(0, fixture.Index);
            assertEquals('f', fixture.Current);
            fixture.Index = "fixture".Length - 1;
            assertEquals('e', fixture.Current);
            try
            {
                fixture.Index = (-1);
                fail("no illegal argument");
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }

            try
            {
                fixture.Index = ("fixture".Length + 1);
                fail("no illegal argument");
            }
            catch (ArgumentOutOfRangeException e)
            {
                // expected
            }
        }
Exemplo n.º 5
0
        public void Test_first()
        {
            StringCharacterEnumerator fixture = new StringCharacterEnumerator("fixture");

            assertTrue(fixture.MoveFirst());
            assertEquals('f', fixture.Current);
            fixture.MoveNext();
            assertTrue(fixture.MoveFirst());
            assertEquals('f', fixture.Current);
            fixture = new StringCharacterEnumerator("fixture", 1);
            assertTrue(fixture.MoveFirst());
            assertEquals('f', fixture.Current);
            fixture = new StringCharacterEnumerator("fixture", 1, "fixture".Length - 1,
                                                    2);
            assertTrue(fixture.MoveFirst());
            assertEquals('i', fixture.Current);

            StringCharacterEnumerator it1 =
                new StringCharacterEnumerator("testing", 2, 4, 4);

            assertTrue(it1.MoveFirst());
            assertEquals("Wrong first char", 's', it1.Current);
            assertTrue(it1.MoveNext());
            assertEquals("Wrong next char", 't', it1.Current);
            it1 = new StringCharacterEnumerator("testing", 2, 0, 2);
            assertTrue("Not DONE", it1.MoveFirst() == false);
        }
Exemplo n.º 6
0
        public void Test_equalsLjava_lang_Object()
        {
            StringCharacterEnumerator sci0 = new StringCharacterEnumerator("fixture");

            assertEquals(sci0, sci0);
            assertFalse(sci0.Equals(null));
            assertFalse(sci0.Equals("fixture"));

            StringCharacterEnumerator sci1 = new StringCharacterEnumerator("fixture");

            assertEquals(sci0, sci1);

            sci1.MoveNext();
            assertFalse(sci0.Equals(sci1));
            sci0.MoveNext();
            assertEquals(sci0, sci1);

            StringCharacterEnumerator it1 = new StringCharacterEnumerator("testing", 2,
                                                                          4, 4);
            StringCharacterEnumerator it2 = new StringCharacterEnumerator("xxstinx", 2,
                                                                          4, 4);

            assertTrue("Range is equal", !it1.Equals(it2));
            StringCharacterEnumerator it3 = new StringCharacterEnumerator("testing", 2,
                                                                          4, 2);

            it3.Index = 4;
            assertTrue("Not equal", it1.Equals(it3));
        }
Exemplo n.º 7
0
        public void Test_next()
        {
            StringCharacterEnumerator fixture = new StringCharacterEnumerator("fixture");

            assertEquals(0, fixture.Index);
            assertTrue(fixture.MoveNext());
            assertEquals('i', fixture.Current);
            assertEquals(1, fixture.Index);
            assertTrue(fixture.MoveNext());
            assertEquals('x', fixture.Current);
            assertEquals(2, fixture.Index);
            assertTrue(fixture.MoveNext());
            assertEquals('t', fixture.Current);
            assertEquals(3, fixture.Index);
            assertTrue(fixture.MoveNext());
            assertEquals('u', fixture.Current);
            assertEquals(4, fixture.Index);
            assertTrue(fixture.MoveNext());
            assertEquals('r', fixture.Current);
            assertEquals(5, fixture.Index);
            assertTrue(fixture.MoveNext());
            assertEquals('e', fixture.Current);
            assertEquals(6, fixture.Index);
            assertFalse(fixture.MoveNext());
            assertEquals(6, fixture.Index);
            assertFalse(fixture.MoveNext());
            assertEquals(6, fixture.Index);
            assertFalse(fixture.MoveNext());
            assertEquals(6, fixture.Index);

            StringCharacterEnumerator it1 = new StringCharacterEnumerator("testing", 2,
                                                                          4, 3);

            assertTrue(it1.MoveNext());
            char result = it1.Current;

            assertEquals("Wrong MoveNext() char1", 'i', result);
            assertTrue(it1.MoveNext());
            assertEquals("Wrong MoveNext() char2", 'n', it1.Current);
            assertTrue("Wrong MoveNext() char3", it1.MoveNext() == false);
            assertTrue("Wrong MoveNext() char4", it1.MoveNext() == false);
            int index = it1.Index;

            assertEquals("Wrong index", 5, index);
            assertTrue("Wrong current char",
                       it1.Current == 'n');
        }
Exemplo n.º 8
0
        public void Test_getIndex()
        {
            StringCharacterEnumerator it1 = new StringCharacterEnumerator("testing", 2,
                                                                          4, 4);

            assertEquals("Wrong index 4", 4, it1.Index);
            it1.MoveNext();
            assertEquals("Wrong index 5", 5, it1.Index);
            it1.MoveLast();
            assertEquals("Wrong index 4/2", 5, it1.Index);
        }
Exemplo n.º 9
0
        public void Test_ConstructorLjava_lang_StringI()
        {
            StringCharacterEnumerator it = new StringCharacterEnumerator("testing", 3);

            assertEquals("Wrong begin index", 0, it.StartIndex);
            assertEquals("Wrong end index", 6, it.EndIndex);
            assertEquals("Wrong current index", 3, it.Index);
            assertEquals("Wrong current char", 't', it.Current);
            assertTrue(it.MoveNext());
            assertEquals("Wrong next char", 'i', it.Current);
        }
Exemplo n.º 10
0
        public void Test_current()
        {
            StringCharacterEnumerator fixture = new StringCharacterEnumerator("fixture");

            assertEquals('f', fixture.Current);
            fixture.MoveNext();
            assertEquals('i', fixture.Current);

            StringCharacterEnumerator it =
                new StringCharacterEnumerator("testing", 2, 4, 4);

            assertEquals("Wrong current char", 'i', it.Current);
        }
Exemplo n.º 11
0
        public void TestLast()
        {
            StringCharacterEnumerator fixture = new StringCharacterEnumerator("fixture");

            assertTrue(fixture.MoveLast());
            assertEquals('e', fixture.Current);
            fixture.MoveNext();
            assertTrue(fixture.MoveLast());
            assertEquals('e', fixture.Current);
            fixture = new StringCharacterEnumerator("fixture", 1);
            assertTrue(fixture.MoveLast());
            assertEquals('e', fixture.Current);
            fixture = new StringCharacterEnumerator("fixture", 1, "fixture".Length - 1,
                                                    2);
            assertTrue(fixture.MoveLast());
            assertEquals('e', fixture.Current);
            fixture = new StringCharacterEnumerator("fixture", 1, 3, 2);
            assertTrue(fixture.MoveLast());
            assertEquals('t', fixture.Current);
        }
Exemplo n.º 12
0
        public void Test_ConstructorLjava_lang_String()
        {
            assertNotNull(new StringCharacterEnumerator("value"));
            assertNotNull(new StringCharacterEnumerator(""));
            try
            {
                new StringCharacterEnumerator(null);
                fail("Assert 0: no null pointer");
            }
            catch (ArgumentNullException e)
            {
                // expected
            }

            StringCharacterEnumerator it = new StringCharacterEnumerator("testing");

            assertEquals("Wrong begin index", 0, it.StartIndex);
            assertEquals("Wrong end index", 6, it.EndIndex);
            assertEquals("Wrong current index", 0, it.Index);
            assertEquals("Wrong current char", 't', it.Current);
            assertTrue(it.MoveNext());
            assertEquals("Wrong next char", 'e', it.Current);
        }