public void FindBits() { BitArray arraySet = new BitArray(true, 15); BitArray arrayClear = new BitArray(false, 15); if (arraySet.FindClearedBit() != -1) { throw new Exception(); } if (arrayClear.FindSetBit() != -1) { throw new Exception(); } int count = 0; foreach (int set in arraySet.GetAllSetBits()) { if (set != count) { throw new Exception(); } count++; } count = 0; foreach (int set in arrayClear.GetAllClearedBits()) { if (set != count) { throw new Exception(); } count++; } if (arrayClear.GetAllSetBits().Count() != 0) { throw new Exception(); } if (arraySet.GetAllClearedBits().Count() != 0) { throw new Exception(); } arraySet.EnsureCapacity(300); if (!arraySet.AreAllBitsSet(62, 200)) { throw new Exception(); } if (arraySet.ClearCount != 0) { 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(); } }
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 FindBits() { BitArray arraySet = new BitArray(true, 15); BitArray arrayClear = new BitArray(false, 15); if (arraySet.FindClearedBit() != -1) throw new Exception(); if (arrayClear.FindSetBit() != -1) throw new Exception(); int count = 0; foreach (var set in arraySet.GetAllSetBits()) { if (set != count) throw new Exception(); count++; } count = 0; foreach (var set in arrayClear.GetAllClearedBits()) { if (set != count) throw new Exception(); count++; } if (arrayClear.GetAllSetBits().Count() != 0) throw new Exception(); if (arraySet.GetAllClearedBits().Count() != 0) throw new Exception(); arraySet.EnsureCapacity(300); if (!arraySet.AreAllBitsSet(62, 200)) throw new Exception(); if (arraySet.ClearCount != 0) throw new Exception(); }