Ejemplo n.º 1
0
 public void TestHalf()
 {
     var data = new[]
     {
         0f, -0f, 1f, -1f, 65504f, -65504f, 0.000061035156f, -0.000061035156f, 12.3359375f, -12.3359375f,
         float.NaN, float.PositiveInfinity, float.NegativeInfinity,
     };
     var stream = new MemoryStream();
     var writer = NetworkBinaryWriter.Create(stream);
     foreach (float value in data)
         writer.Write((Half)value);
     writer.Flush();
     var bytes = stream.GetBuffer();
     Assert.That(bytes.Any(x => x != 0), "Something wrong with memory stream usage?");
     stream = new MemoryStream(bytes);
     var reader = new NetworkBinaryReader(stream);
     var result = new float[data.Length];
     for (int i = 0; i < data.Length; ++i)
         result[i] = reader.ReadHalf();
     Assert.AreEqual(data, result);
 }