예제 #1
0
        public virtual void  TestToString()
        {
            char[]        b = new char[] { 'a', 'l', 'o', 'h', 'a' };
            TermAttribute t = new TermAttribute();

            t.SetTermBuffer(b, 0, 5);
            Assert.AreEqual("term=aloha", t.ToString());

            t.SetTermBuffer("hi there");
            Assert.AreEqual("term=hi there", t.ToString());
        }
예제 #2
0
        public override void  CopyTo(AttributeImpl target)
        {
            InitTermBuffer();
            TermAttribute t = (TermAttribute)target;

            t.SetTermBuffer(termBuffer, 0, termLength);
        }
예제 #3
0
        public virtual void  TestMixedStringArray()
        {
            TermAttribute t = new TermAttribute();

            t.SetTermBuffer("hello");
            Assert.AreEqual(t.TermLength(), 5);
            Assert.AreEqual(t.Term, "hello");
            t.SetTermBuffer("hello2");
            Assert.AreEqual(t.TermLength(), 6);
            Assert.AreEqual(t.Term, "hello2");
            t.SetTermBuffer("hello3".ToCharArray(), 0, 6);
            Assert.AreEqual(t.Term, "hello3");

            // Make sure if we get the buffer and change a character
            // that term() reflects the change
            char[] buffer = t.TermBuffer();
            buffer[1] = 'o';
            Assert.AreEqual(t.Term, "hollo3");
        }
예제 #4
0
        public virtual void  TestClone()
        {
            TermAttribute t = new TermAttribute();

            char[] content = "hello".ToCharArray();
            t.SetTermBuffer(content, 0, 5);
            char[]        buf  = t.TermBuffer();
            TermAttribute copy = (TermAttribute)TestSimpleAttributeImpls.AssertCloneIsEqual(t);

            Assert.AreEqual(t.Term, copy.Term);
            Assert.AreNotSame(buf, copy.TermBuffer());
        }
예제 #5
0
 public virtual void  TestResize()
 {
     TermAttribute t = new TermAttribute();
     char[] content = "hello".ToCharArray();
     t.SetTermBuffer(content, 0, content.Length);
     for (int i = 0; i < 2000; i++)
     {
         t.ResizeTermBuffer(i);
         Assert.IsTrue(i <= t.TermBuffer().Length);
         Assert.AreEqual("hello", t.Term);
     }
 }
예제 #6
0
        public virtual void  TestResize()
        {
            TermAttribute t = new TermAttribute();

            char[] content = "hello".ToCharArray();
            t.SetTermBuffer(content, 0, content.Length);
            for (int i = 0; i < 2000; i++)
            {
                t.ResizeTermBuffer(i);
                Assert.IsTrue(i <= t.TermBuffer().Length);
                Assert.AreEqual("hello", t.Term);
            }
        }
예제 #7
0
        public virtual void  TestEquals()
        {
            TermAttribute t1a = new TermAttribute();

            char[] content1a = "hello".ToCharArray();
            t1a.SetTermBuffer(content1a, 0, 5);
            TermAttribute t1b = new TermAttribute();

            char[] content1b = "hello".ToCharArray();
            t1b.SetTermBuffer(content1b, 0, 5);
            TermAttribute t2 = new TermAttribute();

            char[] content2 = "hello2".ToCharArray();
            t2.SetTermBuffer(content2, 0, 6);
            Assert.IsTrue(t1a.Equals(t1b));
            Assert.IsFalse(t1a.Equals(t2));
            Assert.IsFalse(t2.Equals(t1b));
        }
