From 44f3b86547b57efb35acb341fa5e358e2c8af83f Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 7 Sep 2018 13:03:39 +0200 Subject: [PATCH] changed: rename the summary regression/integrationtest classes it restores c++ ODR which is nice, but the main reason is to allow usage of summary and generic comparison classes in the the same application. --- examples/test_util/compareSummary.cpp | 4 +- examples/test_util/summaryIntegrationTest.cpp | 60 ++++++++----------- examples/test_util/summaryIntegrationTest.hpp | 6 +- examples/test_util/summaryRegressionTest.cpp | 10 ++-- examples/test_util/summaryRegressionTest.hpp | 6 +- tests/test_compareSummary.cpp | 16 ++--- 6 files changed, 46 insertions(+), 56 deletions(-) diff --git a/examples/test_util/compareSummary.cpp b/examples/test_util/compareSummary.cpp index 388df848a..f933b21ab 100644 --- a/examples/test_util/compareSummary.cpp +++ b/examples/test_util/compareSummary.cpp @@ -180,7 +180,7 @@ int main (int argc, char ** argv){ try { if(regressionTest){ - RegressionTest compare(basename1,basename2, absoluteTolerance, relativeTolerance); + SummaryRegressionTest compare(basename1,basename2, absoluteTolerance, relativeTolerance); compare.throwOnErrors(throwOnError); compare.doAnalysis(analysis); if(printKeywords){compare.setPrintKeywords(true);} @@ -194,7 +194,7 @@ int main (int argc, char ** argv){ } } if(integrationTest){ - IntegrationTest compare(basename1,basename2, absoluteTolerance, relativeTolerance); + SummaryIntegrationTest compare(basename1,basename2, absoluteTolerance, relativeTolerance); compare.throwOnErrors(throwOnError); if(findVectorWithGreatestErrorRatio){compare.setFindVectorWithGreatestErrorRatio(true);} if(allowSpikes){compare.setAllowSpikes(true);} diff --git a/examples/test_util/summaryIntegrationTest.cpp b/examples/test_util/summaryIntegrationTest.cpp index e71d81374..6ea1e63f2 100644 --- a/examples/test_util/summaryIntegrationTest.cpp +++ b/examples/test_util/summaryIntegrationTest.cpp @@ -24,7 +24,7 @@ #include -void IntegrationTest::getIntegrationTest(){ +void SummaryIntegrationTest::getIntegrationTest(){ std::vector timeVec1, timeVec2; setTimeVecs(timeVec1, timeVec2); // Sets the time vectors, they are equal for all keywords (WPOR:PROD01 etc) setDataSets(timeVec1, timeVec2); @@ -89,7 +89,7 @@ void IntegrationTest::getIntegrationTest(){ } -void IntegrationTest::getIntegrationTest(const char* keyword){ +void SummaryIntegrationTest::getIntegrationTest(const char* keyword){ if(stringlist_contains(keysShort,keyword) && stringlist_contains(keysLong, keyword)){ std::vector timeVec1, timeVec2; setTimeVecs(timeVec1, timeVec2); // Sets the time vectors, they are equal for all keywords (WPOR:PROD01 etc) @@ -115,9 +115,9 @@ void IntegrationTest::getIntegrationTest(const char* keyword){ } -void IntegrationTest::checkForKeyword(const std::vector& timeVec1, - const std::vector& timeVec2, - const char* keyword){ +void SummaryIntegrationTest::checkForKeyword(const std::vector& timeVec1, + const std::vector& timeVec2, + const char* keyword){ std::vector dataVec1, dataVec2; getDataVecs(dataVec1,dataVec2,keyword); chooseReference(timeVec1, timeVec2,dataVec1,dataVec2); @@ -130,7 +130,7 @@ void IntegrationTest::checkForKeyword(const std::vector& timeVec1, } -int IntegrationTest::checkDeviation(const Deviation& deviation){ +int SummaryIntegrationTest::checkDeviation(const Deviation& deviation){ double absTol = getAbsTolerance(); double relTol = getRelTolerance(); if (deviation.rel> relTol && deviation.abs > absTol){ @@ -140,10 +140,10 @@ int IntegrationTest::checkDeviation(const Deviation& deviation){ } -void IntegrationTest::findGreatestErrorRatio(const WellProductionVolume& volume, - double &greatestRatio, - const char* currentKeyword, - std::string &greatestErrorRatio){ +void SummaryIntegrationTest::findGreatestErrorRatio(const WellProductionVolume& volume, + double &greatestRatio, + const char* currentKeyword, + std::string &greatestErrorRatio){ if (volume.total != 0 && (volume.total - volume.error > getAbsTolerance()) ){ if(volume.error/volume.total > greatestRatio){ greatestRatio = volume.error/volume.total; @@ -154,7 +154,7 @@ void IntegrationTest::findGreatestErrorRatio(const WellProductionVolume& volume, } -void IntegrationTest::volumeErrorCheck(const char* keyword){ +void SummaryIntegrationTest::volumeErrorCheck(const char* keyword){ const smspec_node_type * node = ecl_sum_get_general_var_node (ecl_sum_fileShort ,keyword);//doesn't matter which ecl_sum_file one uses, the kewyord SHOULD be equal in terms of smspec data. bool hist = smspec_node_is_historical(node); /* returns true if the keyword corresponds to a summary vector "history". @@ -199,7 +199,7 @@ void IntegrationTest::volumeErrorCheck(const char* keyword){ } -void IntegrationTest::updateVolumeError(const char* keyword){ +void SummaryIntegrationTest::updateVolumeError(const char* keyword){ std::string keywordString(keyword); std::string firstFour = keywordString.substr(0,4); @@ -223,7 +223,7 @@ void IntegrationTest::updateVolumeError(const char* keyword){ } -WellProductionVolume IntegrationTest::getWellProductionVolume(const char * keyword){ +WellProductionVolume SummaryIntegrationTest::getWellProductionVolume(const char * keyword){ double total = integrate(*referenceVec, *referenceDataVec); double error = integrateError(*referenceVec, *referenceDataVec, *checkVec, *checkDataVec); @@ -239,7 +239,7 @@ WellProductionVolume IntegrationTest::getWellProductionVolume(const char * keywo } -void IntegrationTest::evaluateWellProductionVolume(){ +void SummaryIntegrationTest::evaluateWellProductionVolume(){ if(mainVariable.empty()){ double ratioWOP, ratioWWP, ratioWGP, ratioWBHP; ratioWOP = WOP.error/WOP.total; @@ -266,7 +266,7 @@ void IntegrationTest::evaluateWellProductionVolume(){ } -void IntegrationTest::checkWithSpikes(const char* keyword){ +void SummaryIntegrationTest::checkWithSpikes(const char* keyword){ int errorOccurrences = 0; size_t jvar = 0 ; bool spikeCurrent = false; @@ -295,9 +295,9 @@ void IntegrationTest::checkWithSpikes(const char* keyword){ WellProductionVolume -IntegrationTest::getSpecificWellVolume(const std::vector& timeVec1, - const std::vector& timeVec2, - const char* keyword){ +SummaryIntegrationTest::getSpecificWellVolume(const std::vector& timeVec1, + const std::vector& timeVec2, + const char* keyword){ std::vector dataVec1, dataVec2; getDataVecs(dataVec1,dataVec2,keyword); chooseReference(timeVec1, timeVec2,dataVec1,dataVec2); @@ -305,20 +305,8 @@ IntegrationTest::getSpecificWellVolume(const std::vector& timeVec1, } -#if 0 -bool IntegrationTest::checkUnits(const char * keyword){ - const smspec_node_type * node1 = ecl_sum_get_general_var_node (ecl_sum_fileShort ,keyword); - const smspec_node_type * node2 = ecl_sum_get_general_var_node (ecl_sum_fileLong ,keyword); - if(strcmp(smspec_node_get_unit(node1),smspec_node_get_unit(node2)) == 0){ - return true; - } - return false; -} -#endif - - -double IntegrationTest::integrate(const std::vector& timeVec, - const std::vector& dataVec){ +double SummaryIntegrationTest::integrate(const std::vector& timeVec, + const std::vector& dataVec){ double totalSum = 0; if(timeVec.size() != dataVec.size()){ OPM_THROW(std::runtime_error, "The size of the time vector does not match the size of the data vector."); @@ -332,10 +320,10 @@ double IntegrationTest::integrate(const std::vector& timeVec, } -double IntegrationTest::integrateError(const std::vector& timeVec1, - const std::vector& dataVec1, - const std::vector& timeVec2, - const std::vector& dataVec2){ +double SummaryIntegrationTest::integrateError(const std::vector& timeVec1, + const std::vector& dataVec1, + const std::vector& timeVec2, + const std::vector& dataVec2){ // When the data corresponds to a rate the integration will become a Riemann // sum. This function calculates the Riemann sum of the error. The reason why // a Riemann sum is used is because of the way the data is written to file. diff --git a/examples/test_util/summaryIntegrationTest.hpp b/examples/test_util/summaryIntegrationTest.hpp index f6940bb2e..be25d9382 100644 --- a/examples/test_util/summaryIntegrationTest.hpp +++ b/examples/test_util/summaryIntegrationTest.hpp @@ -35,7 +35,7 @@ struct WellProductionVolume{ }; //! \details The class inherits from the SummaryComparator class, which takes care of all file reading. \n The IntegrationTest class compares values from the two different files and throws exceptions when the deviation is unsatisfying. -class IntegrationTest: public SummaryComparator { +class SummaryIntegrationTest: public SummaryComparator { private: bool allowSpikes = false; //!< Boolean value, when true checkForSpikes is included as a sub test in the integration test. By default: false. bool findVolumeError = false; //!< Boolean value, when true volumeErrorCheck() is included as a sub test in the integration test. By default: false. @@ -124,8 +124,8 @@ class IntegrationTest: public SummaryComparator { //! \param[in] atol The absolute tolerance which is to be used in the test. //! \param[in] rtol The relative tolerance which is to be used in the test. //! \details The constructor calls the constructor of the super class. - IntegrationTest(const char* basename1, const char* basename2, - double atol, double rtol) : + SummaryIntegrationTest(const char* basename1, const char* basename2, + double atol, double rtol) : SummaryComparator(basename1, basename2, atol, rtol) {} //! \brief This function sets the private member variable allowSpikes. diff --git a/examples/test_util/summaryRegressionTest.cpp b/examples/test_util/summaryRegressionTest.cpp index 77c111738..37895d3b9 100644 --- a/examples/test_util/summaryRegressionTest.cpp +++ b/examples/test_util/summaryRegressionTest.cpp @@ -22,7 +22,7 @@ #include #include -void RegressionTest::getRegressionTest(){ +void SummaryRegressionTest::getRegressionTest(){ std::vector timeVec1, timeVec2; setTimeVecs(timeVec1, timeVec2); // Sets the time vectors, they are equal for all keywords (WPOR:PROD01 etc) setDataSets(timeVec1, timeVec2); //Figures which dataset that contains more/less values pr keyword vector. @@ -104,7 +104,7 @@ void RegressionTest::getRegressionTest(){ -void RegressionTest::getRegressionTest(const char* keyword){ +void SummaryRegressionTest::getRegressionTest(const char* keyword){ std::vector timeVec1, timeVec2; setTimeVecs(timeVec1, timeVec2); // Sets the time vectors, they are equal for all keywords (WPOR:PROD01 etc) setDataSets(timeVec1, timeVec2); //Figures which dataset that contains more/less values pr keyword vector. @@ -126,7 +126,7 @@ void RegressionTest::getRegressionTest(const char* keyword){ -bool RegressionTest::checkDeviation(Deviation deviation, const char* keyword, int refIndex, int checkIndex){ +bool SummaryRegressionTest::checkDeviation(Deviation deviation, const char* keyword, int refIndex, int checkIndex){ double absTol = getAbsTolerance(); double relTol = getRelTolerance(); @@ -149,7 +149,7 @@ bool RegressionTest::checkDeviation(Deviation deviation, const char* keyword, in -bool RegressionTest::checkForKeyword(std::vector& timeVec1, std::vector& timeVec2, const char* keyword){ +bool SummaryRegressionTest::checkForKeyword(std::vector& timeVec1, std::vector& timeVec2, const char* keyword){ std::vector dataVec1, dataVec2; getDataVecs(dataVec1,dataVec2,keyword); chooseReference(timeVec1, timeVec2,dataVec1,dataVec2); @@ -158,7 +158,7 @@ bool RegressionTest::checkForKeyword(std::vector& timeVec1, std::vector< -bool RegressionTest::startTest(const char* keyword){ +bool SummaryRegressionTest::startTest(const char* keyword){ size_t jvar = 0; Deviation deviation; bool result = true; diff --git a/examples/test_util/summaryRegressionTest.hpp b/examples/test_util/summaryRegressionTest.hpp index c5247fa85..5e0dd6027 100644 --- a/examples/test_util/summaryRegressionTest.hpp +++ b/examples/test_util/summaryRegressionTest.hpp @@ -23,7 +23,7 @@ #include "summaryComparator.hpp" //! \details The class inherits from the SummaryComparator class, which takes care of all file reading. \n The RegressionTest class compares the values from the two different files and throws exceptions when the deviation is unsatisfying. -class RegressionTest: public SummaryComparator { +class SummaryRegressionTest: public SummaryComparator { private: //! \brief Gathers the correct data for comparison for a specific keyword //! \param[in] timeVec1 The time steps of file 1. @@ -55,7 +55,9 @@ class RegressionTest: public SummaryComparator { //! \param[in] relativeTol The relative tolerance which is to be used in the test. //! \param[in] absoluteTol The absolute tolerance which is to be used in the test. //! \details The constructor calls the constructor of the super class. - RegressionTest(const char* basename1, const char* basename2, double relativeTol, double absoluteTol): + SummaryRegressionTest(const char* basename1, + const char* basename2, + double relativeTol, double absoluteTol) : SummaryComparator(basename1, basename2, relativeTol, absoluteTol) {} //! \details The function executes a regression test for all the keywords. If the two files do not match in amount of keywords, an exception is thrown. diff --git a/tests/test_compareSummary.cpp b/tests/test_compareSummary.cpp index e4373cb3f..29b08572c 100644 --- a/tests/test_compareSummary.cpp +++ b/tests/test_compareSummary.cpp @@ -42,9 +42,9 @@ BOOST_AUTO_TEST_CASE(area) { double width2 = 2; double width3 = 10; - double area1 = IntegrationTest::getRectangleArea(1,width2); - double area2 = IntegrationTest::getRectangleArea(10,width1); - double area3 = IntegrationTest::getRectangleArea(4,width3); + double area1 = SummaryIntegrationTest::getRectangleArea(1,width2); + double area2 = SummaryIntegrationTest::getRectangleArea(10,width1); + double area3 = SummaryIntegrationTest::getRectangleArea(4,width3); BOOST_CHECK_EQUAL(area1,2); BOOST_CHECK_EQUAL(area2,0); @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(integration) { std::vector data1 = {2,2,2,2,2,2}; std::vector time1 = {0,1,2,3,4,5}; - double val1 = IntegrationTest::integrate(time1, data1); + double val1 = SummaryIntegrationTest::integrate(time1, data1); std::vector data2 = {3, 3, 4, 3, 2, 1, 0, 4}; std::vector time2 = {0, 0.5, 1, 2, 3, 3.5, 4.5, 5}; @@ -83,10 +83,10 @@ BOOST_AUTO_TEST_CASE(integration) { std::vector data5 = {0, 4, 3, 2, 5, 6, 3, 1, 0, 4, 2, 1}; std::vector time5 = {0, 0.5, 1, 2.5, 3, 4, 4.5, 6, 7.5,8, 9.5 ,10}; - double val2 = IntegrationTest::integrateError(time1, data1, time2, data2); - double val3 = IntegrationTest::integrateError(time1, data1, time2, data3); - double val4 = IntegrationTest::integrateError(time1, data1, time1, data1); - double val5 = IntegrationTest::integrateError(time4, data4, time5, data5); + double val2 = SummaryIntegrationTest::integrateError(time1, data1, time2, data2); + double val3 = SummaryIntegrationTest::integrateError(time1, data1, time2, data3); + double val4 = SummaryIntegrationTest::integrateError(time1, data1, time1, data1); + double val5 = SummaryIntegrationTest::integrateError(time4, data4, time5, data5); BOOST_CHECK_EQUAL(val1,10); BOOST_CHECK_EQUAL(val2,6); BOOST_CHECK_EQUAL(val3,10);