test: Test packing floats into ushort

This commit is contained in:
Paul Pacheco 2019-12-23 12:52:39 -06:00
parent ad2bee222a
commit a800064d8a

View File

@ -1,4 +1,6 @@
using NUnit.Framework;
using UnityEngine;
namespace Mirror.Tests
{
[TestFixture]
@ -21,5 +23,17 @@ public void ScaleByteToFloat()
Assert.That(FloatBytePacker.ScaleByteToFloat(191, byte.MinValue, byte.MaxValue, -1, 1), Is.EqualTo(0.4980392f).Within(0.0001f));
Assert.That(FloatBytePacker.ScaleByteToFloat(255, byte.MinValue, byte.MaxValue, -1, 1), Is.EqualTo(1).Within(0.0001f));
}
[Test]
public void TestPackFloatToUShort()
{
ushort packed = FloatBytePacker.PackThreeFloatsIntoUShort(15, 95, 170, 0, 360);
Vector3 unpacked = FloatBytePacker.UnpackUShortIntoThreeFloats(packed, 0, 360);
Assert.That(unpacked.x, Is.EqualTo(15).Within(10f));
Assert.That(unpacked.y, Is.EqualTo(95).Within(10f));
Assert.That(unpacked.z, Is.EqualTo(170).Within(10f));
}
}
}