Beispiel #1
0
        public void BigEndianBitConverter_Decimal()
        {
            const int n = sizeof(Decimal);

            const Decimal pos  = 3.1415926535897932384626433833m;
            const Decimal zero = 0;
            const Decimal neg  = -pos;

            var posRepr = GetCanonicalRepresentation(pos);
            var negRepr = GetCanonicalRepresentation(neg);

            // --------------------------------------------------------------

            var buffer = new byte[n];

            BigEndianBitConverter.FillBytes(pos, buffer);
            Assert.IsTrue(buffer.SequenceEqual(posRepr));
            Assert.IsTrue(BigEndianBitConverter.GetBytes(pos).SequenceEqual(buffer));
            Assert.AreEqual(pos, BigEndianBitConverter.ToDecimal(buffer));

            BigEndianBitConverter.FillBytes(zero, buffer);
            Assert.IsTrue(buffer.SequenceEqual(new byte[n]));
            Assert.IsTrue(BigEndianBitConverter.GetBytes(zero).SequenceEqual(buffer));
            Assert.AreEqual(zero, BigEndianBitConverter.ToDecimal(buffer));

            BigEndianBitConverter.FillBytes(neg, buffer);
            Assert.IsTrue(buffer.SequenceEqual(negRepr));
            Assert.IsTrue(BigEndianBitConverter.GetBytes(neg).SequenceEqual(buffer));
            Assert.AreEqual(neg, BigEndianBitConverter.ToDecimal(buffer));
        }