Beispiel #1
0
        public void should_read_numeric_values([ValueSource(nameof(GetBufferSegmentSizes))] int bufferSegmentSize)
        {
            CreateContext(Encoding.UTF8, bufferSegmentSize);

            _writer.Write(1);
            _writer.Write(-1);
            _writer.Write(int.MaxValue);
            _writer.Write(int.MinValue);

            _writer.Write((uint)2);
            _writer.Write(uint.MaxValue);
            _writer.Write(uint.MinValue);

            _writer.Write((short)3);
            _writer.Write((short)-3);
            _writer.Write(short.MaxValue);
            _writer.Write(short.MinValue);

            _writer.Write((ushort)4);
            _writer.Write(ushort.MaxValue);
            _writer.Write(ushort.MinValue);

            _writer.Write((long)5);
            _writer.Write((long)-5);
            _writer.Write(long.MaxValue);
            _writer.Write(long.MinValue);

            _writer.Write((ulong)6);
            _writer.Write(ulong.MaxValue);
            _writer.Write(ulong.MinValue);

            _writer.Write((byte)7);
            _writer.Write(byte.MaxValue);
            _writer.Write(byte.MinValue);

            _writer.Write((sbyte)8);
            _writer.Write((sbyte)-8);
            _writer.Write(sbyte.MaxValue);
            _writer.Write(sbyte.MinValue);

            _writer.Write(true);
            _writer.Write(false);

            _writer.Write(2.2f);
            _writer.Write(-2.2f);
            _writer.Write(float.MaxValue);
            _writer.Write(float.MinValue);

            _writer.Write(3.3d);
            _writer.Write(-3.3d);
            _writer.Write(double.MaxValue);
            _writer.Write(double.MinValue);

            _writer.Write(4.4m);
            _writer.Write(-4.4m);
            _writer.Write(decimal.MaxValue);
            _writer.Write(decimal.MinValue);

            _writer.Write(_marker);

            Assert.AreEqual(1, _reader.ReadInt32());
            Assert.AreEqual(-1, _reader.ReadInt32());
            Assert.AreEqual(int.MaxValue, _reader.ReadInt32());
            Assert.AreEqual(int.MinValue, _reader.ReadInt32());

            Assert.AreEqual(2, _reader.ReadUInt32());
            Assert.AreEqual(uint.MaxValue, _reader.ReadUInt32());
            Assert.AreEqual(uint.MinValue, _reader.ReadUInt32());

            Assert.AreEqual(3, _reader.ReadInt16());
            Assert.AreEqual(-3, _reader.ReadInt16());
            Assert.AreEqual(short.MaxValue, _reader.ReadInt16());
            Assert.AreEqual(short.MinValue, _reader.ReadInt16());

            Assert.AreEqual(4, _reader.ReadUInt16());
            Assert.AreEqual(ushort.MaxValue, _reader.ReadUInt16());
            Assert.AreEqual(ushort.MinValue, _reader.ReadUInt16());

            Assert.AreEqual(5, _reader.ReadInt64());
            Assert.AreEqual(-5, _reader.ReadInt64());
            Assert.AreEqual(long.MaxValue, _reader.ReadInt64());
            Assert.AreEqual(long.MinValue, _reader.ReadInt64());

            Assert.AreEqual(6, _reader.ReadUInt64());
            Assert.AreEqual(ulong.MaxValue, _reader.ReadUInt64());
            Assert.AreEqual(ulong.MinValue, _reader.ReadUInt64());

            Assert.AreEqual(7, _reader.ReadByte());
            Assert.AreEqual(byte.MaxValue, _reader.ReadByte());
            Assert.AreEqual(byte.MinValue, _reader.ReadByte());

            Assert.AreEqual(8, _reader.ReadSByte());
            Assert.AreEqual(-8, _reader.ReadSByte());
            Assert.AreEqual(sbyte.MaxValue, _reader.ReadSByte());
            Assert.AreEqual(sbyte.MinValue, _reader.ReadSByte());

            Assert.AreEqual(true, _reader.ReadBoolean());
            Assert.AreEqual(false, _reader.ReadBoolean());

            Assert.AreEqual(2.2f, _reader.ReadSingle());
            Assert.AreEqual(-2.2f, _reader.ReadSingle());
            Assert.AreEqual(float.MaxValue, _reader.ReadSingle());
            Assert.AreEqual(float.MinValue, _reader.ReadSingle());

            Assert.AreEqual(3.3d, _reader.ReadDouble());
            Assert.AreEqual(-3.3d, _reader.ReadDouble());
            Assert.AreEqual(double.MaxValue, _reader.ReadDouble());
            Assert.AreEqual(double.MinValue, _reader.ReadDouble());

            Assert.AreEqual(4.4m, _reader.ReadDecimal());
            Assert.AreEqual(-4.4m, _reader.ReadDecimal());
            Assert.AreEqual(decimal.MaxValue, _reader.ReadDecimal());
            Assert.AreEqual(decimal.MinValue, _reader.ReadDecimal());

            Assert.AreEqual(_marker, _reader.ReadUInt32());
        }