FloatTest.cs
1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using NUnit.Framework;
using System;
using System.Linq;
namespace UniJSON.MsgPack
{
[TestFixture]
public class FloatTest
{
[Test]
public void Float32()
{
var i = 1.1f;
var float_be = new byte[]
{
(Byte)MsgPackType.FLOAT, 0x3f, 0x8c, 0xcc, 0xcd
};
var f = new MsgPackFormatter();
f.Value(i);
var bytes = f.GetStoreBytes();
var value = MsgPackParser.Parse(bytes);
var body = value.Value.Bytes;
Assert.AreEqual(float_be, body.ToEnumerable().ToArray());
Assert.AreEqual(i, value.GetValue());
}
[Test]
public void Float64()
{
var i = 1.1;
var double_be = new Byte[]{
(Byte)MsgPackType.DOUBLE, 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a,
};
var f = new MsgPackFormatter();
f.Value(i);
var bytes = f.GetStoreBytes();
var value = MsgPackParser.Parse(bytes);
var body = value.Value.Bytes;
Assert.AreEqual(double_be, body.ToEnumerable().ToArray());
Assert.AreEqual(i, value.GetValue());
}
}
}