From 136ab8c19902e1b41915dabb23e36945e5b6e394 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 3 Aug 2022 14:55:35 +0200 Subject: [PATCH] Add unit test for float decoding PR #3369 --- .../com/genymobile/scrcpy/BinaryTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 server/src/test/java/com/genymobile/scrcpy/BinaryTest.java diff --git a/server/src/test/java/com/genymobile/scrcpy/BinaryTest.java b/server/src/test/java/com/genymobile/scrcpy/BinaryTest.java new file mode 100644 index 00000000..b2d3d72d --- /dev/null +++ b/server/src/test/java/com/genymobile/scrcpy/BinaryTest.java @@ -0,0 +1,20 @@ +package com.genymobile.scrcpy; + +import org.junit.Assert; +import org.junit.Test; + +public class BinaryTest { + + @Test + public void testU16FixedPointToFloat() { + final float delta = 0.0f; // on these values, there MUST be no rounding error + Assert.assertEquals(0.0f, Binary.u16FixedPointToFloat((short) 0), delta); + Assert.assertEquals(0.03125f, Binary.u16FixedPointToFloat((short) 0x800), delta); + Assert.assertEquals(0.0625f, Binary.u16FixedPointToFloat((short) 0x1000), delta); + Assert.assertEquals(0.125f, Binary.u16FixedPointToFloat((short) 0x2000), delta); + Assert.assertEquals(0.25f, Binary.u16FixedPointToFloat((short) 0x4000), delta); + Assert.assertEquals(0.5f, Binary.u16FixedPointToFloat((short) 0x8000), delta); + Assert.assertEquals(0.75f, Binary.u16FixedPointToFloat((short) 0xc000), delta); + Assert.assertEquals(1.0f, Binary.u16FixedPointToFloat((short) 0xffff), delta); + } +}