public virtual void TestEquals() { // this test can't handle numBits==0: int numBits = Random().Next(2000) + 1; Int64BitSet b1 = new Int64BitSet(numBits); Int64BitSet b2 = new Int64BitSet(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())); }
public void TestClearSmall() { Int64BitSet a = new Int64BitSet(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]); } Int64BitSet b = new Int64BitSet(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)); }
public void TestClearLarge() { int iters = AtLeast(1000); for (int it = 0; it < iters; it++) { Random random = new Random(); int sz = AtLeast(1200); Int64BitSet a = new Int64BitSet(sz); Int64BitSet b = new Int64BitSet(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)); } }
public virtual void TestHashCodeEquals() { // this test can't handle numBits==0: int numBits = Random().Next(2000) + 1; Int64BitSet b1 = new Int64BitSet(numBits); Int64BitSet b2 = new Int64BitSet(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()); } } }
public virtual void TestSmallBitSets() { // Make sure size 0-10 bit sets are OK: for (int numBits = 0; numBits < 10; numBits++) { Int64BitSet b1 = new Int64BitSet(numBits); Int64BitSet b2 = new Int64BitSet(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()); } } }