aboutsummaryrefslogtreecommitdiff
path: root/tests/xttest_scalar.cpp
diff options
context:
space:
mode:
authorJamie Bullock <jamie@jamiebullock.com>2014-11-10 20:29:19 +0000
committerJamie Bullock <jamie@jamiebullock.com>2014-11-10 20:29:19 +0000
commit356eeb7a319b6ee865f5001d1e3d8fab2f57e3c0 (patch)
treeb33b0f46f4c04d66c9e4b39eeba2598132052b47 /tests/xttest_scalar.cpp
parentba706261d3fc5b436aa6f09d57e62eeb77377d8f (diff)
downloadLibXtract-356eeb7a319b6ee865f5001d1e3d8fab2f57e3c0.tar.gz
LibXtract-356eeb7a319b6ee865f5001d1e3d8fab2f57e3c0.tar.bz2
LibXtract-356eeb7a319b6ee865f5001d1e3d8fab2f57e3c0.zip
Initial unit testing setup with an example test
Diffstat (limited to 'tests/xttest_scalar.cpp')
-rw-r--r--tests/xttest_scalar.cpp54
1 files changed, 54 insertions, 0 deletions
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);
+ }
+ }
+ }
+ }
+}