Equals() public method

returns true if both sets have the same bits set
public Equals ( object o ) : bool
o object
return bool
コード例 #1
0
        public virtual void TestEquals()
        {
            // this test can't handle numBits==0:
            int        numBits = Random().Next(2000) + 1;
            LongBitSet b1      = new LongBitSet(numBits);
            LongBitSet b2      = new LongBitSet(numBits);

            Assert.IsTrue(b1.Equals(b2));
            Assert.IsTrue(b2.Equals(b1));
            for (int iter = 0; iter < 10 * RANDOM_MULTIPLIER; iter++)
            {
                int idx = Random().Next(numBits);
                if (!b1.Get(idx))
                {
                    b1.Set(idx);
                    Assert.IsFalse(b1.Equals(b2));
                    Assert.IsFalse(b2.Equals(b1));
                    b2.Set(idx);
                    Assert.IsTrue(b1.Equals(b2));
                    Assert.IsTrue(b2.Equals(b1));
                }
            }

            // try different type of object
            Assert.IsFalse(b1.Equals(new object()));
        }
コード例 #2
0
        public void TestClearSmall()
        {
            LongBitSet a = new LongBitSet(30);   // 0110010111001000101101001001110...0

            int[] onesA = { 1, 2, 5, 7, 8, 9, 12, 16, 18, 19, 21, 24, 27, 28, 29 };

            for (int i = 0; i < onesA.size(); i++)
            {
                a.Set(onesA[i]);
            }

            LongBitSet b = new LongBitSet(30);   // 0110000001001000101101001001110...0

            int[] onesB = { 1, 2, 9, 12, 16, 18, 19, 21, 24, 27, 28, 29 };

            for (int i = 0; i < onesB.size(); i++)
            {
                b.Set(onesB[i]);
            }

            a.Clear(5, 9);
            Assert.True(a.Equals(b));

            a.Clear(9, 10);
            Assert.False(a.Equals(b));

            a.Set(9);
            Assert.True(a.Equals(b));
        }
コード例 #3
0
ファイル: TestLongBitSet.cs プロジェクト: Cefa68000/lucenenet
        public void TestClearSmall()
        {
            LongBitSet a = new LongBitSet(30);   // 0110010111001000101101001001110...0
            int[] onesA = { 1, 2, 5, 7, 8, 9, 12, 16, 18, 19, 21, 24, 27, 28, 29 };

            for (int i = 0; i < onesA.size(); i++)
            {
                a.Set(onesA[i]);
            }

            LongBitSet b = new LongBitSet(30);   // 0110000001001000101101001001110...0
            int[] onesB = { 1, 2, 9, 12, 16, 18, 19, 21, 24, 27, 28, 29 };

            for (int i = 0; i < onesB.size(); i++)
            {
                b.Set(onesB[i]);
            }

            a.Clear(5, 9);
            Assert.True(a.Equals(b));

            a.Clear(9, 10);
            Assert.False(a.Equals(b));

            a.Set(9);
            Assert.True(a.Equals(b));
        }
コード例 #4
0
ファイル: TestLongBitSet.cs プロジェクト: Cefa68000/lucenenet
        public void TestClearLarge()
        {
            int iters = AtLeast(1000);
            for (int it = 0; it < iters; it++)
            {
                Random random = new Random();
                int sz = AtLeast(1200);
                LongBitSet a = new LongBitSet(sz);
                LongBitSet b = new LongBitSet(sz);
                int from = random.Next(sz - 1);
                int to = random.Next(from, sz);

                for (int i = 0; i < sz / 2; i++)
                {
                    int index = random.Next(sz - 1);
                    a.Set(index);

                    if (index < from || index >= to)
                    {
                        b.Set(index);
                    }
                }

                a.Clear(from, to);
                Assert.True(a.Equals(b));
            }
        }
コード例 #5
0
        public void TestClearLarge()
        {
            int iters = AtLeast(1000);

            for (int it = 0; it < iters; it++)
            {
                Random     random = new Random();
                int        sz     = AtLeast(1200);
                LongBitSet a      = new LongBitSet(sz);
                LongBitSet b      = new LongBitSet(sz);
                int        from   = random.Next(sz - 1);
                int        to     = random.Next(from, sz);

                for (int i = 0; i < sz / 2; i++)
                {
                    int index = random.Next(sz - 1);
                    a.Set(index);

                    if (index < from || index >= to)
                    {
                        b.Set(index);
                    }
                }

                a.Clear(from, to);
                Assert.True(a.Equals(b));
            }
        }
