public virtual void TestToString()
        {
            char[]            b = new char[] { 'a', 'l', 'o', 'h', 'a' };
            CharTermAttribute t = new CharTermAttribute();

            t.CopyBuffer(b, 0, 5);
            Assert.AreEqual("aloha", t.ToString());

            t.SetEmpty().Append("hi there");
            Assert.AreEqual("hi there", t.ToString());
        }
Example #2
0
        public virtual void TestClone()
        {
            CharTermAttribute t = new CharTermAttribute();

            char[] content = "hello".ToCharArray();
            t.CopyBuffer(content, 0, 5);
            char[]            buf  = t.Buffer;
            CharTermAttribute copy = TestToken.AssertCloneIsEqual(t);

            Assert.AreEqual(t.ToString(), copy.ToString());
            Assert.AreNotSame(buf, copy.Buffer);
        }
 public virtual void TestResize()
 {
     CharTermAttribute t = new CharTermAttribute();
     char[] content = "hello".ToCharArray();
     t.CopyBuffer(content, 0, content.Length);
     for (int i = 0; i < 2000; i++)
     {
         t.ResizeBuffer(i);
         Assert.IsTrue(i <= t.Buffer.Length);
         Assert.AreEqual("hello", t.ToString());
     }
 }
 public virtual void TestEquals()
 {
     CharTermAttribute t1a = new CharTermAttribute();
     char[] content1a = "hello".ToCharArray();
     t1a.CopyBuffer(content1a, 0, 5);
     CharTermAttribute t1b = new CharTermAttribute();
     char[] content1b = "hello".ToCharArray();
     t1b.CopyBuffer(content1b, 0, 5);
     CharTermAttribute t2 = new CharTermAttribute();
     char[] content2 = "hello2".ToCharArray();
     t2.CopyBuffer(content2, 0, 6);
     Assert.IsTrue(t1a.Equals(t1b));
     Assert.IsFalse(t1a.Equals(t2));
     Assert.IsFalse(t2.Equals(t1b));
 }
Example #5
0
        public virtual void TestGrow()
        {
            CharTermAttribute t   = new CharTermAttribute();
            StringBuilder     buf = new StringBuilder("ab");

            for (int i = 0; i < 20; i++)
            {
                char[] content = buf.ToString().ToCharArray();
                t.CopyBuffer(content, 0, content.Length);
                Assert.AreEqual(buf.Length, t.Length);
                Assert.AreEqual(buf.ToString(), t.ToString());
                buf.Append(buf.ToString());
            }
            Assert.AreEqual(1048576, t.Length);

            // now as a StringBuilder, first variant
            t   = new CharTermAttribute();
            buf = new StringBuilder("ab");
            for (int i = 0; i < 20; i++)
            {
                t.SetEmpty().Append(buf);
                Assert.AreEqual(buf.Length, t.Length);
                Assert.AreEqual(buf.ToString(), t.ToString());
                buf.Append(t);
            }
            Assert.AreEqual(1048576, t.Length);

            // Test for slow growth to a long term
            t   = new CharTermAttribute();
            buf = new StringBuilder("a");
            for (int i = 0; i < 20000; i++)
            {
                t.SetEmpty().Append(buf);
                Assert.AreEqual(buf.Length, t.Length);
                Assert.AreEqual(buf.ToString(), t.ToString());
                buf.Append("a");
            }
            Assert.AreEqual(20000, t.Length);
        }
Example #6
0
        public override void CopyTo(IAttribute target)
        {
            CharTermAttribute t = (CharTermAttribute)target;

            t.CopyBuffer(termBuffer, 0, termLength);
        }