summaryrefslogtreecommitdiff
path: root/test/randomtest.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-06-16 18:05:00 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-06-16 18:15:59 +0200
commit2abc107b24f73b8c4664189c34196d9a27a3e339 (patch)
treeb7067a45f7294dbd143c410bdfb690157c976e3c /test/randomtest.cc
parente694a23ab28686ecc0635c2ac8c625e743b89a3b (diff)
Port the rest of the unittests to DGUnit and remove the CppUnit dependency.
Diffstat (limited to 'test/randomtest.cc')
-rw-r--r--test/randomtest.cc40
1 files changed, 16 insertions, 24 deletions
diff --git a/test/randomtest.cc b/test/randomtest.cc
index 16a16c4..bc79432 100644
--- a/test/randomtest.cc
+++ b/test/randomtest.cc
@@ -24,7 +24,7 @@
* along with DrumGizmo; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include <cppunit/extensions/HelperMacros.h>
+#include "dgunit.h"
#include <random.h>
@@ -32,22 +32,14 @@
#include <cmath>
class RandomTest
- : public CppUnit::TestFixture
+ : public DGUnit
{
- CPPUNIT_TEST_SUITE(RandomTest);
- CPPUNIT_TEST(rangeTest);
- CPPUNIT_TEST(normalTest);
- CPPUNIT_TEST(chooseTest);
- CPPUNIT_TEST_SUITE_END();
-
public:
- void setUp()
+ RandomTest()
{
- }
-
- void tearDown()
- {
-
+ DGUNIT_TEST(RandomTest::rangeTest);
+ DGUNIT_TEST(RandomTest::normalTest);
+ DGUNIT_TEST(RandomTest::chooseTest);
}
void rangeTest()
@@ -63,16 +55,16 @@ public:
{
float rand_float = rand.floatInRange(float_lb, float_ub);
float rand_int = rand.intInRange(int_lb, int_ub);
- CPPUNIT_ASSERT(rand_float >= float_lb && rand_float <= float_ub);
- CPPUNIT_ASSERT(rand_int >= int_lb && rand_int <= int_ub);
+ DGUNIT_ASSERT(rand_float >= float_lb && rand_float <= float_ub);
+ DGUNIT_ASSERT(rand_int >= int_lb && rand_int <= int_ub);
}
-
+
// check if the series of random numbers is the one we expect
// for a certain seed.
rand = Random(666);
- CPPUNIT_ASSERT_EQUAL(0, rand.intInRange(0,100));
- CPPUNIT_ASSERT_EQUAL(61, rand.intInRange(0,100));
- CPPUNIT_ASSERT_EQUAL(23, rand.intInRange(0,100));
+ DGUNIT_ASSERT_EQUAL(0, rand.intInRange(0,100));
+ DGUNIT_ASSERT_EQUAL(61, rand.intInRange(0,100));
+ DGUNIT_ASSERT_EQUAL(23, rand.intInRange(0,100));
}
void normalTest()
@@ -97,8 +89,8 @@ public:
float estimated_stddev = sqrt(sum_of_squares/nr_of_samples - estimated_mean*estimated_mean);
float epsilon = 0.1;
- CPPUNIT_ASSERT(estimated_mean >= real_mean-epsilon && estimated_mean <= real_mean+epsilon);
- CPPUNIT_ASSERT(estimated_stddev >= real_stddev-epsilon && estimated_stddev <= real_stddev+epsilon);
+ DGUNIT_ASSERT(estimated_mean >= real_mean-epsilon && estimated_mean <= real_mean+epsilon);
+ DGUNIT_ASSERT(estimated_stddev >= real_stddev-epsilon && estimated_stddev <= real_stddev+epsilon);
}
void chooseTest()
@@ -110,10 +102,10 @@ public:
for (int i=0; i<nr_of_samples; i++)
{
- CPPUNIT_ASSERT_EQUAL(42, rand.choose(vec));
+ DGUNIT_ASSERT_EQUAL(42, rand.choose(vec));
}
}
};
// Registers the fixture into the 'registry'
-CPPUNIT_TEST_SUITE_REGISTRATION(RandomTest);
+static RandomTest test;