diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testbase.cpp | 117 |
1 files changed, 114 insertions, 3 deletions
diff --git a/tests/testbase.cpp b/tests/testbase.cpp index e7cdd5b..9a9c699 100644 --- a/tests/testbase.cpp +++ b/tests/testbase.cpp @@ -26,14 +26,20 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "../src/simpl/base.h" +#include "../src/simpl/exceptions.h" namespace Simpl { -class TestBase : public CPPUNIT_NS::TestCase +// --------------------------------------------------------------------------- +// TestPeak +// --------------------------------------------------------------------------- +class TestPeak : public CPPUNIT_NS::TestCase { - CPPUNIT_TEST_SUITE(TestBase); + CPPUNIT_TEST_SUITE(TestPeak); CPPUNIT_TEST(test_constructor); + CPPUNIT_TEST(test_is_free); + CPPUNIT_TEST(test_is_start_of_partial); CPPUNIT_TEST_SUITE_END(); protected: @@ -52,6 +58,42 @@ protected: CPPUNIT_ASSERT(peak->frame_number == 0); } + void test_is_start_of_partial() + { + CPPUNIT_ASSERT(peak->is_start_of_partial()); + Peak* tmp = new Peak(); + peak->previous_peak = tmp; + CPPUNIT_ASSERT(!peak->is_start_of_partial()); + peak->previous_peak = NULL; + delete tmp; + } + + void test_is_free() + { + peak->amplitude = 0.0; + CPPUNIT_ASSERT(!peak->is_free()); + peak->amplitude = 1.0; + CPPUNIT_ASSERT(peak->is_free()); + + Peak* tmp = new Peak(); + + peak->next_peak = tmp; + CPPUNIT_ASSERT(!peak->is_free()); + CPPUNIT_ASSERT(!peak->is_free("forwards")); + CPPUNIT_ASSERT(peak->is_free("backwards")); + peak->next_peak = NULL; + + peak->previous_peak = tmp; + CPPUNIT_ASSERT(peak->is_free()); + CPPUNIT_ASSERT(peak->is_free("forwards")); + CPPUNIT_ASSERT(!peak->is_free("backwards")); + peak->previous_peak = NULL; + + delete tmp; + + CPPUNIT_ASSERT_THROW(peak->is_free("random_text"), InvalidArgument); + } + public: void setUp() { @@ -64,9 +106,78 @@ public: } }; +// --------------------------------------------------------------------------- +// TestFrame +// --------------------------------------------------------------------------- +class TestFrame : public CPPUNIT_NS::TestCase +{ + CPPUNIT_TEST_SUITE(TestFrame); + CPPUNIT_TEST(test_constructor); + CPPUNIT_TEST(test_set_size); + CPPUNIT_TEST(test_set_max_peaks); + CPPUNIT_TEST(test_set_max_partials); + CPPUNIT_TEST_SUITE_END(); + +protected: + static const double PRECISION = 0.001; + Frame* frame; + + void test_constructor() + { + CPPUNIT_ASSERT(frame->get_size() == 512); + CPPUNIT_ASSERT(frame->audio.size() == 512); + CPPUNIT_ASSERT(frame->synth.size() == 512); + CPPUNIT_ASSERT(frame->residual.size() == 512); + CPPUNIT_ASSERT(frame->synth_residual.size() == 512); + CPPUNIT_ASSERT(frame->get_max_peaks() == 100); + CPPUNIT_ASSERT(frame->peaks.size() == 100); + CPPUNIT_ASSERT(frame->get_max_partials() == 100); + CPPUNIT_ASSERT(frame->partials.size() == 100); + } + + void test_set_size() + { + frame->set_size(1024); + CPPUNIT_ASSERT(frame->get_size() == 1024); + CPPUNIT_ASSERT(frame->audio.size() == 1024); + CPPUNIT_ASSERT(frame->synth.size() == 1024); + CPPUNIT_ASSERT(frame->residual.size() == 1024); + CPPUNIT_ASSERT(frame->synth_residual.size() == 1024); + frame->set_size(512); + } + + void test_set_max_peaks() + { + frame->set_max_peaks(200); + CPPUNIT_ASSERT(frame->get_max_peaks() == 200); + CPPUNIT_ASSERT(frame->peaks.size() == 200); + frame->set_max_peaks(100); + } + + void test_set_max_partials() + { + frame->set_max_partials(200); + CPPUNIT_ASSERT(frame->get_max_partials() == 200); + CPPUNIT_ASSERT(frame->partials.size() == 200); + frame->set_max_partials(100); + } + +public: + void setUp() + { + frame = new Frame(); + } + + void tearDown() + { + delete frame; + } +}; + } // end of namespace Simpl -CPPUNIT_TEST_SUITE_REGISTRATION(Simpl::TestBase); +CPPUNIT_TEST_SUITE_REGISTRATION(Simpl::TestPeak); +CPPUNIT_TEST_SUITE_REGISTRATION(Simpl::TestFrame); int main(int arg, char **argv) { |