Example #1
0
        public void TestFloat()
        {
            var stream = new MsgPackStream();

            stream.WriteDouble(178.5);
            Assert.AreEqual(stream.Position, 8);

            stream.WriteSingle(-10.3f);
            Assert.AreEqual(stream.Position, 12);

            stream.WriteSingle(float.NaN);
            stream.WriteSingle(float.NegativeInfinity);
            stream.WriteSingle(float.PositiveInfinity);
            stream.WriteDouble(double.NaN);
            stream.WriteDouble(double.NegativeInfinity);
            stream.WriteDouble(double.PositiveInfinity);

            stream.Position = 0;
            Assert.AreEqual(178.5, stream.ReadDouble());
            Assert.AreEqual(-10.3f, stream.ReadSingle());
            Assert.IsTrue(float.IsNaN(stream.ReadSingle()));
            Assert.IsTrue(float.IsNegativeInfinity(stream.ReadSingle()));
            Assert.IsTrue(float.IsPositiveInfinity(stream.ReadSingle()));
            Assert.IsTrue(double.IsNaN(stream.ReadDouble()));
            Assert.IsTrue(double.IsNegativeInfinity(stream.ReadDouble()));
            Assert.IsTrue(double.IsPositiveInfinity(stream.ReadDouble()));
        }