CharAt() public method

public CharAt ( int index ) : char
index int
return char
示例#1
0
        public virtual void TestCharSequenceInterface()
        {
            const string      s = "0123456789";
            CharTermAttribute t = new CharTermAttribute();

            t.Append(s);

            Assert.AreEqual(s.Length, t.Length);
            Assert.AreEqual("12", t.SubSequence(1, 3).ToString());
            Assert.AreEqual(s, t.SubSequence(0, s.Length).ToString());

            Assert.IsTrue(Regex.IsMatch(t.ToString(), "01\\d+"));
            Assert.IsTrue(Regex.IsMatch(t.SubSequence(3, 5).ToString(), "34"));

            Assert.AreEqual(s.Substring(3, 4), t.SubSequence(3, 7).ToString());

            for (int i = 0; i < s.Length; i++)
            {
                Assert.IsTrue(t.CharAt(i) == s[i]);
            }

            // LUCENENET specific to test indexer
            for (int i = 0; i < s.Length; i++)
            {
                Assert.IsTrue(t[i] == s[i]);
            }
        }
示例#2
0
        public virtual void TestExceptions()
        {
            CharTermAttribute t = new CharTermAttribute();

            t.Append("test");
            Assert.AreEqual("test", t.ToString());

            try
            {
                t.CharAt(-1);
                Assert.Fail("Should throw IndexOutOfBoundsException");
            }
            catch (System.IndexOutOfRangeException)
            {
            }

            try
            {
                t.CharAt(4);
                Assert.Fail("Should throw IndexOutOfBoundsException");
            }
            catch (System.IndexOutOfRangeException)
            {
            }

            try
            {
                t.SubSequence(0, 5);
                Assert.Fail("Should throw IndexOutOfBoundsException");
            }
            catch (System.IndexOutOfRangeException)
            {
            }

            try
            {
                t.SubSequence(5, 0);
                Assert.Fail("Should throw IndexOutOfBoundsException");
            }
            catch (System.IndexOutOfRangeException)
            {
            }
        }
示例#3
0
        public virtual void TestCharSequenceInterface()
        {
            const string      s = "0123456789";
            CharTermAttribute t = new CharTermAttribute();

            t.Append(s);

            Assert.AreEqual(s.Length, t.Length);
            Assert.AreEqual("12", t.SubSequence(1, 3).ToString());
            Assert.AreEqual(s, t.SubSequence(0, s.Length).ToString());

            //Assert.IsTrue(Pattern.matches("01\\d+", t));
            //Assert.IsTrue(Pattern.matches("34", t.SubSequence(3, 5)));

            Assert.AreEqual(s.Substring(3, 4), t.SubSequence(3, 7).ToString());

            for (int i = 0; i < s.Length; i++)
            {
                Assert.IsTrue(t.CharAt(i) == s[i]);
            }
        }
        public virtual void TestExceptions()
        {
            CharTermAttribute t = new CharTermAttribute();
            t.Append("test");
            Assert.AreEqual("test", t.ToString());

            try
            {
                t.CharAt(-1);
                Assert.Fail("Should throw IndexOutOfBoundsException");
            }
            catch (System.IndexOutOfRangeException)
            {
            }

            try
            {
                t.CharAt(4);
                Assert.Fail("Should throw IndexOutOfBoundsException");
            }
            catch (System.IndexOutOfRangeException)
            {
            }

            try
            {
                t.SubSequence(0, 5);
                Assert.Fail("Should throw IndexOutOfBoundsException");
            }
            catch (System.IndexOutOfRangeException)
            {
            }

            try
            {
                t.SubSequence(5, 0);
                Assert.Fail("Should throw IndexOutOfBoundsException");
            }
            catch (System.IndexOutOfRangeException)
            {
            }
        }
        public virtual void TestCharSequenceInterface()
        {
            const string s = "0123456789";
            CharTermAttribute t = new CharTermAttribute();
            t.Append(s);

            Assert.AreEqual(s.Length, t.Length);
            Assert.AreEqual("12", t.SubSequence(1, 3).ToString());
            Assert.AreEqual(s, t.SubSequence(0, s.Length).ToString());

            //Assert.IsTrue(Pattern.matches("01\\d+", t));
            //Assert.IsTrue(Pattern.matches("34", t.SubSequence(3, 5)));

            Assert.AreEqual(s.Substring(3, 4), t.SubSequence(3, 7).ToString());

            for (int i = 0; i < s.Length; i++)
            {
                Assert.IsTrue(t.CharAt(i) == s[i]);
            }
        }
        public virtual void TestCharSequenceInterface()
        {
            const string s = "0123456789";
            CharTermAttribute t = new CharTermAttribute();
            t.Append(s);

            Assert.AreEqual(s.Length, t.Length);
            Assert.AreEqual("12", t.SubSequence(1, 3).ToString());
            Assert.AreEqual(s, t.SubSequence(0, s.Length).ToString());

            Assert.IsTrue(Regex.IsMatch(t.ToString(), "01\\d+"));
            Assert.IsTrue(Regex.IsMatch(t.SubSequence(3, 5).ToString(), "34"));

            Assert.AreEqual(s.Substring(3, 4), t.SubSequence(3, 7).ToString());

            for (int i = 0; i < s.Length; i++)
            {
                Assert.IsTrue(t.CharAt(i) == s[i]);
            }

            // LUCENENET specific to test indexer
            for (int i = 0; i < s.Length; i++)
            {
                Assert.IsTrue(t[i] == s[i]);
            }
        }