Commit 56661a3e authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

test refactoring

parent 764035ee
#include "generators/algorithms/NormalDistribution.hpp"
#include "generators/NormalDistribution.hpp"
#include "basics/Utilities.hpp"
#include "TestEnvironment.hpp"
#include "MeshesCreator.hpp"
......@@ -6,94 +6,85 @@
typedef std::vector<SampleID> TestSampleIDs;
/*
* Todo: Find explanation for constants in EXPECT, i.e. sqrt(10.0)
*/
class TestNormalDistribution : public Test {
protected:
TestSampleIDs sampleIDs;
TestSampleIDs sampleIDs;
Meshes *meshes;
Meshes *meshes;
int numSamples = 1e6;
int numSamples = 1e6;
void SetUp() override {
meshes = MeshesCreator("Interval").Create();
for (int number = 0; number < numSamples; number++)
sampleIDs.push_back(SampleID(0, number, false));
}
void SetUp() override {
meshes = MeshesCreator("Interval").Create();
for (int number = 0; number < numSamples; number++)
sampleIDs.push_back(SampleID(0, number, false));
}
void TearDown() override {
delete meshes;
}
void TearDown() override {
delete meshes;
}
};
TEST_F(TestNormalDistribution, NormalDistributionReal) {
NormalDistributionReal normalDist(*meshes);
RVector results;
for (auto &id : sampleIDs) {
normalDist.DrawSample(id);
results.push_back(normalDist.EvalSample());
}
double mean = results.Mean();
double var = results.Variance();
EXPECT_NEAR(0.0, mean, sqrt(1.0 / numSamples));
EXPECT_NEAR(1.0, var, sqrt(10.0 / numSamples));
NormalDistributionReal normalDist(*meshes);
RVector results;
for (auto &id : sampleIDs) results.push_back(normalDist.DrawAndEvalSample(id));
double mean = results.Mean();
double var = results.Variance();
EXPECT_NEAR(0.0, mean, sqrt(1.0 / numSamples));
EXPECT_NEAR(1.0, var, sqrt(10.0 / numSamples));
}
TEST_F(TestNormalDistribution, ComplexNormalDistribution) {
NormalDistributionComplex normalDist(*meshes);
CVector results;
for (auto &id : sampleIDs) {
normalDist.DrawSample(id);
results.push_back(normalDist.EvalSample());
}
Complex mean = results.Mean();
double var = results.Variance();
EXPECT_NEAR(0.0, mean.real(), sqrt(1.0 / numSamples));
EXPECT_NEAR(0.0, mean.imag(), sqrt(1.0 / numSamples));
EXPECT_NEAR(2.0, var, sqrt(100.0 / numSamples));
NormalDistributionComplex normalDist(*meshes);
CVector results;
for (auto &id : sampleIDs) results.push_back(normalDist.DrawAndEvalSample(id));
Complex mean = results.Mean();
double var = results.Variance();
EXPECT_NEAR(0.0, mean.real(), sqrt(1.0 / numSamples));
EXPECT_NEAR(0.0, mean.imag(), sqrt(1.0 / numSamples));
EXPECT_NEAR(2.0, var, sqrt(100.0 / numSamples));
}
TEST_F(TestNormalDistribution, NormalDistributionRVector) {
NormalDistributionRVector normalDist(*meshes, numSamples);
normalDist.DrawSample(sampleIDs[0]);
RVector results = normalDist.EvalSample();
EXPECT_NEAR(0.0, results.Mean(), sqrt(1.0 / numSamples));
EXPECT_NEAR(1.0, results.Variance(), sqrt(10.0 / numSamples));
NormalDistributionRVector normalDist(*meshes, numSamples);
RVector results = normalDist.DrawAndEvalSample(sampleIDs[0]);
EXPECT_NEAR(0.0, results.Mean(), sqrt(1.0 / numSamples));
EXPECT_NEAR(1.0, results.Variance(), sqrt(10.0 / numSamples));
}
TEST_F(TestNormalDistribution, NormalDistributionCVector) {
NormalDistributionCVector normalDist(*meshes, numSamples);
normalDist.DrawSample(sampleIDs[0]);
CVector results = normalDist.EvalSample();
Complex mean = results.Mean();
EXPECT_NEAR(0.0, mean.real(), sqrt(1.0 / numSamples));
EXPECT_NEAR(0.0, mean.imag(), sqrt(1.0 / numSamples));
EXPECT_NEAR(1.0, results.Variance() / 2.0, sqrt(10.0 / numSamples));
NormalDistributionCVector normalDist(*meshes, numSamples);
CVector results = normalDist.DrawAndEvalSample(sampleIDs[0]);
Complex mean = results.Mean();
EXPECT_NEAR(0.0, mean.real(), sqrt(1.0 / numSamples));
EXPECT_NEAR(0.0, mean.imag(), sqrt(1.0 / numSamples));
EXPECT_NEAR(1.0, results.Variance() / 2.0, sqrt(10.0 / numSamples));
}
TEST_F(TestNormalDistribution, NormalDistributionRMatrix) {
NormalDistributionRMatrix normalDist(*meshes, sqrt(numSamples), sqrt(numSamples));
normalDist.DrawSample(sampleIDs[0]);
RMatrix results = normalDist.EvalSample();
EXPECT_NEAR(0.0, results.Mean(), sqrt(1.0 / numSamples));
EXPECT_NEAR(1.0, results.Variance(), sqrt(10.0 / numSamples));
NormalDistributionRMatrix normalDist(*meshes, sqrt(numSamples), sqrt(numSamples));
RMatrix results = normalDist.DrawAndEvalSample(sampleIDs[0]);
EXPECT_NEAR(0.0, results.Mean(), sqrt(1.0 / numSamples));
EXPECT_NEAR(1.0, results.Variance(), sqrt(10.0 / numSamples));
}
TEST_F(TestNormalDistribution, NormalDistributionCMatrix) {
NormalDistributionCMatrix normalDist(*meshes, sqrt(numSamples), sqrt(numSamples));
normalDist.DrawSample(sampleIDs[0]);
CMatrix results = normalDist.EvalSample();
Complex mean = results.Mean();
EXPECT_NEAR(0.0, mean.real(), sqrt(1.0 / numSamples));
EXPECT_NEAR(0.0, mean.imag(), sqrt(1.0 / numSamples));
EXPECT_NEAR(1.0, results.Variance() / 2.0, sqrt(10.0 / numSamples));
NormalDistributionCMatrix normalDist(*meshes, sqrt(numSamples), sqrt(numSamples));
CMatrix results = normalDist.DrawAndEvalSample(sampleIDs[0]);
Complex mean = results.Mean();
EXPECT_NEAR(0.0, mean.real(), sqrt(1.0 / numSamples));
EXPECT_NEAR(0.0, mean.imag(), sqrt(1.0 / numSamples));
EXPECT_NEAR(1.0, results.Variance() / 2.0, sqrt(10.0 / numSamples));
}
int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
WithPPM()
).RUN_ALL_MPP_TESTS();
return MppTest(
MppTestBuilder(argc, argv).
WithPPM()
).RUN_ALL_MPP_TESTS();
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment