public void GetBytesFromBooleanTest() { var bc = new StraightBitConverter(); var bytes = new byte[1]; bc.GetBytes(true, bytes, 0); Assert.AreEqual("01", ByteArrayToString(bytes)); bc.GetBytes(false, bytes, 0); Assert.AreEqual("00", ByteArrayToString(bytes)); }
public void GetBytesFromDoubleTest() { var bc = new StraightBitConverter(); var bytes = new byte[8]; bc.GetBytes(1.0, bytes, 0); Assert.AreEqual("00-00-00-00-00-00-F0-3F", ByteArrayToString(bytes)); bc.GetBytes(-1.0, bytes, 0); Assert.AreEqual("00-00-00-00-00-00-F0-BF", ByteArrayToString(bytes)); }
public void GetBytesFromInt32Test() { var bc = new StraightBitConverter(); var bytes = new byte[4]; bc.GetBytes((Int32)0, bytes, 0); Assert.AreEqual("00-00-00-00", ByteArrayToString(bytes)); bc.GetBytes((Int32)1, bytes, 0); Assert.AreEqual("01-00-00-00", ByteArrayToString(bytes)); bc.GetBytes((Int32)(-1), bytes, 0); Assert.AreEqual("FF-FF-FF-FF", ByteArrayToString(bytes)); bc.GetBytes(Int32.MinValue, bytes, 0); Assert.AreEqual("00-00-00-80", ByteArrayToString(bytes)); bc.GetBytes(Int32.MaxValue, bytes, 0); Assert.AreEqual("FF-FF-FF-7F", ByteArrayToString(bytes)); }
public void ToUInt64Test() { var bc = new StraightBitConverter(); Assert.AreEqual(1UL, bc.ToUInt64(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 }, 0)); Assert.AreEqual(65536UL, bc.ToUInt64(new byte[] { 0, 0, 1, 0, 0, 0, 0, 0 }, 0)); Assert.AreEqual(4294967296UL, bc.ToUInt64(new byte[] { 0, 0, 0, 0, 1, 0, 0, 0 }, 0)); Assert.AreEqual(281474976710656UL, bc.ToUInt64(new byte[] { 0, 0, 0, 0, 0, 0, 1, 0 }, 0)); Assert.AreEqual(18446744073709551615UL, bc.ToUInt64(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 }, 0)); }
public void ToUInt32Test() { var bc = new StraightBitConverter(); Assert.AreEqual(1U, bc.ToUInt32(new byte[] { 1, 0, 0, 0 }, 0)); Assert.AreEqual(65536U, bc.ToUInt32(new byte[] { 0, 0, 1, 0 }, 0)); Assert.AreEqual(4294967295U, bc.ToUInt32(new byte[] { 255, 255, 255, 255 }, 0)); }
public void ToUInt16Test() { var bc = new StraightBitConverter(); Assert.AreEqual(1U, bc.ToUInt16(new byte[] { 1, 0 }, 0)); Assert.AreEqual(256U, bc.ToUInt16(new byte[] { 0, 1 }, 0)); Assert.AreEqual(257U, bc.ToUInt16(new byte[] { 1, 1 }, 0)); Assert.AreEqual(65535U, bc.ToUInt16(new byte[] { 255, 255 }, 0)); }
public void ToSingleTest() { var bc = new StraightBitConverter(); Assert.AreEqual(1.0f, bc.ToSingle(new byte[] { 0, 0, 128, 63 }, 0)); Assert.AreEqual(-1.0f, bc.ToSingle(new byte[] { 0, 0, 128, 191 }, 0)); }
public void ToSByteTest() { var bc = new StraightBitConverter(); Assert.AreEqual(0, bc.ToSByte(new byte[] { 0 }, 0)); Assert.AreEqual(1, bc.ToSByte(new byte[] { 1 }, 0)); Assert.AreEqual(127, bc.ToSByte(new byte[] { 127 }, 0)); Assert.AreEqual(-128, bc.ToSByte(new byte[] { 128 }, 0)); Assert.AreEqual(-1, bc.ToSByte(new byte[] { 255 }, 0)); }
public void ToInt64Test() { var bc = new StraightBitConverter(); Assert.AreEqual(1L, bc.ToInt64(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 }, 0)); Assert.AreEqual(65536L, bc.ToInt64(new byte[] { 0, 0, 1, 0, 0, 0, 0, 0 }, 0)); Assert.AreEqual(4294967296L, bc.ToInt64(new byte[] { 0, 0, 0, 0, 1, 0, 0, 0 }, 0)); Assert.AreEqual(281474976710656L, bc.ToInt64(new byte[] { 0, 0, 0, 0, 0, 0, 1, 0 }, 0)); Assert.AreEqual(-1L, bc.ToInt64(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 }, 0)); }
public void ToInt32Test() { var bc = new StraightBitConverter(); Assert.AreEqual(1, bc.ToInt32(new byte[] { 1, 0, 0, 0 }, 0)); Assert.AreEqual(65536, bc.ToInt32(new byte[] { 0, 0, 1, 0 }, 0)); Assert.AreEqual(-1, bc.ToInt32(new byte[] { 255, 255, 255, 255 }, 0)); }
public void ToInt16Test() { var bc = new StraightBitConverter(); Assert.AreEqual(1, bc.ToInt16(new byte[] { 1, 0 }, 0)); Assert.AreEqual(256, bc.ToInt16(new byte[] { 0, 1 }, 0)); Assert.AreEqual(257, bc.ToInt16(new byte[] { 1, 1 }, 0)); Assert.AreEqual(-1, bc.ToInt16(new byte[] { 255, 255 }, 0)); Assert.AreEqual(-32768, bc.ToInt16(new byte[] { 0, 128 }, 0)); Assert.AreEqual(32767, bc.ToInt16(new byte[] { 255, 127 }, 0)); }
public void ToDoubleTest() { var bc = new StraightBitConverter(); Assert.AreEqual(1.0, bc.ToDouble(new byte[] { 0, 0, 0, 0, 0, 0, 240, 63 }, 0)); Assert.AreEqual(-1.0, bc.ToDouble(new byte[] { 0, 0, 0, 0, 0, 0, 240, 191 }, 0)); }
public void ToBooleanTest() { var bc = new StraightBitConverter(); Assert.IsTrue(bc.ToBoolean(new byte[] { 1 }, 0)); Assert.IsTrue(bc.ToBoolean(new byte[] { 8 }, 0)); Assert.IsFalse(bc.ToBoolean(new byte[] { 0 }, 0)); }
public void GetBytesFromUInt64Test() { var bc = new StraightBitConverter(); var bytes = new byte[8]; bc.GetBytes(0UL, bytes, 0); Assert.AreEqual("00-00-00-00-00-00-00-00", ByteArrayToString(bytes)); bc.GetBytes(1UL, bytes, 0); Assert.AreEqual("01-00-00-00-00-00-00-00", ByteArrayToString(bytes)); bc.GetBytes(UInt64.MinValue, bytes, 0); Assert.AreEqual("00-00-00-00-00-00-00-00", ByteArrayToString(bytes)); bc.GetBytes(UInt64.MaxValue, bytes, 0); Assert.AreEqual("FF-FF-FF-FF-FF-FF-FF-FF", ByteArrayToString(bytes)); }