opm-common/tests/test_EclFilesComparator.cpp

73 lines
1.8 KiB
C++
Raw Normal View History

/*
Copyright 2016 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#if HAVE_DYNAMIC_BOOST_TEST
#define BOOST_TEST_DYN_LINK
#endif
#define BOOST_TEST_MODULE EclFilesComparatorTest
#include <boost/test/unit_test.hpp>
#include <opm/test_util/EclFilesComparator.hpp>
BOOST_AUTO_TEST_CASE(deviation) {
double a = 1;
double b = 3;
const double tol = 1.0e-14;
Deviation dev = ECLFilesComparator::calculateDeviations(a,b);
BOOST_CHECK_EQUAL(dev.abs, 2.0);
BOOST_CHECK_CLOSE(dev.rel, 2.0/3, tol);
a = 0;
dev = ECLFilesComparator::calculateDeviations(a,b);
BOOST_CHECK_EQUAL(dev.abs, 3.0);
BOOST_CHECK_EQUAL(dev.rel, -1);
}
BOOST_AUTO_TEST_CASE(median) {
std::vector<double> vec = {1,3,4,5};
double median = ECLFilesComparator::median(vec);
BOOST_CHECK_EQUAL(median, 3.5);
vec = {1,4,5};
median = ECLFilesComparator::median(vec);
BOOST_CHECK_EQUAL(median, 4);
}
BOOST_AUTO_TEST_CASE(average) {
std::vector<double> vec = {1,3,4,5};
const double tol = 1.0e-14;
double average = ECLFilesComparator::average(vec);
BOOST_CHECK_CLOSE(average, 13.0/4, tol);
}