void simpleTest() { srand(0); DelaunayInterpolator uut; shared_ptr<DataFrame> dfPtr(new DataFrame()); DataFrame& df = *dfPtr; vector<string> labels; labels.push_back("x"); labels.push_back("y"); labels.push_back("h"); vector<int> types(3, DataFrame::Numerical); df.setFactorLabels(labels); df.setFactorTypes(types); // is there a cleaner way? vector<double> d(3); for (size_t i = 0; i < 500; i++) { d[0] = Random::generateUniform() * 2 - 1; d[1] = Random::generateUniform() * 2 - 1; double e = sqrt(d[0] * d[0] + d[1] * d[1]); d[2] = Normal::normal(e, .5); df.addDataVector("", d); } uut.setData(dfPtr); vector<string> ind; ind.push_back("x"); ind.push_back("y"); uut.setIndependentColumns(ind); vector<string> dep; dep.push_back("h"); uut.setDependentColumns(dep); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0028, uut.estimateError(), 0.0001); }
void serializationTest() { srand(0); shared_ptr<DelaunayInterpolator> di = buildRandom(); DelaunayInterpolator& uut = *di; srand(0); double error = uut.estimateError(); QBuffer buf; buf.open(QBuffer::WriteOnly); uut.writeInterpolator(buf); buf.close(); buf.open(QBuffer::ReadOnly); DelaunayInterpolator copy; copy.readInterpolator(buf); srand(0); CPPUNIT_ASSERT_DOUBLES_EQUAL(error, copy.estimateError(), 0.0001); }