Пример #1
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());
            }
        }
Пример #2
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));
            }
        }
Пример #3
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));
            }
        }
Пример #4
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);
        }
Пример #5
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));
            }
        }
Пример #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.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));
     }
 }
Пример #7
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));
     }
 }
Пример #8
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());
            }
        }
Пример #9
0
 private void DoTestConstructOfSize(int n)
 {
     BitVector bv = new BitVector(n);
     Assert.AreEqual(n, bv.Size());
 }
Пример #10
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));
     }
 }
Пример #11
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;
 }
Пример #12
0
        private void DoTestConstructOfSize(int n)
        {
            BitVector bv = new BitVector(n);

            Assert.AreEqual(n, bv.Size());
        }