Пример #1
0
        private void DoTestCountVectorOfSize(int n)
        {
            BitVector bv = new BitVector(n);

            // test count when incrementally setting bits
            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
            {
                Assert.IsFalse(bv.Get(i));
                Assert.AreEqual(i, bv.Count());
                bv.Set(i);
                Assert.IsTrue(bv.Get(i));
                Assert.AreEqual(i + 1, bv.Count());
            }

            bv = new BitVector(n);
            // test count when setting then clearing bits
            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
            {
                Assert.IsFalse(bv.Get(i));
                Assert.AreEqual(0, bv.Count());
                bv.Set(i);
                Assert.IsTrue(bv.Get(i));
                Assert.AreEqual(1, bv.Count());
                bv.Clear(i);
                Assert.IsFalse(bv.Get(i));
                Assert.AreEqual(0, bv.Count());
            }
        }
Пример #2
0
        private void DoTestGetSetVectorOfSize(int n)
        {
            BitVector bv = new BitVector(n);

            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
            {
                // ensure a set bit can be git'
                Assert.IsFalse(bv.Get(i));
                bv.Set(i);
                Assert.IsTrue(bv.Get(i));
            }
        }
Пример #3
0
        private void DoTestGetSetVectorOfSize(int n)
        {
            BitVector bv = new BitVector(n);

            for (int i = 0; i < bv.Size(); i++)
            {
                // ensure a set bit can be git'
                Assert.IsFalse(bv.Get(i));
                bv.Set(i);
                Assert.IsTrue(bv.Get(i));
            }
        }
Пример #4
0
        private void DoTestClearVectorOfSize(int n)
        {
            BitVector bv = new BitVector(n);

            for (int i = 0; i < bv.Size(); i++)
            {
                // ensure a set bit is cleared
                Assert.IsFalse(bv.Get(i));
                bv.Set(i);
                Assert.IsTrue(bv.Get(i));
                bv.Clear(i);
                Assert.IsFalse(bv.Get(i));
            }
        }
Пример #5
0
        public virtual void TestMostlySet()
        {
            Directory d       = NewDirectory();
            int       numBits = TestUtil.NextInt32(Random, 30, 1000);

            for (int numClear = 0; numClear < 20; numClear++)
            {
                BitVector bv = new BitVector(numBits);
                bv.InvertAll();
                int count = 0;
                while (count < numClear)
                {
                    int bit = Random.Next(numBits);
                    // Don't use getAndClear, so that count is recomputed
                    if (bv.Get(bit))
                    {
                        bv.Clear(bit);
                        count++;
                        Assert.AreEqual(numBits - count, bv.Count());
                    }
                }
            }

            d.Dispose();
        }
Пример #6
0
        private void DoTestWriteRead(int n)
        {
            MockDirectoryWrapper d = new MockDirectoryWrapper(Random, new RAMDirectory());

            d.PreventDoubleWrite = false;
            BitVector bv = new BitVector(n);

            // test count when incrementally setting bits
            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
            {
                Assert.IsFalse(bv.Get(i));
                Assert.AreEqual(i, bv.Count());
                bv.Set(i);
                Assert.IsTrue(bv.Get(i));
                Assert.AreEqual(i + 1, bv.Count());
                bv.Write(d, "TESTBV", NewIOContext(Random));
                BitVector compare = new BitVector(d, "TESTBV", NewIOContext(Random));
                // compare bit vectors with bits set incrementally
                Assert.IsTrue(DoCompare(bv, compare));
            }
        }
Пример #7
0
        /// <summary>
        /// Compare two BitVectors.
        /// this should really be an equals method on the BitVector itself. </summary>
        /// <param name="bv"> One bit vector </param>
        /// <param name="compare"> The second to compare </param>
        private bool DoCompare(BitVector bv, BitVector compare)
        {
            bool equal = true;

            for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
            {
                // bits must be equal
                if (bv.Get(i) != compare.Get(i))
                {
                    equal = false;
                    break;
                }
            }
            Assert.AreEqual(bv.Count(), compare.Count());
            return(equal);
        }
