Exemplo n.º 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();
        }
Exemplo n.º 2
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");
 }
Exemplo n.º 3
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");
        }
        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.");
        }
Exemplo n.º 5
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.");
        }
Exemplo n.º 6
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
            }
        }
Exemplo n.º 7
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
            }
        }
Exemplo n.º 8
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
			}
		}