コード例 #6
0
        public virtual void TestHashCodeEquals()
        {
            // this test can't handle numBits==0:
            int        numBits = Random().Next(2000) + 1;
            LongBitSet b1      = new LongBitSet(numBits);
            LongBitSet b2      = new LongBitSet(numBits);

            Assert.IsTrue(b1.Equals(b2));
            Assert.IsTrue(b2.Equals(b1));
            for (int iter = 0; iter < 10 * RANDOM_MULTIPLIER; iter++)
            {
                int idx = Random().Next(numBits);
                if (!b1.Get(idx))
                {
                    b1.Set(idx);
                    Assert.IsFalse(b1.Equals(b2));
                    Assert.IsFalse(b1.GetHashCode() == b2.GetHashCode());
                    b2.Set(idx);
                    Assert.AreEqual(b1, b2);
                    Assert.AreEqual(b1.GetHashCode(), b2.GetHashCode());
                }
            }
        }
コード例 #7
0
 public virtual void TestSmallBitSets()
 {
     // Make sure size 0-10 bit sets are OK:
     for (int numBits = 0; numBits < 10; numBits++)
     {
         LongBitSet b1 = new LongBitSet(numBits);
         LongBitSet b2 = new LongBitSet(numBits);
         Assert.IsTrue(b1.Equals(b2));
         Assert.AreEqual(b1.GetHashCode(), b2.GetHashCode());
         Assert.AreEqual(0, b1.Cardinality());
         if (numBits > 0)
         {
             b1.Set(0, numBits);
             Assert.AreEqual(numBits, b1.Cardinality());
             b1.Flip(0, numBits);
             Assert.AreEqual(0, b1.Cardinality());
         }
     }
 }
コード例 #8
0
 public virtual void TestSmallBitSets()
 {
     // Make sure size 0-10 bit sets are OK:
     for (int numBits = 0; numBits < 10; numBits++)
     {
         LongBitSet b1 = new LongBitSet(numBits);
         LongBitSet b2 = new LongBitSet(numBits);
         Assert.IsTrue(b1.Equals(b2));
         Assert.AreEqual(b1.GetHashCode(), b2.GetHashCode());
         Assert.AreEqual(0, b1.Cardinality());
         if (numBits > 0)
         {
             b1.Set(0, numBits);
             Assert.AreEqual(numBits, b1.Cardinality());
             b1.Flip(0, numBits);
             Assert.AreEqual(0, b1.Cardinality());
         }
     }
 }
コード例 #9
0
 public virtual void TestHashCodeEquals()
 {
     // this test can't handle numBits==0:
     int numBits = Random().Next(2000) + 1;
     LongBitSet b1 = new LongBitSet(numBits);
     LongBitSet b2 = new LongBitSet(numBits);
     Assert.IsTrue(b1.Equals(b2));
     Assert.IsTrue(b2.Equals(b1));
     for (int iter = 0; iter < 10 * RANDOM_MULTIPLIER; iter++)
     {
         int idx = Random().Next(numBits);
         if (!b1.Get(idx))
         {
             b1.Set(idx);
             Assert.IsFalse(b1.Equals(b2));
             Assert.IsFalse(b1.GetHashCode() == b2.GetHashCode());
             b2.Set(idx);
             Assert.AreEqual(b1, b2);
             Assert.AreEqual(b1.GetHashCode(), b2.GetHashCode());
         }
     }
 }
コード例 #10
0
        public virtual void TestEquals()
        {
            // this test can't handle numBits==0:
            int numBits = Random().Next(2000) + 1;
            LongBitSet b1 = new LongBitSet(numBits);
            LongBitSet b2 = new LongBitSet(numBits);
            Assert.IsTrue(b1.Equals(b2));
            Assert.IsTrue(b2.Equals(b1));
            for (int iter = 0; iter < 10 * RANDOM_MULTIPLIER; iter++)
            {
                int idx = Random().Next(numBits);
                if (!b1.Get(idx))
                {
                    b1.Set(idx);
                    Assert.IsFalse(b1.Equals(b2));
                    Assert.IsFalse(b2.Equals(b1));
                    b2.Set(idx);
                    Assert.IsTrue(b1.Equals(b2));
                    Assert.IsTrue(b2.Equals(b1));
                }
            }

            // try different type of object
            Assert.IsFalse(b1.Equals(new object()));
        }