Skip to content

Display and control your Android device

Add unit test for float encoding

Romain Vimont1ab6c19486b4
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;
}