Esempio n. 1
0
        private void  DoTestDgaps(int size, int count1, int count2)
        {
            Directory d  = new RAMDirectory();
            BitVector bv = new BitVector(size);

            for (int i = 0; i < count1; i++)
            {
                bv.Set(i);
                Assert.AreEqual(i + 1, bv.Count());
            }
            bv.Write(d, "TESTBV", null);
            // gradually increase number of set bits
            for (int i = count1; i < count2; i++)
            {
                BitVector bv2 = new BitVector(d, "TESTBV", null);
                Assert.IsTrue(DoCompare(bv, bv2));
                bv = bv2;
                bv.Set(i);
                Assert.AreEqual(i + 1, bv.Count());
                bv.Write(d, "TESTBV", null);
            }
            // now start decreasing number of set bits
            for (int i = count2 - 1; i >= count1; i--)
            {
                BitVector bv2 = new BitVector(d, "TESTBV", null);
                Assert.IsTrue(DoCompare(bv, bv2));
                bv = bv2;
                bv.Clear(i);
                Assert.AreEqual(i, bv.Count());
                bv.Write(d, "TESTBV", null);
            }
        }
Esempio n. 2
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());
            }
        }
Esempio n. 3
0
        private void  DoTestWriteRead(int n)
        {
            Directory d = new RAMDirectory();

            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", null);
                BitVector compare = new BitVector(d, "TESTBV", null);
                // compare bit vectors with bits set incrementally
                Assert.IsTrue(DoCompare(bv, compare));
            }
        }
Esempio n. 4
0
        /// <summary> Compare a subset against the corresponding portion of the test pattern</summary>
        private void  DoTestSubset(int start, int end)
        {
            BitVector full   = CreateSubsetTestVector();
            BitVector subset = full.Subset(start, end);

            Assert.AreEqual(end - start, subset.Size());
            int count = 0;

            for (int i = start, j = 0; i < end; i++, j++)
            {
                if (subsetPattern[i] == 1)
                {
                    count++;
                    Assert.IsTrue(subset.Get(j));
                }
                else
                {
                    Assert.IsFalse(subset.Get(j));
                }
            }
            Assert.AreEqual(count, subset.Count());
        }
Esempio n. 5
0
		private void  DoTestDgaps(int size, int count1, int count2)
		{
			Directory d = new RAMDirectory();
			BitVector bv = new BitVector(size);
			for (int i = 0; i < count1; i++)
			{
				bv.Set(i);
				Assert.AreEqual(i + 1, bv.Count());
			}
			bv.Write(d, "TESTBV");
			// gradually increase number of set bits
			for (int i = count1; i < count2; i++)
			{
				BitVector bv2 = new BitVector(d, "TESTBV");
				Assert.IsTrue(DoCompare(bv, bv2));
				bv = bv2;
				bv.Set(i);
				Assert.AreEqual(i + 1, bv.Count());
				bv.Write(d, "TESTBV");
			}
			// now start decreasing number of set bits
			for (int i = count2 - 1; i >= count1; i--)
			{
				BitVector bv2 = new BitVector(d, "TESTBV");
				Assert.IsTrue(DoCompare(bv, bv2));
				bv = bv2;
				bv.Clear(i);
				Assert.AreEqual(i, bv.Count());
				bv.Write(d, "TESTBV");
			}
		}
Esempio n. 6
0
		private void  DoTestWriteRead(int n)
		{
			Directory d = new RAMDirectory();
			
			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");
				BitVector compare = new BitVector(d, "TESTBV");
				// compare bit vectors with bits set incrementally
				Assert.IsTrue(DoCompare(bv, compare));
			}
		}
Esempio n. 7
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());
			}
		}