예제 #1
0
        public virtual void TestIntStream()
        {
            NumericTokenStream stream = (new NumericTokenStream()).SetInt32Value(ivalue);
            // use getAttribute to test if attributes really exist, if not an IAE will be throwed
            ITermToBytesRefAttribute bytesAtt = stream.GetAttribute <ITermToBytesRefAttribute>();
            ITypeAttribute           typeAtt  = stream.GetAttribute <ITypeAttribute>();

            NumericTokenStream.INumericTermAttribute numericAtt = stream.GetAttribute <NumericTokenStream.INumericTermAttribute>();
            BytesRef bytes = bytesAtt.BytesRef;

            stream.Reset();
            Assert.AreEqual(32, numericAtt.ValueSize);
            for (int shift = 0; shift < 32; shift += NumericUtils.PRECISION_STEP_DEFAULT)
            {
                Assert.IsTrue(stream.IncrementToken(), "New token is available");
                Assert.AreEqual(shift, numericAtt.Shift, "Shift value wrong");
                bytesAtt.FillBytesRef();
                Assert.AreEqual(ivalue & ~((1 << shift) - 1), NumericUtils.PrefixCodedToInt32(bytes), "Term is incorrectly encoded");
                Assert.AreEqual(((long)ivalue) & ~((1L << shift) - 1L), numericAtt.RawValue, "Term raw value is incorrectly encoded");
                Assert.AreEqual((shift == 0) ? NumericTokenStream.TOKEN_TYPE_FULL_PREC : NumericTokenStream.TOKEN_TYPE_LOWER_PREC, typeAtt.Type, "Type incorrect");
            }
            Assert.IsFalse(stream.IncrementToken(), "More tokens available");
            stream.End();
            stream.Dispose();
        }
        public virtual void TestNotInitialized()
        {
            NumericTokenStream stream = new NumericTokenStream();

            Assert.Throws <SystemException>(stream.Reset, "reset() should not succeed.");
            Assert.Throws <SystemException>(() => stream.IncrementToken(), "incrementToken() should not succeed.");
        }
예제 #3
0
        public virtual void TestNotInitialized()
        {
            NumericTokenStream stream = new NumericTokenStream();

            Assert.Throws<SystemException>(stream.Reset, "reset() should not succeed.");
            Assert.Throws<SystemException>(() => stream.IncrementToken(), "incrementToken() should not succeed.");
        }
예제 #4
0
 public virtual void  TestIntStream()
 {
     NumericTokenStream stream = new NumericTokenStream().SetIntValue(ivalue);
     // use getAttribute to test if attributes really exist, if not an IAE will be throwed
     ITermAttribute termAtt = stream.GetAttribute<ITermAttribute>();
     ITypeAttribute typeAtt = stream.GetAttribute<ITypeAttribute>();
     for (int shift = 0; shift < 32; shift += NumericUtils.PRECISION_STEP_DEFAULT)
     {
         Assert.IsTrue(stream.IncrementToken(), "New token is available");
         Assert.AreEqual(NumericUtils.IntToPrefixCoded(ivalue, shift), termAtt.Term, "Term is correctly encoded");
         Assert.AreEqual((shift == 0)?NumericTokenStream.TOKEN_TYPE_FULL_PREC:NumericTokenStream.TOKEN_TYPE_LOWER_PREC, typeAtt.Type, "Type correct");
     }
     Assert.IsFalse(stream.IncrementToken(), "No more tokens available");
 }
예제 #5
0
        public virtual void  TestIntStream()
        {
            NumericTokenStream stream = new NumericTokenStream().SetIntValue(ivalue);
            // use getAttribute to test if attributes really exist, if not an IAE will be throwed
            TermAttribute termAtt = (TermAttribute)stream.GetAttribute(typeof(TermAttribute));
            TypeAttribute typeAtt = (TypeAttribute)stream.GetAttribute(typeof(TypeAttribute));

            for (int shift = 0; shift < 32; shift += NumericUtils.PRECISION_STEP_DEFAULT)
            {
                Assert.IsTrue(stream.IncrementToken(), "New token is available");
                Assert.AreEqual(NumericUtils.IntToPrefixCoded(ivalue, shift), termAtt.Term(), "Term is correctly encoded");
                Assert.AreEqual((shift == 0)?NumericTokenStream.TOKEN_TYPE_FULL_PREC:NumericTokenStream.TOKEN_TYPE_LOWER_PREC, typeAtt.Type(), "Type correct");
            }
            Assert.IsFalse(stream.IncrementToken(), "No more tokens available");
        }
