From 3c4861c75213e253784f8d7a51341b5afb548241 Mon Sep 17 00:00:00 2001 From: derselbst Date: Thu, 17 Oct 2019 22:37:24 +0200 Subject: [PATCH] Add a unit test for fluid_ct2hz_real() --- test/CMakeLists.txt | 1 + test/test_ct2hz.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/test_ct2hz.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0b735452..9752c11a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,7 @@ ADD_FLUID_TEST(test_seqbind_unregister) ADD_FLUID_TEST(test_synth_chorus_reverb) ADD_FLUID_TEST(test_snprintf) ADD_FLUID_TEST(test_synth_process) +ADD_FLUID_TEST(test_ct2hz) # if ( LIBSNDFILE_HASVORBIS ) # ADD_FLUID_TEST(test_sf3_sfont_loading) diff --git a/test/test_ct2hz.c b/test/test_ct2hz.c new file mode 100644 index 00000000..ef89a1e5 --- /dev/null +++ b/test/test_ct2hz.c @@ -0,0 +1,36 @@ + +#include "test.h" +#include "utils/fluid_conv.h" +#include "utils/fluid_sys.h" + +// this test makes sure FLUID_SNPRINTF uses a proper C99 compliant implementation + +int float_eq(fluid_real_t x, fluid_real_t y) +{ + static const float EPS = 1e-5; + return fabs(x-y) < EPS; +} + +int main(void) +{ + // 440 * 2^((x-6900)/1200) where x is the cent value given to ct2hz() + + TEST_ASSERT(float_eq(fluid_ct2hz_real(13500), 19912.12696)); + + TEST_ASSERT(float_eq(fluid_ct2hz_real(12900), 14080)); + TEST_ASSERT(float_eq(fluid_ct2hz_real(12899), 14071.86942)); + + TEST_ASSERT(float_eq(fluid_ct2hz_real(12700), 12543.85395)); + TEST_ASSERT(float_eq(fluid_ct2hz_real(6900), 440)); + TEST_ASSERT(float_eq(fluid_ct2hz_real(5700), 220)); + TEST_ASSERT(float_eq(fluid_ct2hz_real(4500), 110)); + + TEST_ASSERT(float_eq(fluid_ct2hz_real(901), 13.75794461)); + TEST_ASSERT(float_eq(fluid_ct2hz_real(900), 13.75)); + TEST_ASSERT(float_eq(fluid_ct2hz_real(899), 13.74205998)); + + TEST_ASSERT(float_eq(fluid_ct2hz_real(1), 8.180522806)); + TEST_ASSERT(float_eq(fluid_ct2hz_real(0), 8.175798916)); // often referred to as Absolute zero in the SF2 spec + + return EXIT_SUCCESS; +}