From 1ab6c19486b43c55a14c0a309f34cd081bfab85d Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 3 Aug 2022 15:23:39 +0200 Subject: [PATCH] Add unit test for float encoding PR #3369 --- app/tests/test_binary.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/tests/test_binary.c b/app/tests/test_binary.c index 93aeccc8..6e52da72 100644 --- a/app/tests/test_binary.c +++ b/app/tests/test_binary.c @@ -67,6 +67,17 @@ static void test_read64be(void) { assert(val == 0xABCD1234567890EF); } +static void test_float_to_u16fp(void) { + assert(sc_float_to_u16fp(0.0f) == 0); + assert(sc_float_to_u16fp(0.03125f) == 0x800); + assert(sc_float_to_u16fp(0.0625f) == 0x1000); + assert(sc_float_to_u16fp(0.125f) == 0x2000); + assert(sc_float_to_u16fp(0.25f) == 0x4000); + assert(sc_float_to_u16fp(0.5f) == 0x8000); + assert(sc_float_to_u16fp(0.75f) == 0xc000); + assert(sc_float_to_u16fp(1.0f) == 0xffff); +} + int main(int argc, char *argv[]) { (void) argc; (void) argv; @@ -77,5 +88,7 @@ int main(int argc, char *argv[]) { test_read16be(); test_read32be(); test_read64be(); + + test_float_to_u16fp(); return 0; }