public void TestClearBit() { Assert.AreEqual(zero, zero.ClearBit(0)); Assert.AreEqual(zero, one.ClearBit(0)); Assert.AreEqual(two, two.ClearBit(0)); Assert.AreEqual(zero, zero.ClearBit(1)); Assert.AreEqual(one, one.ClearBit(1)); Assert.AreEqual(zero, two.ClearBit(1)); // TODO Tests for clearing bits in negative numbers // TODO Tests for clearing extended bits for (int i = 0; i < 10; ++i) { IBigInteger n = new BigInteger(128, _random); for (int j = 0; j < 10; ++j) { int pos = _random.Next(128); IBigInteger m = n.ClearBit(pos); bool test = m.ShiftRight(pos).Remainder(two).Equals(one); Assert.IsFalse(test); } } for (int i = 0; i < 100; ++i) { IBigInteger pow2 = one.ShiftLeft(i); IBigInteger minusPow2 = pow2.Negate(); Assert.AreEqual(zero, pow2.ClearBit(i)); Assert.AreEqual(minusPow2.ShiftLeft(1), minusPow2.ClearBit(i)); IBigInteger bigI = BigInteger.ValueOf(i); IBigInteger negI = bigI.Negate(); for (int j = 0; j < 10; ++j) { string data = "i=" + i + ", j=" + j; Assert.AreEqual(bigI.AndNot(one.ShiftLeft(j)), bigI.ClearBit(j), data); Assert.AreEqual(negI.AndNot(one.ShiftLeft(j)), negI.ClearBit(j), data); } } }