예제 #8
0
        public virtual void  TestGrow()
        {
            TermAttribute t = new TermAttribute();

            System.Text.StringBuilder buf = new System.Text.StringBuilder("ab");
            for (int i = 0; i < 20; i++)
            {
                char[] content = buf.ToString().ToCharArray();
                t.SetTermBuffer(content, 0, content.Length);
                Assert.AreEqual(buf.Length, t.TermLength());
                Assert.AreEqual(buf.ToString(), t.Term);
                buf.Append(buf.ToString());
            }
            Assert.AreEqual(1048576, t.TermLength());
            Assert.AreEqual(1048576, t.TermBuffer().Length);

            // now as a string, first variant
            t   = new TermAttribute();
            buf = new System.Text.StringBuilder("ab");
            for (int i = 0; i < 20; i++)
            {
                System.String content = buf.ToString();
                t.SetTermBuffer(content, 0, content.Length);
                Assert.AreEqual(content.Length, t.TermLength());
                Assert.AreEqual(content, t.Term);
                buf.Append(content);
            }
            Assert.AreEqual(1048576, t.TermLength());
            Assert.AreEqual(1048576, t.TermBuffer().Length);

            // now as a string, second variant
            t   = new TermAttribute();
            buf = new System.Text.StringBuilder("ab");
            for (int i = 0; i < 20; i++)
            {
                System.String content = buf.ToString();
                t.SetTermBuffer(content);
                Assert.AreEqual(content.Length, t.TermLength());
                Assert.AreEqual(content, t.Term);
                buf.Append(content);
            }
            Assert.AreEqual(1048576, t.TermLength());
            Assert.AreEqual(1048576, t.TermBuffer().Length);

            // Test for slow growth to a long term
            t   = new TermAttribute();
            buf = new System.Text.StringBuilder("a");
            for (int i = 0; i < 20000; i++)
            {
                System.String content = buf.ToString();
                t.SetTermBuffer(content);
                Assert.AreEqual(content.Length, t.TermLength());
                Assert.AreEqual(content, t.Term);
                buf.Append("a");
            }
            Assert.AreEqual(20000, t.TermLength());
            Assert.AreEqual(32768, t.TermBuffer().Length);

            // Test for slow growth to a long term
            t   = new TermAttribute();
            buf = new System.Text.StringBuilder("a");
            for (int i = 0; i < 20000; i++)
            {
                System.String content = buf.ToString();
                t.SetTermBuffer(content);
                Assert.AreEqual(content.Length, t.TermLength());
                Assert.AreEqual(content, t.Term);
                buf.Append("a");
            }
            Assert.AreEqual(20000, t.TermLength());
            Assert.AreEqual(32768, t.TermBuffer().Length);
        }
예제 #9
0
 public virtual void  TestGrow()
 {
     TermAttribute t = new TermAttribute();
     System.Text.StringBuilder buf = new System.Text.StringBuilder("ab");
     for (int i = 0; i < 20; i++)
     {
         char[] content = buf.ToString().ToCharArray();
         t.SetTermBuffer(content, 0, content.Length);
         Assert.AreEqual(buf.Length, t.TermLength());
         Assert.AreEqual(buf.ToString(), t.Term);
         buf.Append(buf.ToString());
     }
     Assert.AreEqual(1048576, t.TermLength());
     Assert.AreEqual(1179654, t.TermBuffer().Length);
     
     // now as a string, first variant
     t = new TermAttribute();
     buf = new System.Text.StringBuilder("ab");
     for (int i = 0; i < 20; i++)
     {
         System.String content = buf.ToString();
         t.SetTermBuffer(content, 0, content.Length);
         Assert.AreEqual(content.Length, t.TermLength());
         Assert.AreEqual(content, t.Term);
         buf.Append(content);
     }
     Assert.AreEqual(1048576, t.TermLength());
     Assert.AreEqual(1179654, t.TermBuffer().Length);
     
     // now as a string, second variant
     t = new TermAttribute();
     buf = new System.Text.StringBuilder("ab");
     for (int i = 0; i < 20; i++)
     {
         System.String content = buf.ToString();
         t.SetTermBuffer(content);
         Assert.AreEqual(content.Length, t.TermLength());
         Assert.AreEqual(content, t.Term);
         buf.Append(content);
     }
     Assert.AreEqual(1048576, t.TermLength());
     Assert.AreEqual(1179654, t.TermBuffer().Length);
     
     // Test for slow growth to a long term
     t = new TermAttribute();
     buf = new System.Text.StringBuilder("a");
     for (int i = 0; i < 20000; i++)
     {
         System.String content = buf.ToString();
         t.SetTermBuffer(content);
         Assert.AreEqual(content.Length, t.TermLength());
         Assert.AreEqual(content, t.Term);
         buf.Append("a");
     }
     Assert.AreEqual(20000, t.TermLength());
     Assert.AreEqual(20167, t.TermBuffer().Length);
     
     // Test for slow growth to a long term
     t = new TermAttribute();
     buf = new System.Text.StringBuilder("a");
     for (int i = 0; i < 20000; i++)
     {
         System.String content = buf.ToString();
         t.SetTermBuffer(content);
         Assert.AreEqual(content.Length, t.TermLength());
         Assert.AreEqual(content, t.Term);
         buf.Append("a");
     }
     Assert.AreEqual(20000, t.TermLength());
     Assert.AreEqual(20167, t.TermBuffer().Length);
 }
