/* + 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 . + */ #include "config.h" #include #include #define BOOST_TEST_MODULE CalculationTest #include BOOST_AUTO_TEST_CASE(deviation){ double a = 5; double b = 10; const double tol = 1.0e-14; Deviation dev = SummaryComparator::calculateDeviations(a,b); BOOST_CHECK_EQUAL(dev.abs, 5); BOOST_CHECK_CLOSE(dev.rel, 5.0/10.0, tol); } BOOST_AUTO_TEST_CASE(area) { double width1 = 0; double width2 = 2; double width3 = 10; double area1 = IntegrationTest::getRectangleArea(1,width2); double area2 = IntegrationTest::getRectangleArea(10,width1); double area3 = IntegrationTest::getRectangleArea(4,width3); BOOST_CHECK_EQUAL(area1,2); BOOST_CHECK_EQUAL(area2,0); BOOST_CHECK_EQUAL(area3,40); } BOOST_AUTO_TEST_CASE(operatorOverload) { WellProductionVolume volumeA; WellProductionVolume volumeB; volumeA.total = 2; volumeA.error = 2; volumeB.total = 3; volumeB.error = 1; volumeA += volumeB; BOOST_CHECK_EQUAL(volumeA.total,5); BOOST_CHECK_EQUAL(volumeA.error,3); } 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); 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}; std::vector data3 = {0, 0, 0, 0, 0, 0, 0, 0}; std::vector data4 = {0, 1, 4, 1, 2, 4, 0, 2, 5, 6, 3}; std::vector time4 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10}; 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); BOOST_CHECK_EQUAL(val1,10); BOOST_CHECK_EQUAL(val2,6); BOOST_CHECK_EQUAL(val3,10); BOOST_CHECK_EQUAL(val4,0); BOOST_CHECK_EQUAL(val5,24.5); }