Commit 211a4e72 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

testing prev commit

parent 6dfa3af9
......@@ -11,38 +11,59 @@ protected:
Meshes *meshes;
NormalDistribution *normalDist;
int testSamples = 1e6;
std::vector<double> results;
void SetUp() override {
meshes = createTestMeshes("Interval_DirichletBC", 0, 0);
normalDist = new NormalDistribution(*meshes);
for (int number = 0; number < testSamples; number++)
sampleIDs.push_back(SampleID(Level(), number, false));
}
void TearDown() override {
delete meshes;
delete normalDist;
}
};
TEST_F(TestNormalDistribution, TestDrawSample) {
TEST_F(TestNormalDistribution, NormalDistribution) {
NormalDistribution normalDist(*meshes);
std::vector<Scalar> results;
for (auto &id : sampleIDs) {
normalDist.DrawSample(id);
results.push_back(normalDist.EvalScalarSample());
}
Scalar mean = Mean(results);
Scalar var = Variance(results);
ASSERT_NEAR(0.0, mean, sqrt(1.0 / testSamples));
ASSERT_NEAR(1.0, var, sqrt(10.0 / testSamples));
}
TEST_F(TestNormalDistribution, ComplexNormalDistribution) {
ComplexNormalDistribution normalDist(*meshes);
std::vector<Complex> results;
for (auto &id : sampleIDs) {
normalDist->DrawSample(id);
results.push_back(normalDist->EvalScalarSample());
normalDist.DrawSample(id);
results.push_back(normalDist.EvalComplexSample());
}
double mean = calc_mean(results);
double var = calc_var(results);
Complex mean = Mean(results);
Complex var = Variance(results);
ASSERT_NEAR(0.0, mean.real(), sqrt(1.0 / testSamples));
ASSERT_NEAR(0.0, mean.imag(), sqrt(1.0 / testSamples));
// ASSERT_NEAR(1.0, var, sqrt(10.0 / testSamples)); // TODO
// ASSERT_NEAR(1.0, var.imag(), sqrt(10.0 / testSamples));
}
TEST_F(TestNormalDistribution, NormalDistributionScalar1DField) {
NormalDistributionScalar1DField normalDist(*meshes);
normalDist.Resize(sampleIDs.size());
normalDist.DrawSample(sampleIDs[0]);
ScalarField1D results = normalDist.EvalScalarField1DSample();
Scalar mean = Mean(results);
Scalar var = Variance(results);
ASSERT_NEAR(0.0, mean, sqrt(1.0 / testSamples));
// Todo how does variance drop?
ASSERT_NEAR(1.0, var, sqrt(10.0 / testSamples));
}
int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
......
Markdown is supported
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