diff options
author | John Glover <j@johnglover.net> | 2013-01-11 17:44:05 +0100 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2013-01-11 17:44:05 +0100 |
commit | ad704b5e9c985765e14eb38a0922e702b8bfc25a (patch) | |
tree | a1aa9e55e4df46c1f30ec33d301370ae44b7f1af /tests/test_base.cpp | |
parent | 971a93d0676914837cdef22afa26f020b7be9041 (diff) | |
download | simpl-ad704b5e9c985765e14eb38a0922e702b8bfc25a.tar.gz simpl-ad704b5e9c985765e14eb38a0922e702b8bfc25a.tar.bz2 simpl-ad704b5e9c985765e14eb38a0922e702b8bfc25a.zip |
[tests] Tidy up test C++ tests.
All tests can now be run from a single executable
called 'tests' (created in the build directory).
Diffstat (limited to 'tests/test_base.cpp')
-rw-r--r-- | tests/test_base.cpp | 153 |
1 files changed, 55 insertions, 98 deletions
diff --git a/tests/test_base.cpp b/tests/test_base.cpp index 2f7b5c4..b5f3acf 100644 --- a/tests/test_base.cpp +++ b/tests/test_base.cpp @@ -1,117 +1,74 @@ -#include <iostream> -#include <cppunit/ui/text/TextTestRunner.h> -#include <cppunit/TestResult.h> -#include <cppunit/TestResultCollector.h> -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/BriefTestProgressListener.h> -#include <cppunit/extensions/TestFactoryRegistry.h> +#include "test_base.h" -#include "../src/simpl/base.h" - -namespace simpl -{ +using namespace simpl; // --------------------------------------------------------------------------- // TestPeak // --------------------------------------------------------------------------- -class TestPeak : public CPPUNIT_NS::TestCase { - CPPUNIT_TEST_SUITE(TestPeak); - CPPUNIT_TEST_SUITE_END(); - -protected: - static const double PRECISION = 0.001; - Peak* peak; +void TestPeak::setUp() { + peak = new Peak(); +} -public: - void setUp() { - peak = new Peak(); - } +void TestPeak::tearDown() { + delete peak; +} - void tearDown() { - delete peak; - } -}; // --------------------------------------------------------------------------- // TestFrame // --------------------------------------------------------------------------- -class TestFrame : public CPPUNIT_NS::TestCase { - CPPUNIT_TEST_SUITE(TestFrame); - CPPUNIT_TEST(test_size); - CPPUNIT_TEST(test_max_peaks); - CPPUNIT_TEST(test_max_partials); - CPPUNIT_TEST(test_add_peak); - CPPUNIT_TEST(test_clear); - CPPUNIT_TEST_SUITE_END(); - -protected: - static const double PRECISION = 0.001; - Frame* frame; - - void test_size() { - frame->size(1024); - CPPUNIT_ASSERT(frame->size() == 1024); - frame->size(512); - } - - void test_max_peaks() { - frame->max_peaks(200); - CPPUNIT_ASSERT(frame->max_peaks() == 200); - CPPUNIT_ASSERT(frame->num_peaks() == 0); - frame->max_peaks(100); - } - - void test_max_partials() { - frame->max_partials(200); - CPPUNIT_ASSERT(frame->max_partials() == 200); - CPPUNIT_ASSERT(frame->num_partials() == 0); - frame->max_partials(100); - } - void test_add_peak() { - Peak p = Peak(); - p.amplitude = 1.5; - frame->add_peak(&p); - CPPUNIT_ASSERT(frame->max_peaks() == 100); - CPPUNIT_ASSERT(frame->num_peaks() == 1); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5, frame->peak(0)->amplitude, PRECISION); - - Peak p2 = Peak(); - p2.amplitude = 2.0; - frame->add_peak(&p2); - CPPUNIT_ASSERT(frame->max_peaks() == 100); - CPPUNIT_ASSERT(frame->num_peaks() == 2); - CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, frame->peak(1)->amplitude, PRECISION); - - frame->clear(); - } +void TestFrame::setUp() { + frame = new Frame(); +} - void test_clear() { - Peak p = Peak(); - p.amplitude = 1.5; - frame->add_peak(&p); - CPPUNIT_ASSERT(frame->num_peaks() == 1); - frame->clear(); - CPPUNIT_ASSERT(frame->num_peaks() == 0); - } +void TestFrame::tearDown() { + delete frame; +} -public: - void setUp() { - frame = new Frame(); - } +void TestFrame::test_size() { + frame->size(1024); + CPPUNIT_ASSERT(frame->size() == 1024); + frame->size(512); +} - void tearDown() { - delete frame; - } -}; +void TestFrame::test_max_peaks() { + frame->max_peaks(200); + CPPUNIT_ASSERT(frame->max_peaks() == 200); + CPPUNIT_ASSERT(frame->num_peaks() == 0); + frame->max_peaks(100); +} -} // end of namespace simpl +void TestFrame::test_max_partials() { + frame->max_partials(200); + CPPUNIT_ASSERT(frame->max_partials() == 200); + CPPUNIT_ASSERT(frame->num_partials() == 0); + frame->max_partials(100); +} -CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestPeak); -CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestFrame); +void TestFrame::test_add_peak() { + Peak p = Peak(); + p.amplitude = 1.5; + frame->add_peak(&p); + CPPUNIT_ASSERT(frame->max_peaks() == 100); + CPPUNIT_ASSERT(frame->num_peaks() == 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5, frame->peak(0)->amplitude, PRECISION); + + Peak p2 = Peak(); + p2.amplitude = 2.0; + frame->add_peak(&p2); + CPPUNIT_ASSERT(frame->max_peaks() == 100); + CPPUNIT_ASSERT(frame->num_peaks() == 2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, frame->peak(1)->amplitude, PRECISION); + + frame->clear(); +} -int main(int arg, char **argv) { - CppUnit::TextTestRunner runner; - runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); - return runner.run("", false); +void TestFrame::test_clear() { + Peak p = Peak(); + p.amplitude = 1.5; + frame->add_peak(&p); + CPPUNIT_ASSERT(frame->num_peaks() == 1); + frame->clear(); + CPPUNIT_ASSERT(frame->num_peaks() == 0); } |