added: fmt formatter for Evaluation
and a simple test
This commit is contained in:
58
tests/test_EvaluationFormat.cpp
Normal file
58
tests/test_EvaluationFormat.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
#define BOOST_TEST_MODULE EVALUATION_FORMAT_TESTS
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/material/densead/EvaluationFormat.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestEvaluation2)
|
||||
{
|
||||
Opm::DenseAd::Evaluation<double,2> ev2;
|
||||
ev2.setValue(1.0);
|
||||
ev2.setDerivative(0, 2.0);
|
||||
ev2.setDerivative(1, 3.0);
|
||||
|
||||
std::string s2 = fmt::format("{}", ev2);
|
||||
std::string f2 = fmt::format("{:.2f}", ev2);
|
||||
std::string e2 = fmt::format("{:.1e}", ev2);
|
||||
|
||||
BOOST_CHECK(s2 == "v: 1 / d: [2, 3]");
|
||||
BOOST_CHECK(f2 == "v: 1.00 / d: [2.00, 3.00]");
|
||||
BOOST_CHECK(e2 == "v: 1.0e+00 / d: [2.0e+00, 3.0e+00]");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestEvaluation3)
|
||||
{
|
||||
Opm::DenseAd::Evaluation<double,3> ev3;
|
||||
ev3.setValue(1.0);
|
||||
ev3.setDerivative(0, 2.0);
|
||||
ev3.setDerivative(1, 3.0);
|
||||
ev3.setDerivative(2, 4.0);
|
||||
|
||||
std::string s3 = fmt::format("{}", ev3);
|
||||
std::string f3 = fmt::format("{:.2f}", ev3);
|
||||
std::string e3 = fmt::format("{:.1e}", ev3);
|
||||
|
||||
BOOST_CHECK(s3 == "v: 1 / d: [2, 3, 4]");
|
||||
BOOST_CHECK(f3 == "v: 1.00 / d: [2.00, 3.00, 4.00]");
|
||||
BOOST_CHECK(e3 == "v: 1.0e+00 / d: [2.0e+00, 3.0e+00, 4.0e+00]");
|
||||
}
|
||||
Reference in New Issue
Block a user