From 356eeb7a319b6ee865f5001d1e3d8fab2f57e3c0 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Mon, 10 Nov 2014 20:29:19 +0000 Subject: Initial unit testing setup with an example test --- tests/xttest_scalar.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/xttest_scalar.cpp (limited to 'tests/xttest_scalar.cpp') diff --git a/tests/xttest_scalar.cpp b/tests/xttest_scalar.cpp new file mode 100644 index 0000000..4a11486 --- /dev/null +++ b/tests/xttest_scalar.cpp @@ -0,0 +1,54 @@ + +#include "xttest_util.hpp" + +#include "xtract/xtract_scalar.h" + +#include "catch.hpp" + + +SCENARIO( "F0 is correctly detected for a clean sine wave", "[xtract_f0]" ) +{ + GIVEN( "a 1024 sample block with a sample rate of 44100" ) + { + uint32_t blocksize = 1024; + double samplerate = 44100; + double result = 0.0; + double table[blocksize]; + + WHEN( "the frequency is 344.53125 Hz" ) // This will give a period of exactly 128 samples: 8 cycles in the block + { + double frequency = 344.53125; + double min = frequency * 0.995; + double max = frequency * 1.005; + + WHEN( "the amplitude is 1.0" ) + { + double amplitude = 1.0; + + xttest_gen_sine(table, blocksize, samplerate, frequency, amplitude); + xtract_f0(table, blocksize, &samplerate, &result); + CAPTURE( result ); + + THEN( "the detected F0 is in the range 344.53125 ± 0.5%" ) + { + REQUIRE(result < max); + REQUIRE(result > min); + } + } + WHEN( "the amplitude is 0.1" ) + { + double amplitude = 0.1; + + xttest_gen_sine(table, blocksize, samplerate, frequency, amplitude); + xtract_f0(table, blocksize, &samplerate, &result); + CAPTURE( result ); + + THEN( "the detected F0 is in the range 344.53125 ± 0.5%" ) + { + REQUIRE(result < max); + REQUIRE(result > min); + } + } + } + } +} -- cgit v1.2.3