예제 #10
0
 public virtual void  TestCopyTo()
 {
     TermAttribute t = new TermAttribute();
     TermAttribute copy = (TermAttribute) TestSimpleAttributeImpls.AssertCopyIsEqual(t);
     Assert.AreEqual("", t.Term);
     Assert.AreEqual("", copy.Term);
     
     t = new TermAttribute();
     char[] content = "hello".ToCharArray();
     t.SetTermBuffer(content, 0, 5);
     char[] buf = t.TermBuffer();
     copy = (TermAttribute) TestSimpleAttributeImpls.AssertCopyIsEqual(t);
     Assert.AreEqual(t.Term, copy.Term);
     Assert.AreNotSame(buf, copy.TermBuffer());
 }
예제 #11
0
 public virtual void  TestEquals()
 {
     TermAttribute t1a = new TermAttribute();
     char[] content1a = "hello".ToCharArray();
     t1a.SetTermBuffer(content1a, 0, 5);
     TermAttribute t1b = new TermAttribute();
     char[] content1b = "hello".ToCharArray();
     t1b.SetTermBuffer(content1b, 0, 5);
     TermAttribute t2 = new TermAttribute();
     char[] content2 = "hello2".ToCharArray();
     t2.SetTermBuffer(content2, 0, 6);
     Assert.IsTrue(t1a.Equals(t1b));
     Assert.IsFalse(t1a.Equals(t2));
     Assert.IsFalse(t2.Equals(t1b));
 }
예제 #12
0
 public virtual void  TestMixedStringArray()
 {
     TermAttribute t = new TermAttribute();
     t.SetTermBuffer("hello");
     Assert.AreEqual(t.TermLength(), 5);
     Assert.AreEqual(t.Term, "hello");
     t.SetTermBuffer("hello2");
     Assert.AreEqual(t.TermLength(), 6);
     Assert.AreEqual(t.Term, "hello2");
     t.SetTermBuffer("hello3".ToCharArray(), 0, 6);
     Assert.AreEqual(t.Term, "hello3");
     
     // Make sure if we get the buffer and change a character
     // that term() reflects the change
     char[] buffer = t.TermBuffer();
     buffer[1] = 'o';
     Assert.AreEqual(t.Term, "hollo3");
 }
예제 #13
0
 public virtual void  TestToString()
 {
     char[] b = new char[]{'a', 'l', 'o', 'h', 'a'};
     TermAttribute t = new TermAttribute();
     t.SetTermBuffer(b, 0, 5);
     Assert.AreEqual("term=aloha", t.ToString());
     
     t.SetTermBuffer("hi there");
     Assert.AreEqual("term=hi there", t.ToString());
 }