2013-11-10 20:14:10 +00:00
|
|
|
#include "BaseTestCase.h"
|
2013-11-10 16:03:07 +00:00
|
|
|
|
|
|
|
#include "NoiseGenerator.h"
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST(NoiseGenerator, getRange) {
|
|
|
|
NoiseGenerator *noise;
|
2013-11-10 16:03:07 +00:00
|
|
|
double minvalue, maxvalue;
|
|
|
|
|
|
|
|
noise = new NoiseGenerator();
|
|
|
|
|
|
|
|
noise->addLevelSimple(0.1, -1.0, 1.0);
|
|
|
|
noise->addLevelSimple(0.2, -0.5, 0.2);
|
|
|
|
noise->addLevelSimple(0.4, -0.3, 1.2);
|
|
|
|
noise->validate();
|
|
|
|
noise->getRange(&minvalue, &maxvalue);
|
|
|
|
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_DOUBLE_EQ(minvalue, -1.8);
|
|
|
|
EXPECT_DOUBLE_EQ(maxvalue, 2.4);
|
2013-11-10 16:03:07 +00:00
|
|
|
|
|
|
|
delete noise;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST(NoiseGenerator, normalizeAmplitude) {
|
2013-11-10 16:03:07 +00:00
|
|
|
int x;
|
2015-11-09 21:30:46 +00:00
|
|
|
NoiseGenerator *noise;
|
2013-11-10 16:03:07 +00:00
|
|
|
|
|
|
|
noise = new NoiseGenerator();
|
|
|
|
|
|
|
|
/* Symmetric case */
|
2013-11-10 20:14:10 +00:00
|
|
|
noise->addLevelsSimple(10, 1.0, -4.0, 4.0, 0.5);
|
2013-11-10 16:03:07 +00:00
|
|
|
noise->validate();
|
2013-11-10 20:14:10 +00:00
|
|
|
noise->normalizeAmplitude(-1.0, 1.0, 0);
|
2015-11-09 21:30:46 +00:00
|
|
|
for (x = 0; x < 1000; x++) {
|
2013-11-10 20:14:10 +00:00
|
|
|
double value = noise->get1DTotal(0.01 * (double)x);
|
|
|
|
ASSERT_DOUBLE_IN_RANGE(value, -1.0, 1.0);
|
2013-11-10 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Target center differs from current center */
|
|
|
|
noise->clearLevels();
|
2013-11-10 20:14:10 +00:00
|
|
|
noise->addLevelsSimple(10, 1.0, -5.0, 5.0, 0.5);
|
2013-11-10 16:03:07 +00:00
|
|
|
noise->validate();
|
2013-11-10 20:14:10 +00:00
|
|
|
noise->normalizeAmplitude(0.0, 1.0, 0);
|
2015-11-09 21:30:46 +00:00
|
|
|
for (x = 0; x < 1000; x++) {
|
2013-11-10 16:03:07 +00:00
|
|
|
double value = noise->get1DTotal(0.01 * (double)x);
|
2013-11-10 20:14:10 +00:00
|
|
|
ASSERT_DOUBLE_IN_RANGE(value, 0.0, 1.0);
|
2013-11-10 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Asymmetric range */
|
|
|
|
noise->clearLevels();
|
|
|
|
noise->addLevelsSimple(10, 1.0, 0.0, 10.0, 0.0);
|
|
|
|
noise->validate();
|
|
|
|
noise->normalizeAmplitude(0.0, 1.0, 0);
|
2015-11-09 21:30:46 +00:00
|
|
|
for (x = 0; x < 1000; x++) {
|
2013-11-10 16:03:07 +00:00
|
|
|
double value = noise->get1DTotal(0.01 * (double)x);
|
2013-11-10 20:14:10 +00:00
|
|
|
ASSERT_DOUBLE_IN_RANGE(value, 0.0, 1.0);
|
2013-11-10 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Complex asymmetric case */
|
|
|
|
noise->clearLevels();
|
|
|
|
noise->addLevelsSimple(3, 1.0, -2.0, 8.0, 0.3);
|
|
|
|
noise->validate();
|
|
|
|
noise->normalizeAmplitude(-2.0, 4.0, 0.0);
|
2015-11-09 21:30:46 +00:00
|
|
|
for (x = 0; x < 1000; x++) {
|
2013-11-10 16:03:07 +00:00
|
|
|
double value = noise->get1DTotal(0.01 * (double)x);
|
2013-11-10 20:14:10 +00:00
|
|
|
ASSERT_DOUBLE_IN_RANGE(value, -2.0, 4.0);
|
2013-11-10 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete noise;
|
|
|
|
}
|