public void GetSetBits() { BitArray array = new BitArray(false, 15); for (int x = 0; x < 15; x++) { if (array[x]) { throw new Exception(); } } for (int x = 0; x < 15; x++) { if (array.GetBitUnchecked(x)) { throw new Exception(); } } array[1] = true; if (array.TrySetBit(1)) { throw new Exception(); } if (!array.TrySetBit(2)) { throw new Exception(); } if (array.TrySetBit(2)) { throw new Exception(); } if (!array.TryClearBit(2)) { throw new Exception(); } if (array.TryClearBit(2)) { throw new Exception(); } //Here, bit 1 is set. if (!array.AreAllBitsSet(1, 1)) { throw new Exception(); } if (array.AreAllBitsSet(1, 3)) { throw new Exception(); } if (!array.AreAllBitsCleared(2, 8)) { throw new Exception(); } if (array.AreAllBitsCleared(0, 8)) { throw new Exception(); } array.SetBits(1, 8); if (!array.AreAllBitsSet(1, 8)) { throw new Exception(); } array.ClearBits(1, 8); if (!array.AreAllBitsCleared(1, 8)) { throw new Exception(); } array.EnsureCapacity(62); if (!array.AreAllBitsCleared(1, 8)) { throw new Exception(); } array.EnsureCapacity(1000); if (!array.AreAllBitsCleared(62, 500)) { throw new Exception(); } }
public void GetSetBits() { BitArray array = new BitArray(false, 15); for (int x = 0; x < 15; x++) { if (array[x]) throw new Exception(); } for (int x = 0; x < 15; x++) { if (array.GetBitUnchecked(x)) throw new Exception(); } array[1] = true; if(array.TrySetBit(1)) throw new Exception(); if (!array.TrySetBit(2)) throw new Exception(); if (array.TrySetBit(2)) throw new Exception(); if (!array.TryClearBit(2)) throw new Exception(); if (array.TryClearBit(2)) throw new Exception(); //Here, bit 1 is set. if (!array.AreAllBitsSet(1,1)) throw new Exception(); if (array.AreAllBitsSet(1,3)) throw new Exception(); if (!array.AreAllBitsCleared(2,8)) throw new Exception(); if (array.AreAllBitsCleared(0, 8)) throw new Exception(); array.SetBits(1,8); if (!array.AreAllBitsSet(1,8)) throw new Exception(); array.ClearBits(1, 8); if (!array.AreAllBitsCleared(1, 8)) throw new Exception(); array.EnsureCapacity(62); if (!array.AreAllBitsCleared(1, 8)) throw new Exception(); array.EnsureCapacity(1000); if (!array.AreAllBitsCleared(62, 500)) throw new Exception(); }