예제 #6
0
 public virtual void TestCTA()
 {
     NumericTokenStream stream = new NumericTokenStream();
     try
     {
         stream.AddAttribute<ICharTermAttribute>();
         Assert.Fail("Succeeded to add CharTermAttribute.");
     }
     catch (System.ArgumentException iae)
     {
         Assert.IsTrue(iae.Message.StartsWith("NumericTokenStream does not support"));
     }
     try
     {
         stream.AddAttribute<ITestAttribute>();
         Assert.Fail("Succeeded to add TestAttribute.");
     }
     catch (System.ArgumentException iae)
     {
         Assert.IsTrue(iae.Message.StartsWith("NumericTokenStream does not support"));
     }
 }
예제 #7
0
        public virtual void TestCTA()
        {
            NumericTokenStream stream = new NumericTokenStream();

            try
            {
                stream.AddAttribute <ICharTermAttribute>();
                Assert.Fail("Succeeded to add CharTermAttribute.");
            }
            catch (Exception iae) when(iae.IsIllegalArgumentException())
            {
                Assert.IsTrue(iae.Message.StartsWith("NumericTokenStream does not support", StringComparison.Ordinal));
            }
            try
            {
                stream.AddAttribute <ITestAttribute>();
                Assert.Fail("Succeeded to add TestAttribute.");
            }
            catch (Exception iae) when(iae.IsIllegalArgumentException())
            {
                Assert.IsTrue(iae.Message.StartsWith("NumericTokenStream does not support", StringComparison.Ordinal));
            }
        }
예제 #8
0
        public virtual void TestCTA()
        {
            NumericTokenStream stream = new NumericTokenStream();

            try
            {
                stream.AddAttribute <ICharTermAttribute>();
                Assert.Fail("Succeeded to add CharTermAttribute.");
            }
            catch (System.ArgumentException iae)
            {
                Assert.IsTrue(iae.Message.StartsWith("NumericTokenStream does not support"));
            }
            try
            {
                stream.AddAttribute <ITestAttribute>();
                Assert.Fail("Succeeded to add TestAttribute.");
            }
            catch (System.ArgumentException iae)
            {
                Assert.IsTrue(iae.Message.StartsWith("NumericTokenStream does not support"));
            }
        }
예제 #9
0
        public virtual void TestNotInitialized()
        {
            NumericTokenStream stream = new NumericTokenStream();

            try
            {
                stream.Reset();
                Assert.Fail("reset() should not succeed.");
            }
            catch (Exception e) when(e.IsIllegalStateException())
            {
                // pass
            }

            try
            {
                stream.IncrementToken();
                Assert.Fail("IncrementToken() should not succeed.");
            }
            catch (Exception e) when(e.IsIllegalStateException())
            {
                // pass
            }
        }
예제 #10
0
        public virtual void  TestNotInitialized()
        {
            NumericTokenStream stream = new NumericTokenStream();

            try
            {
                stream.Reset();
                Assert.Fail("reset() should not succeed.");
            }
            catch (System.SystemException e)
            {
                // pass
            }

            try
            {
                stream.IncrementToken();
                Assert.Fail("incrementToken() should not succeed.");
            }
            catch (System.SystemException e)
            {
                // pass
            }
        }
예제 #11
0
		public virtual void  TestNotInitialized()
		{
			NumericTokenStream stream = new NumericTokenStream();
			
			try
			{
				stream.Reset();
				Assert.Fail("reset() should not succeed.");
			}
			catch (System.SystemException e)
			{
				// pass
			}
			
			try
			{
				stream.IncrementToken();
				Assert.Fail("incrementToken() should not succeed.");
			}
			catch (System.SystemException e)
			{
				// pass
			}
		}