public void ClearBit(int size, int bit) { var mask = new LogLevelBitMask(size, true, false); // check the actual size of the mask in bits int effectiveSize = (size + 31) & ~31; Assert.Equal(effectiveSize, mask.Size); // clear bit mask.ClearBit(bit); // check underlying buffer uint[] maskArray = mask.AsArray(); int clearedBitArrayIndex = bit / 32; int clearedBitIndex = bit % 32; uint[] expectedMaskArray = new uint[effectiveSize / 32]; for (int i = 0; i < expectedMaskArray.Length; i++) { if (i == clearedBitArrayIndex) { expectedMaskArray[i] = ~0u & ~(1u << clearedBitIndex); } else { expectedMaskArray[i] = ~0u; } } Assert.Equal(expectedMaskArray, maskArray); }
[InlineData(128, 1, 126, new uint[] { 0x00000001u, 0x00000000u, 0x00000000u, 0x80000000u })] // all bits except the first and the last one public void ClearBits( int size, int fromBit, int count, uint[] expectedMaskArray) { var mask = new LogLevelBitMask(size, true, false); // check the actual size of the mask in bits int effectiveSize = (size + 31) & ~31; Assert.Equal(effectiveSize, mask.Size); // clear bit mask.ClearBits(fromBit, count); // check underlying buffer uint[] maskArray = mask.AsArray(); Assert.Equal(expectedMaskArray, maskArray); }
public void Create(int size, bool initialBitValue, bool paddingValue) { var mask = new LogLevelBitMask(size, initialBitValue, paddingValue); // check the actual size of the mask in bits int effectiveSize = (size + 31) & ~31; Assert.Equal(effectiveSize, mask.Size); // check padding value Assert.Equal(paddingValue, mask.PaddingValue); // check underlying buffer uint[] maskArray = mask.AsArray(); uint[] expectedMaskArray = new uint[effectiveSize / 32]; for (int i = 0; i < expectedMaskArray.Length; i++) { expectedMaskArray[i] = initialBitValue ? ~0u : 0u; } Assert.Equal(expectedMaskArray, maskArray); }