GetHashCode() публичный Метод

public GetHashCode ( ) : int
Результат int
Пример #1
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());
                }
            }
        }
Пример #2
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());
         }
     }
 }
Пример #3
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());
         }
     }
 }
Пример #4
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());
         }
     }
 }