Exemplo n.º 1
0
        public virtual void  TestMixedStringArray()
        {
            TermAttributeImpl t = new TermAttributeImpl();

            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");
        }
		public virtual void  TestGrow()
		{
			TermAttributeImpl t = new TermAttributeImpl();
			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 TermAttributeImpl();
			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 TermAttributeImpl();
			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 TermAttributeImpl();
			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 TermAttributeImpl();
			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);
		}
		public virtual void  TestMixedStringArray()
		{
			TermAttributeImpl t = new TermAttributeImpl();
			
            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");
		}
Exemplo n.º 4
0
        public virtual void  TestGrow()
        {
            TermAttributeImpl t = new TermAttributeImpl();

            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 TermAttributeImpl();
            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 TermAttributeImpl();
            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 TermAttributeImpl();
            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 TermAttributeImpl();
            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);
        }