Beispiel #1
0
        public void Should_SerializeInt48()
        {
            Int48 value = Int48.MaxValue; // range -140,737,488,355,327 to 140,737,488,355,327

            Assert.AreEqual(false, value._sign);
            Assert.AreEqual(new byte[] { 255, 255, 255, 255, 255, 127 }, value.GetBytes());
            Assert.AreEqual(new Bit[] {
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
            }, value.GetBits());

            value = Int48.MinValue;
            Assert.AreEqual(true, value._sign);
            Assert.AreEqual(new byte[] { 255, 255, 255, 255, 255, 255 }, value.GetBytes());
            Assert.AreEqual(new Bit[] {
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
            }, value.GetBits());

            // test overflow
            value = (Int48)140737488556378L;
            Assert.AreEqual(201050, value);
            Assert.AreEqual(false, value._sign);
            Assert.AreEqual(new byte[] { 90, 17, 3, 0, 0, 0 }, value.GetBytes());
            Assert.AreEqual(new Bit[] {
                0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            }, value.GetBits());
        }
Beispiel #2
0
 public static void TestValidValuesFromBytes(Int64 value)
 {
     TestHelpers.CatchUnexpected(() => {
         byte[] buffer = Int48.GetBytes(value);
         int pos       = 0;
         Int48 val     = Int48.GetNew(buffer, ref pos);
         Assert.AreEqual(value, val.Value, string.Format("On Set with Int32:{0}", buffer.ToHexByteString()));
     });
 }