Skip to content

Commit

Permalink
Add unit test for float encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
rom1v committed Aug 28, 2022
1 parent fd3483c commit 1ab6c19
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/tests/test_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -77,5 +88,7 @@ int main(int argc, char *argv[]) {
test_read16be();
test_read32be();
test_read64be();

test_float_to_u16fp();
return 0;
}

0 comments on commit 1ab6c19

Please sign in to comment.