public void TestBitCompactorIndexerSingleByteSuccess() { BitCompactor Compactor = new BitCompactor(true, false); Assert.IsTrue(Compactor[0]); Assert.IsFalse(Compactor[1]); Assert.IsFalse(Compactor[2]); // Not defined case }
public void TestBitCompactorConstructorFromFourBitsSuccess() { BitCompactor Compactor = new BitCompactor(true, false, true, true); Assert.IsNotNull(Compactor); Assert.IsNotNull(Compactor.Value); Assert.AreEqual(1, Compactor.Value.Length); Assert.AreEqual(0x0D, Compactor.Value[0]); }
/// <summary> /// Read a <see cref="BitCompactor"/> instance from a <see cref="BinaryWriter"/> instance. /// </summary> /// <param name="reader"><see cref="BinaryWriter"/> instance.</param> /// <param name="numberOfBits">Number of bits stored.</param> /// <returns><see cref="BitCompactor"/> instance.</returns> public static BitCompactor ReadBitCompactor(this BinaryReader reader, int numberOfBits) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (numberOfBits < 1) { throw new ArgumentOutOfRangeException(nameof(numberOfBits)); } return(new BitCompactor(reader.ReadBytes(BitCompactor.CalculateBytesNeededToStoreBits(numberOfBits)))); }
/// <summary> /// Write a <see cref="BitCompactor"/> instance to a <see cref="BinaryWriter"/> instance. /// </summary> /// <param name="writer"><see cref="BinaryWriter"/> instance.</param> /// <param name="bitCompactor"><see cref="BitCompactor"/> instance.</param> public static void Write(this BinaryWriter writer, BitCompactor bitCompactor) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (bitCompactor == null) { throw new ArgumentNullException(nameof(bitCompactor)); } writer.Write(bitCompactor.Value); }
public void TestBitCompactorIndexerMultipleByteSuccess() { BitCompactor Compactor = new BitCompactor( new bool[] { true, false, true, true, // 1101 = D true, true, false, true, // 1011 = B true // 0001 = 1 }); Assert.IsTrue(Compactor[0]); Assert.IsFalse(Compactor[1]); Assert.IsTrue(Compactor[7]); Assert.IsTrue(Compactor[8]); }
public void TestBitCompactorConstructorFromNineBitsSuccess() { BitCompactor Compactor = new BitCompactor( new bool[] { true, false, true, true, // 1101 = D true, true, false, true, // 1011 = B true // 0001 = 1 }); Assert.IsNotNull(Compactor); Assert.IsNotNull(Compactor.Value); Assert.AreEqual(2, Compactor.Value.Length); Assert.AreEqual(0xBD, Compactor.Value[0]); Assert.AreEqual(0x01, Compactor.Value[1]); }
public void TestBitCompactorConstructorToBitsSuccess() { BitCompactor Compactor = new BitCompactor(0xBD, 0x01); Assert.IsNotNull(Compactor); Assert.IsNotNull(Compactor.Value); Assert.AreEqual(2, Compactor.Value.Length); bool[] Bits = Compactor.ToBits(); Assert.IsNotNull(Bits); Assert.AreEqual(16, Bits.Length); Assert.IsTrue( Bits .SequenceEqual( new bool[] { true, false, true, true, // 1101 = D true, true, false, true, // 1011 = B true, false, false, false, // 0001 = 1 false, false, false, false // 0000 = 0 })); }