示例#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());
        }
示例#2
0
 public static void TestValidValuesFromInt(Int64 value)
 {
     TestHelpers.CatchUnexpected(() => {
         Int48 val = Int48.GetNew(value);
         Assert.AreEqual(value, val.Value, string.Format("On Set with Int32:{0}", value));
     });
 }
示例#3
0
 public static void TestOutOfRange(Int64 value)
 {
     TestHelpers.CatchUnexpected(() => {
         Assert.Throws <ArgumentOutOfRangeException>(() => {
             Int48 val = Int48.GetNew(value);
         });
     });
 }
示例#4
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()));
     });
 }