Пример #8
0
        /// <summary>
        /// Compare two BitVectors.
        /// this should really be an equals method on the BitVector itself. </summary>
        /// <param name="bv"> One bit vector </param>
        /// <param name="compare"> The second to compare </param>
        private bool DoCompare(BitVector bv, BitVector compare)
        {
            bool equal = true;

            for (int i = 0; i < bv.Size(); i++)
            {
                // bits must be equal
                if (bv.Get(i) != compare.Get(i))
                {
                    equal = false;
                    break;
                }
            }
            Assert.AreEqual(bv.Count(), compare.Count());
            return(equal);
        }
Пример #9
0
 private void DoTestWriteRead(int n)
 {
     MockDirectoryWrapper d = new MockDirectoryWrapper(Random(), new RAMDirectory());
     d.PreventDoubleWrite = false;
     BitVector bv = new BitVector(n);
     // test count when incrementally setting bits
     for (int i = 0; i < bv.Size(); i++)
     {
         Assert.IsFalse(bv.Get(i));
         Assert.AreEqual(i, bv.Count());
         bv.Set(i);
         Assert.IsTrue(bv.Get(i));
         Assert.AreEqual(i + 1, bv.Count());
         bv.Write(d, "TESTBV", NewIOContext(Random()));
         BitVector compare = new BitVector(d, "TESTBV", NewIOContext(Random()));
         // compare bit vectors with bits set incrementally
         Assert.IsTrue(DoCompare(bv, compare));
     }
 }
Пример #10
0
 private void DoTestGetSetVectorOfSize(int n)
 {
     BitVector bv = new BitVector(n);
     for (int i = 0; i < bv.Size(); i++)
     {
         // ensure a set bit can be git'
         Assert.IsFalse(bv.Get(i));
         bv.Set(i);
         Assert.IsTrue(bv.Get(i));
     }
 }
Пример #11
0
        private void DoTestCountVectorOfSize(int n)
        {
            BitVector bv = new BitVector(n);
            // test count when incrementally setting bits
            for (int i = 0; i < bv.Size(); i++)
            {
                Assert.IsFalse(bv.Get(i));
                Assert.AreEqual(i, bv.Count());
                bv.Set(i);
                Assert.IsTrue(bv.Get(i));
                Assert.AreEqual(i + 1, bv.Count());
            }

            bv = new BitVector(n);
            // test count when setting then clearing bits
            for (int i = 0; i < bv.Size(); i++)
            {
                Assert.IsFalse(bv.Get(i));
                Assert.AreEqual(0, bv.Count());
                bv.Set(i);
                Assert.IsTrue(bv.Get(i));
                Assert.AreEqual(1, bv.Count());
                bv.Clear(i);
                Assert.IsFalse(bv.Get(i));
                Assert.AreEqual(0, bv.Count());
            }
        }
Пример #12
0
 private void DoTestClearVectorOfSize(int n)
 {
     BitVector bv = new BitVector(n);
     for (int i = 0; i < bv.Size(); i++)
     {
         // ensure a set bit is cleared
         Assert.IsFalse(bv.Get(i));
         bv.Set(i);
         Assert.IsTrue(bv.Get(i));
         bv.Clear(i);
         Assert.IsFalse(bv.Get(i));
     }
 }
Пример #13
0
 /// <summary>
 /// Compare two BitVectors.
 /// this should really be an equals method on the BitVector itself. </summary>
 /// <param name="bv"> One bit vector </param>
 /// <param name="compare"> The second to compare </param>
 private bool DoCompare(BitVector bv, BitVector compare)
 {
     bool equal = true;
     for (int i = 0; i < bv.Size(); i++)
     {
         // bits must be equal
         if (bv.Get(i) != compare.Get(i))
         {
             equal = false;
             break;
         }
     }
     Assert.AreEqual(bv.Count(), compare.Count());
     return equal;
 }
Пример #14
0
        public virtual void TestMostlySet()
        {
            Directory d = NewDirectory();
            int numBits = TestUtil.NextInt(Random(), 30, 1000);
            for (int numClear = 0; numClear < 20; numClear++)
            {
                BitVector bv = new BitVector(numBits);
                bv.InvertAll();
                int count = 0;
                while (count < numClear)
                {
                    int bit = Random().Next(numBits);
                    // Don't use getAndClear, so that count is recomputed
                    if (bv.Get(bit))
                    {
                        bv.Clear(bit);
                        count++;
                        Assert.AreEqual(numBits - count, bv.Count());
                    }
                }
            }

            d.Dispose();
        }