public void SetBytes_UInt64OverloadOnlyValueInstanceIsNull_ThrowsArgumentNullException() { IBitCharger instance = null; UInt64 value = 42; Assert.That(() => instance.SetBytes(value), Throws.ArgumentNullException); }
/// <summary> /// Sets the bits of <paramref name="value"/> into the /// <paramref name="charger"/> at offset zero. /// </summary> /// <remarks> /// This method sets all bits of <paramref name="value"/> /// into the <paramref name="charger"/> at offset zero. /// </remarks> /// <param name="charger"> /// An instance of <see cref="IBitCharger"/> to set the bits /// into. /// </param> /// <param name="value"> /// The bits to set. /// </param> /// <param name="offset"> /// The byte index to start with changing the bits. /// </param> public static void SetBytes(this IBitCharger charger, UInt64 value, Int32 offset) { charger.ValidateInstance(); Byte[] array = BitConverter.GetBytes(value); charger.SetBytes(array, offset); }
/// <summary> /// Sets the bits of <paramref name="value"/> into the /// <paramref name="charger"/> at offset zero. /// </summary> /// <remarks> /// This method sets all bits of <paramref name="value"/> /// into the <paramref name="charger"/> at offset zero. /// </remarks> /// <param name="charger"> /// An instance of <see cref="IBitCharger"/> to set the bits /// into. /// </param> /// <param name="value"> /// The bits to set. /// </param> /// <param name="offset"> /// The byte index to start with changing the bits. /// </param> public static void SetBytes(this IBitCharger charger, SByte value, Int32 offset) { charger.ValidateInstance(); Byte[] array = new Byte[] { (Byte)value }; charger.SetBytes(array, offset); }
public void SetBytes_UInt64OverloadValueAndLengthInstanceIsNull_ThrowsArgumentNullException() { IBitCharger instance = null; UInt64 value = 42; Int32 offset = 42; Assert.That(() => instance.SetBytes(value, offset), Throws.ArgumentNullException); }
public void ToUInt32_OnlyValue_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); UInt32 expected = 47110815; // LE: 0x9FDACE02 => 10011111 11011010 11001110 00000010 Byte[] array = new Byte[] { 0x9F, 0xDA, 0xCE, 0x02 }; instance.SetBytes(array); Assert.That(instance.ToUInt32(), Is.EqualTo(expected)); }
public void ToUInt64_OnlyValue_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); UInt64 expected = 3026418949640084127; // LE: 0x9FDACE020000002A => 10011111 11011010 11001110 00000010 00000000 00000000 00000000 00101010 Byte[] array = new Byte[] { 0x9F, 0xDA, 0xCE, 0x02, 0x00, 0x00, 0x00, 0x2A }; instance.SetBytes(array); Assert.That(instance.ToUInt64(), Is.EqualTo(expected)); }
public void ToByte_OnlyValue_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); Byte expected = 42; // LE: 0x2A => 00101010 Byte[] array = new Byte[] { 0x2A }; instance.SetBytes(array); Assert.That(instance.ToByte(), Is.EqualTo(expected)); }
public void ToUInt16_OnlyValue_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); UInt16 expected = 4711; // LE: 0x6712 => 01100111 00010010 Byte[] array = new Byte[] { 0x67, 0x12 }; instance.SetBytes(array); Assert.That(instance.ToUInt16(), Is.EqualTo(expected)); }
public void SetBytes_UInt16OverloadOnlyValue_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); UInt16 value = 4711; // LE: 0x6712 => 01100111 00010010 String expected = "0110011100010010"; instance.SetBytes(value); Assert.That(instance.Content, Is.EqualTo(expected)); }
public void SetBytes_UInt64OverloadOnlyValue_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); UInt64 value = 47110815; // LE: 0x9FDACE0200000000 => 10011111 11011010 11001110 00000010 00000000 00000000 00000000 00000000 String expected = "1001111111011010110011100000001000000000000000000000000000000000"; instance.SetBytes(value); Assert.That(instance.Content, Is.EqualTo(expected)); }
public void SetBytes_SByteOverloadOnlyValue_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); SByte value = 42; // LE: 0x2A => 00101010 String expected = "00101010"; instance.SetBytes(value); Assert.That(instance.Content, Is.EqualTo(expected)); }
public void ToInt64_ValueAndOffset_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); Int64 expected = 3026418949640084127; // LE: 0x9FDACE020000002A => 10011111 11011010 11001110 00000010 00000000 00000000 00000000 00101010 Int32 offset = 2; Byte[] array = new Byte[] { 0x9F, 0xDA, 0xCE, 0x02, 0x00, 0x00, 0x00, 0x2A }; instance.SetBytes(array, offset); Assert.That(instance.ToInt64(offset), Is.EqualTo(expected)); }
public void SetBytes_Int64OverloadValueAndOffset_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); Int64 value = 47110815; // LE: 0x9FDACE0200000000 => 10011111 11011010 11001110 00000010 00000000 00000000 00000000 00000000 Int32 offset = 2; String expected = "10011111110110101100111000000010000000000000000000000000000000000000000000000000"; instance.SetBytes(value, offset); Assert.That(instance.Content, Is.EqualTo(expected)); }
public void SetBytes_SByteOverloadValueAndOffset_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); SByte value = 42; // LE: 0x2A => 00101010 Int32 offset = 2; String expected = "001010100000000000000000"; instance.SetBytes(value, offset); Assert.That(instance.Content, Is.EqualTo(expected)); }
public void ToInt32_ValueAndOffset_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); Int32 expected = 47110815; // LE: 0x9FDACE02 => 10011111 11011010 11001110 00000010 Int32 offset = 2; Byte[] array = new Byte[] { 0x9F, 0xDA, 0xCE, 0x02 }; instance.SetBytes(array, offset); Assert.That(instance.ToInt32(offset), Is.EqualTo(expected)); }
public void ToUInt16_ValueAndOffset_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); UInt16 expected = 4711; // LE: 0x6712 => 01100111 00010010 Int32 offset = 2; Byte[] array = new Byte[] { 0x67, 0x12 }; instance.SetBytes(array, offset); Assert.That(instance.ToUInt16(offset), Is.EqualTo(expected)); }
public void ToByte_ValueAndOffset_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); Byte expected = 42; // LE: 0x2A => 00101010 Int32 offset = 2; Byte[] array = new Byte[] { 0x2A }; instance.SetBytes(array, offset); Assert.That(instance.ToByte(offset), Is.EqualTo(expected)); }
public void ToString_GroupingDisabledBE_ResultIsContent() { IBitCharger instance = this.CreateInstance(); this.byteOrder.SetupGet(x => x.IsLittleEndian).Returns(false); Int32 source = 47110815; // BE: 0x02CEDA9F => 00000010 11001110 11011010 10011111 instance.SetBytes(BitConverter.GetBytes(source), 0); String actual = instance.ToString(false); Assert.That(actual, Is.EqualTo(instance.Content)); }
public void SetBytes_SourceIsEmptyOffsetUnused_ContentRemainsUnchanged() { IBitCharger instance = this.CreateInstance(); instance.SetBitAt(2, true); instance.SetBitAt(3, true); instance.SetBitAt(5, true); instance.SetBitAt(7, true); String expected = instance.Content; instance.SetBytes(new Byte[0]); Assert.That(instance.Content, Is.EqualTo(expected)); }
public void ToString_GroupingEnabledLE_ResultAsExpected() { IBitCharger instance = this.CreateInstance(); this.byteOrder.SetupGet(x => x.IsLittleEndian).Returns(true); Int32 source = 47110815; // LE: 0x9FDACE02 => 10011111 11011010 11001110 00000010 instance.SetBytes(BitConverter.GetBytes(source), 0); String expected = "10011111 11011010 11001110 00000010"; String actual = instance.ToString(true); Assert.That(actual, Is.EqualTo(expected)); }
public void SetBytes_SourceThreeBytesOffsetThreeBE_ContentAsExpected() { IBitCharger instance = this.CreateInstance(); this.byteOrder.SetupGet(x => x.IsLittleEndian).Returns(false); // 10101100 (0xAC, 172) -> Bits to keep... instance.SetBitAt(2, true); instance.SetBitAt(3, true); instance.SetBitAt(5, true); instance.SetBitAt(7, true); String expected = this.MakeExpected(new Byte[] { 0x81, 0x82, 0x83, 0x00, 0x00, 0xAC }); Byte[] source = new Byte[] { 0x83, 0x82, 0x81 }; instance.SetBytes(source, 3); Assert.That(instance.Content, Is.EqualTo(expected)); }
public void SetBytes_SourceIsEmptyOffsetInvalid_ThrowsArgumentOutOfRangeException() { IBitCharger instance = this.CreateInstance(); Assert.That(() => instance.SetBytes(new Byte[0], -1), Throws.InstanceOf <ArgumentOutOfRangeException>()); }
/// <summary> /// Sets the bits of <paramref name="value"/> into the /// <paramref name="charger"/> at offset zero. /// </summary> /// <remarks> /// This method sets all bits of <paramref name="value"/> /// into the <paramref name="charger"/> at offset zero. /// </remarks> /// <param name="charger"> /// An instance of <see cref="IBitCharger"/> to set the bits /// into. /// </param> /// <param name="value"> /// The bits to set. /// </param> public static void SetBytes(this IBitCharger charger, UInt64 value) { charger.SetBytes(value, 0); }
public void SetBytes_SourceIsNullOffsetZero_ThrowsArgumentNullException() { IBitCharger instance = this.CreateInstance(); Assert.That(() => instance.SetBytes(null, 0), Throws.ArgumentNullException); }