예제 #1
0
        public void NotEnoughBytesToWrite()
        {
            ulong value = 151288809941952652;

            Assert.ThrowsException <ArithmeticException>(() =>
            {
                var bytes = new byte[7].AsSpan();
                VariableLengthInt.Write(value, ref bytes);
            });

            value = 494878333;
            Assert.ThrowsException <ArithmeticException>(() =>
            {
                var bytes = new byte[3].AsSpan();
                VariableLengthInt.Write(value, ref bytes);
            });

            value = 15293;
            Assert.ThrowsException <ArithmeticException>(() =>
            {
                var bytes = new byte[1].AsSpan();
                VariableLengthInt.Write(value, ref bytes);
            });

            value = 37;
            Assert.ThrowsException <ArithmeticException>(() =>
            {
                var bytes = new byte[0].AsSpan();
                VariableLengthInt.Write(value, ref bytes);
            });
        }
예제 #2
0
        public void NumberTooBigTest()
        {
            ulong value = 4611686018427387904;

            Assert.ThrowsException <ArithmeticException>(() =>
            {
                var bytes = new byte[8].AsSpan();
                VariableLengthInt.Write(value, ref bytes);
            });
        }
예제 #3
0
        public void HappyWriteTests()
        {
            ulong value    = 151288809941952652;
            var   expected = "c2 19 7c 5e ff 14 e8 8c".ToByteArrayFromHex().AsSpan();
            var   actual   = new byte[8].AsSpan();
            int   bytesUsed;

            bytesUsed = VariableLengthInt.Write(value, ref actual);

            Assert.IsTrue(expected.SequenceEqual(actual));
            Assert.AreEqual(expected.Length, bytesUsed);


            value    = 494878333;
            expected = "9d 7f 3e 7d".ToByteArrayFromHex();
            actual   = new byte[4].AsSpan();

            bytesUsed = VariableLengthInt.Write(value, ref actual);

            Assert.IsTrue(expected.SequenceEqual(actual));
            Assert.AreEqual(expected.Length, bytesUsed);


            value    = 15293;
            expected = "7b bd".ToByteArrayFromHex();
            actual   = new byte[2].AsSpan();

            bytesUsed = VariableLengthInt.Write(value, ref actual);

            Assert.IsTrue(expected.SequenceEqual(actual));
            Assert.AreEqual(expected.Length, bytesUsed);


            value    = 37;
            expected = "25".ToByteArrayFromHex();
            actual   = new byte[1].AsSpan();

            bytesUsed = VariableLengthInt.Write(value, ref actual);

            Assert.IsTrue(expected.SequenceEqual(actual));
            Assert.AreEqual(expected.Length, bytesUsed);
        }