From 477fa5a9887285ea849937d24fcba24f079b99bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Wed, 24 May 2017 14:48:27 +0200 Subject: [PATCH] Combine test files, reduce number of targets In an effort to reduce the numbers of targets built, and consequently the repeated work and overhead of compiling boost test, a series of test programs are combined to larger modules. Every target typically has a constant cost of 3-6s, depending on the computer, just for the make to set up dependencies and for the compiler to parse and compile the testing framework and other dependencies. Each set of tests typically add very little, so significant savings are achieved by merging targets. When tested on a 2015 i5m laptop, this reduced serial, single-core compile time from ~14m45s to ~11m15s. --- src/opm/parser/eclipse/CMakeLists.txt | 53 +- .../eclipse/IntegrationTests/ParseCECON.cpp | 38 - .../IntegrationTests/ParseCOORDSYS.cpp | 54 - .../eclipse/IntegrationTests/ParseDEBUG.cpp | 33 - .../eclipse/IntegrationTests/ParseDENSITY.cpp | 63 - .../eclipse/IntegrationTests/ParseEND.cpp | 60 - .../eclipse/IntegrationTests/ParseEQUIL.cpp | 89 - .../eclipse/IntegrationTests/ParseGRUPRIG.cpp | 41 - .../eclipse/IntegrationTests/ParseKEYWORD.cpp | 1383 +++++++++++++++ .../eclipse/IntegrationTests/ParseLGR.cpp | 33 - .../IntegrationTests/ParseMULTREGT.cpp | 101 -- .../IntegrationTests/ParseMULTSEGWELL.cpp | 164 -- .../IntegrationTests/ParseMiscible.cpp | 266 --- .../eclipse/IntegrationTests/ParsePLYADS.cpp | 49 - .../eclipse/IntegrationTests/ParsePLYADSS.cpp | 41 - .../IntegrationTests/ParsePLYDHFLF.cpp | 47 - .../IntegrationTests/ParsePLYSHLOG.cpp | 63 - .../eclipse/IntegrationTests/ParsePLYVISC.cpp | 46 - .../eclipse/IntegrationTests/ParsePORO.cpp | 69 - .../eclipse/IntegrationTests/ParsePRORDER.cpp | 43 - .../eclipse/IntegrationTests/ParsePVTG.cpp | 130 -- .../eclipse/IntegrationTests/ParsePVTO.cpp | 119 -- .../eclipse/IntegrationTests/ParseRSVD.cpp | 51 - .../eclipse/IntegrationTests/ParseSGOF.cpp | 70 - .../eclipse/IntegrationTests/ParseSLGOF.cpp | 71 - .../eclipse/IntegrationTests/ParseSWOF.cpp | 89 - .../eclipse/IntegrationTests/ParseTITLE.cpp | 56 - .../eclipse/IntegrationTests/ParseTOPS.cpp | 62 - .../eclipse/IntegrationTests/ParseTRACERS.cpp | 39 - .../IntegrationTests/ParseTUNINGDP.cpp | 54 - .../eclipse/IntegrationTests/ParseTVDP.cpp | 44 - .../eclipse/IntegrationTests/ParseTVPD.cpp | 37 - .../eclipse/IntegrationTests/ParseVFPPROD.cpp | 165 -- .../IntegrationTests/ParseWCONHIST.cpp | 63 - .../IntegrationTests/ParseWDFACCOR.cpp | 39 - .../eclipse/IntegrationTests/ParseWEFAC.cpp | 40 - .../eclipse/IntegrationTests/ParseWORKLIM.cpp | 38 - .../IntegrationTests/ParseWellProbe.cpp | 52 - .../ParseWellWithWildcards.cpp | 109 -- tests/parser/BoxManagerTests.cpp | 85 - tests/parser/BoxTests.cpp | 75 +- tests/parser/CompletionTests.cpp | 83 + tests/parser/DeckDoubleItemTests.cpp | 164 -- tests/parser/DeckIntItemTests.cpp | 125 -- tests/parser/DeckKeywordTests.cpp | 82 - tests/parser/DeckRecordTests.cpp | 102 -- tests/parser/DeckStringItemTests.cpp | 91 - tests/parser/DeckTests.cpp | 398 ++++- tests/parser/GridPropertiesTests.cpp | 98 -- tests/parser/GridPropertyTests.cpp | 59 + tests/parser/GroupTests.cpp | 63 +- tests/parser/GroupTreeTests.cpp | 80 - tests/parser/ParserEnumTests.cpp | 123 -- tests/parser/ParserItemTests.cpp | 611 ------- tests/parser/ParserKeywordTests.cpp | 512 ------ tests/parser/ParserRecordTests.cpp | 373 ----- tests/parser/ParserTests.cpp | 1478 ++++++++++++++++- tests/parser/RawKeywordTests.cpp | 72 + tests/parser/RawRecordTests.cpp | 97 -- tests/parser/ScheduleEnumTests.cpp | 433 ----- tests/parser/ScheduleTests.cpp | 407 +++++ tests/parser/StringTests.cpp | 96 ++ tests/parser/StringviewTests.cpp | 106 -- tests/parser/WellPropertiesTests.cpp | 237 --- tests/parser/WellTests.cpp | 205 +++ 65 files changed, 4292 insertions(+), 6027 deletions(-) delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseCECON.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseCOORDSYS.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseDEBUG.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseDENSITY.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseEND.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseEQUIL.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseGRUPRIG.cpp create mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseKEYWORD.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseLGR.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseMULTREGT.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseMULTSEGWELL.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseMiscible.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParsePLYADS.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParsePLYADSS.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParsePLYDHFLF.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParsePLYSHLOG.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParsePLYVISC.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParsePORO.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParsePRORDER.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParsePVTG.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParsePVTO.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseRSVD.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseSGOF.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseSLGOF.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseSWOF.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseTITLE.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseTOPS.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseTRACERS.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseTUNINGDP.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseTVDP.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseTVPD.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseVFPPROD.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseWCONHIST.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseWDFACCOR.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseWEFAC.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseWORKLIM.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseWellProbe.cpp delete mode 100644 src/opm/parser/eclipse/IntegrationTests/ParseWellWithWildcards.cpp delete mode 100644 tests/parser/BoxManagerTests.cpp delete mode 100644 tests/parser/DeckDoubleItemTests.cpp delete mode 100644 tests/parser/DeckIntItemTests.cpp delete mode 100644 tests/parser/DeckKeywordTests.cpp delete mode 100644 tests/parser/DeckRecordTests.cpp delete mode 100644 tests/parser/DeckStringItemTests.cpp delete mode 100644 tests/parser/GridPropertiesTests.cpp delete mode 100644 tests/parser/GroupTreeTests.cpp delete mode 100644 tests/parser/ParserEnumTests.cpp delete mode 100644 tests/parser/ParserItemTests.cpp delete mode 100644 tests/parser/ParserKeywordTests.cpp delete mode 100644 tests/parser/ParserRecordTests.cpp delete mode 100644 tests/parser/RawRecordTests.cpp delete mode 100644 tests/parser/ScheduleEnumTests.cpp delete mode 100644 tests/parser/StringviewTests.cpp delete mode 100644 tests/parser/WellPropertiesTests.cpp diff --git a/src/opm/parser/eclipse/CMakeLists.txt b/src/opm/parser/eclipse/CMakeLists.txt index 3f93f9f28..e38e4c980 100644 --- a/src/opm/parser/eclipse/CMakeLists.txt +++ b/src/opm/parser/eclipse/CMakeLists.txt @@ -195,18 +195,11 @@ add_test(NAME EclipseStateTests COMMAND EclipseStateTests ${_testdir}/integration_tests/) foreach(test ADDREGTests - BoxManagerTests BoxTests ColumnSchemaTests - CompletionSetTests CompletionTests COMPSEGUnits CopyRegTests - DeckDoubleItemTests - DeckIntItemTests - DeckKeywordTests - DeckRecordTests - DeckStringItemTests DeckTests DynamicStateTests DynamicVectorTests @@ -218,10 +211,8 @@ foreach(test ADDREGTests FaultTests FunctionalTests GeomodifierTests - GridPropertiesTests GridPropertyTests GroupTests - GroupTreeTests InitConfigTest IOConfigTests MessageContainerTest @@ -230,24 +221,17 @@ foreach(test ADDREGTests MULTREGTScannerTests OrderedMapTests ParseContextTests - ParserEnumTests - ParserItemTests - ParserKeywordTests - ParserRecordTests PORVTests RawKeywordTests - RawRecordTests RestartConfigTests RunspecTests SatfuncPropertyInitializersTests - ScheduleEnumTests ScheduleTests SectionTests SimpleTableTests SimulationConfigTest StarTokenTests StringTests - StringviewTests SummaryConfigTests TabdimsTests TableColumnTests @@ -260,7 +244,6 @@ foreach(test ADDREGTests TuningTests UnitTests ValueTests - WellPropertiesTests WellSolventTests WellTests ) @@ -277,42 +260,8 @@ foreach (test BoxTest IntegrationTests IOConfigIntegrationTest NNCTests - ParseCECON - ParseCOORDSYS + ParseKEYWORD ParseDATAWithDefault - ParseDEBUG - ParseDENSITY - ParseEND - ParseEQUIL - ParseGRUPRIG - ParseLGR - ParseMiscible - ParseMULTREGT - ParseMULTSEGWELL - ParsePLYADSS - ParsePLYDHFLF - ParsePLYSHLOG - ParsePLYVISC - ParsePORO - ParsePRORDER - ParsePVTG - ParsePVTO - ParseRSVD - ParseSGOF - ParseSLGOF - ParseSWOF - ParseTITLE - ParseTOPS - ParseTRACERS - ParseTUNINGDP - ParseTVDP - ParseVFPPROD - ParseWCONHIST - ParseWDFACCOR - ParseWEFAC - ParseWellProbe - ParseWellWithWildcards - ParseWORKLIM Polymer ResinsightTest ScheduleCreateFromDeck diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseCECON.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseCECON.cpp deleted file mode 100644 index 85ecda5c8..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseCECON.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - 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 - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE( parse_CECON ) { - const std::string input = R"( -CECON - PROD1 4* 0.7 / - 'P*' 2* 2 2 1* 3.5 / -/ - )"; - Parser().parseString( input ); -} - diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseCOORDSYS.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseCOORDSYS.cpp deleted file mode 100644 index a1109f452..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseCOORDSYS.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - 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 - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE( parse_COORDSYS ) { - const std::string input = R"( - -RUNSPEC - -NUMRES - 1 / - -GRID - -COORDSYS - 1 1141 / - -COORDSYS - 1 1141 'COMP' 'JOIN' 1 2 / - -COORDSYS - 1 1141 'COMP' 'JOIN' / - -COORDSYS - 1 1141 'INCOMP' / - -)"; - Parser().parseString( input ); -} - diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseDEBUG.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseDEBUG.cpp deleted file mode 100644 index 58450d6fd..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseDEBUG.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( parse_DEBUG ) { - Parser().parseFile( pathprefix() + "DEBUG/DEBUG.DATA" ); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseDENSITY.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseDENSITY.cpp deleted file mode 100644 index b6b3f41ba..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseDENSITY.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE(ParseDENSITY) { - Parser parser; - std::string file(pathprefix() + "DENSITY/DENSITY1"); - auto deck = parser.parseFile(file, ParseContext()); - const auto& densityKw = deck.getKeyword("DENSITY" , 0); - - - BOOST_CHECK_EQUAL( 2U , densityKw.size()); - const auto& rec1 = densityKw.getRecord(0); - - { - const auto& oilDensity = rec1.getItem("OIL"); - const auto& waterDensity = rec1.getItem("WATER"); - const auto& gasDensity = rec1.getItem("GAS"); - - BOOST_CHECK_CLOSE( 500 * Field::Density , oilDensity.getSIDouble(0) , 0.001); - BOOST_CHECK_CLOSE( 1000 * Field::Density , waterDensity.getSIDouble(0) , 0.001); - BOOST_CHECK_CLOSE( 1 * Field::Density , gasDensity.getSIDouble(0) , 0.001); - } - -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseEND.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseEND.cpp deleted file mode 100644 index 62ff5477a..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseEND.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include -#include - -#include -#include - -#include -#include -#include - -#include - -using namespace Opm; - -inline std::string prefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( parse_END_OK ) { - Parser parser; - std::string fileWithTitleKeyword(prefix() + "END/END1.txt"); - auto deck = parser.parseFile(fileWithTitleKeyword, ParseContext()); - - BOOST_CHECK_EQUAL(size_t(1), deck.size()); - BOOST_CHECK_EQUAL (true, deck.hasKeyword("OIL")); - BOOST_CHECK_EQUAL (false, deck.hasKeyword("GAS")); - BOOST_CHECK_EQUAL (false, deck.hasKeyword("END")); -} - -BOOST_AUTO_TEST_CASE( parse_ENDINC_OK ) { - Parser parser; - std::string fileWithTitleKeyword(prefix() + "END/ENDINC1.txt"); - auto deck = parser.parseFile(fileWithTitleKeyword, ParseContext()); - - BOOST_CHECK_EQUAL(size_t(1), deck.size()); - BOOST_CHECK_EQUAL (true, deck.hasKeyword("OIL")); - BOOST_CHECK_EQUAL (false, deck.hasKeyword("GAS")); - BOOST_CHECK_EQUAL (false, deck.hasKeyword("ENDINC")); -} - diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseEQUIL.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseEQUIL.cpp deleted file mode 100644 index 714f8d0eb..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseEQUIL.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -using namespace Opm; - -inline std::string prefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( parse_EQUIL_MISSING_DIMS ) { - Parser parser; - ParseContext parseContext; - parseContext.update(ParseContext::PARSE_MISSING_DIMS_KEYWORD, InputError::IGNORE); - const std::string equil = "EQUIL\n" - "2469 382.4 1705.0 0.0 500 0.0 1 1 20 /"; - auto deck = parser.parseString(equil, parseContext); - const auto& kw1 = deck.getKeyword("EQUIL" , 0); - BOOST_CHECK_EQUAL( 1U , kw1.size() ); - - const auto& rec1 = kw1.getRecord(0); - const auto& item1 = rec1.getItem("OWC"); - const auto& item1_index = rec1.getItem(2); - - BOOST_CHECK_EQUAL( &item1 , &item1_index ); - BOOST_CHECK( fabs(item1.getSIDouble(0) - 1705) < 0.001); - -} - - -BOOST_AUTO_TEST_CASE( parse_EQUIL_OK ) { - Parser parser; - std::string pvtgFile(prefix() + "EQUIL/EQUIL1"); - auto deck = parser.parseFile(pvtgFile, ParseContext()); - const auto& kw1 = deck.getKeyword("EQUIL" , 0); - BOOST_CHECK_EQUAL( 3U , kw1.size() ); - - const auto& rec1 = kw1.getRecord(0); - BOOST_CHECK_EQUAL( 9U , rec1.size() ); - - const auto& rec2 = kw1.getRecord(1); - BOOST_CHECK_EQUAL( 9U , rec2.size() ); - - const auto& rec3 = kw1.getRecord(2); - BOOST_CHECK_EQUAL( 9U , rec3.size() ); - - const auto& item1 = rec1.getItem("OWC"); - const auto& item1_index = rec1.getItem(2); - - BOOST_CHECK_EQUAL( &item1 , &item1_index ); - BOOST_CHECK( fabs(item1.getSIDouble(0) - 1705) < 0.001); - - const auto& item3 = rec3.getItem("OWC"); - const auto& item3_index = rec3.getItem(2); - - BOOST_CHECK_EQUAL( &item3 , &item3_index ); - BOOST_CHECK( fabs(item3.getSIDouble(0) - 3000) < 0.001); - -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseGRUPRIG.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseGRUPRIG.cpp deleted file mode 100644 index 46f501a61..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseGRUPRIG.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - 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 - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE( parse_GRUPRIG ) { - const std::string input = R"( --- --- GRUP WORK DRILL RIG --- NAME RIG RIG OPTN -GRUPRIG - 'FIELD' 1 1 ADD / - 'FIELD' 2* REMOVE / -/ - )"; - Parser().parseString( input ); -} - diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseKEYWORD.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseKEYWORD.cpp new file mode 100644 index 000000000..35dc4c01e --- /dev/null +++ b/src/opm/parser/eclipse/IntegrationTests/ParseKEYWORD.cpp @@ -0,0 +1,1383 @@ +/* + Copyright 2017 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 . + */ + +#define BOOST_TEST_MODULE ParserKeywordsIntegrationTests +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace Opm; + +inline std::string pathprefix() { + return boost::unit_test::framework::master_test_suite().argv[1]; +} + +BOOST_AUTO_TEST_CASE( DEBUG ) { + Parser().parseFile( pathprefix() + "DEBUG/DEBUG.DATA" ); +} + +BOOST_AUTO_TEST_CASE( CECON ) { + const std::string input = R"( +CECON + PROD1 4* 0.7 / + 'P*' 2* 2 2 1* 3.5 / +/ + )"; + Parser().parseString( input ); +} + +BOOST_AUTO_TEST_CASE( COORDSYS ) { + const std::string input = R"( +RUNSPEC + NUMRES + 1 / +GRID + COORDSYS + 1 1141 / + COORDSYS + 1 1141 'COMP' 'JOIN' 1 2 / + COORDSYS + 1 1141 'COMP' 'JOIN' / + COORDSYS + 1 1141 'INCOMP' / +)"; + Parser().parseString( input ); +} + +BOOST_AUTO_TEST_CASE( DENSITY ) { + Parser parser; + std::string file(pathprefix() + "DENSITY/DENSITY1"); + auto deck = parser.parseFile(file, ParseContext()); + const auto& densityKw = deck.getKeyword("DENSITY" , 0); + + + BOOST_CHECK_EQUAL( 2U , densityKw.size()); + const auto& rec1 = densityKw.getRecord(0); + + const auto& oilDensity = rec1.getItem("OIL"); + const auto& waterDensity = rec1.getItem("WATER"); + const auto& gasDensity = rec1.getItem("GAS"); + + const auto density = Field::Density; + BOOST_CHECK_CLOSE( 500 * density, oilDensity.getSIDouble(0), 0.001 ); + BOOST_CHECK_CLOSE( 1000 * density, waterDensity.getSIDouble(0), 0.001 ); + BOOST_CHECK_CLOSE( 1 * density, gasDensity.getSIDouble(0), 0.001 ); +} + +BOOST_AUTO_TEST_CASE( END ) { + Parser parser; + std::string fileWithTitleKeyword = pathprefix() + "END/END1.txt"; + auto deck = parser.parseFile(fileWithTitleKeyword, ParseContext()); + + BOOST_CHECK_EQUAL(size_t(1), deck.size()); + BOOST_CHECK_EQUAL(true, deck.hasKeyword("OIL")); + BOOST_CHECK_EQUAL(false, deck.hasKeyword("GAS")); + BOOST_CHECK_EQUAL(false, deck.hasKeyword("END")); +} + +BOOST_AUTO_TEST_CASE( ENDINC ) { + Parser parser; + std::string fileWithTitleKeyword(pathprefix() + "END/ENDINC1.txt"); + auto deck = parser.parseFile(fileWithTitleKeyword, ParseContext()); + + BOOST_CHECK_EQUAL(size_t(1), deck.size()); + BOOST_CHECK_EQUAL(true, deck.hasKeyword("OIL")); + BOOST_CHECK_EQUAL(false, deck.hasKeyword("GAS")); + BOOST_CHECK_EQUAL(false, deck.hasKeyword("ENDINC")); +} + +BOOST_AUTO_TEST_CASE( EQUIL_MISSING_DIMS ) { + Parser parser; + ParseContext parseContext; + parseContext.update(ParseContext::PARSE_MISSING_DIMS_KEYWORD, InputError::IGNORE); + const std::string equil = "EQUIL\n" + "2469 382.4 1705.0 0.0 500 0.0 1 1 20 /"; + auto deck = parser.parseString(equil, parseContext); + const auto& kw1 = deck.getKeyword("EQUIL" , 0); + BOOST_CHECK_EQUAL( 1U , kw1.size() ); + + const auto& rec1 = kw1.getRecord(0); + const auto& item1 = rec1.getItem("OWC"); + const auto& item1_index = rec1.getItem(2); + + BOOST_CHECK_EQUAL( &item1 , &item1_index ); + BOOST_CHECK( fabs(item1.getSIDouble(0) - 1705) < 0.001); +} + + +BOOST_AUTO_TEST_CASE( EQUIL ) { + Parser parser; + std::string pvtgFile(pathprefix() + "EQUIL/EQUIL1"); + auto deck = parser.parseFile(pvtgFile, ParseContext()); + const auto& kw1 = deck.getKeyword("EQUIL" , 0); + BOOST_CHECK_EQUAL( 3U , kw1.size() ); + + const auto& rec1 = kw1.getRecord(0); + BOOST_CHECK_EQUAL( 9U , rec1.size() ); + + const auto& rec2 = kw1.getRecord(1); + BOOST_CHECK_EQUAL( 9U , rec2.size() ); + + const auto& rec3 = kw1.getRecord(2); + BOOST_CHECK_EQUAL( 9U , rec3.size() ); + + const auto& item1 = rec1.getItem("OWC"); + const auto& item1_index = rec1.getItem(2); + + BOOST_CHECK_EQUAL( &item1 , &item1_index ); + BOOST_CHECK( fabs(item1.getSIDouble(0) - 1705) < 0.001 ); + + const auto& item3 = rec3.getItem("OWC"); + const auto& item3_index = rec3.getItem(2); + + BOOST_CHECK_EQUAL( &item3 , &item3_index ); + BOOST_CHECK( fabs(item3.getSIDouble(0) - 3000) < 0.001 ); +} + +BOOST_AUTO_TEST_CASE( GRUPRIG ) { + const std::string input = R"( +-- GRUP WORK DRILL RIG +-- NAME RIG RIG OPTN +GRUPRIG + 'FIELD' 1 1 ADD / + 'FIELD' 2* REMOVE / +/ + )"; + Parser().parseString( input ); +} + +BOOST_AUTO_TEST_CASE( LGR ) { + Parser().parseFile( pathprefix() + "LGR/LGR.DATA" ); +} + +const std::string miscibleData = R"( +MISCIBLE + 2 3 / +)"; + +const std::string miscibleTightData = R"( +MISCIBLE + 1 2 / +)"; + +const std::string sorwmisData = R"( +SORWMIS + .00 .00 + .50 .00 + 1.0 .00 / + .00 .00 + .30 .20 + 1.0 .80 / +)"; + +const std::string sgcwmisData = R"( +SGCWMIS + .00 .00 + .20 .00 + 1.0 .00 / + .00 .00 + .80 .20 + 1.0 .70 / +)"; + +BOOST_AUTO_TEST_CASE( SORWMIS ) { + + Parser parser; + // missing miscible keyword + BOOST_CHECK_THROW (parser.parseString(sorwmisData, ParseContext()), std::invalid_argument ); + + //too many tables + BOOST_CHECK_THROW( parser.parseString(miscibleTightData + sorwmisData, ParseContext()), std::invalid_argument); + + auto deck1 = parser.parseString(miscibleData + sorwmisData, ParseContext()); + + const auto& sorwmis = deck1.getKeyword("SORWMIS"); + const auto& miscible = deck1.getKeyword("MISCIBLE"); + + const auto& miscible0 = miscible.getRecord(0); + const auto& sorwmis0 = sorwmis.getRecord(0); + const auto& sorwmis1 = sorwmis.getRecord(1); + + // test number of columns + size_t ntmisc = miscible0.getItem(0).get< int >(0); + Opm::SorwmisTable sorwmisTable0(sorwmis0.getItem(0)); + BOOST_CHECK_EQUAL(sorwmisTable0.numColumns(),ntmisc); + + // test table input 1 + BOOST_CHECK_EQUAL(3U, sorwmisTable0.getWaterSaturationColumn().size()); + BOOST_CHECK_EQUAL(1.0, sorwmisTable0.getWaterSaturationColumn()[2]); + BOOST_CHECK_EQUAL(0.0, sorwmisTable0.getMiscibleResidualOilColumn()[2]); + + // test table input 2 + Opm::SorwmisTable sorwmisTable1(sorwmis1.getItem(0)); + BOOST_CHECK_EQUAL(sorwmisTable1.numColumns(),ntmisc); + + BOOST_CHECK_EQUAL(3U, sorwmisTable1.getWaterSaturationColumn().size()); + BOOST_CHECK_EQUAL(0.3, sorwmisTable1.getWaterSaturationColumn()[1]); + BOOST_CHECK_EQUAL(0.8, sorwmisTable1.getMiscibleResidualOilColumn()[2]); +} + +BOOST_AUTO_TEST_CASE( SGCWMIS ) { + Parser parser; + auto deck1 = parser.parseString(miscibleData + sgcwmisData, ParseContext()); + + const auto& sgcwmis = deck1.getKeyword("SGCWMIS"); + const auto& miscible = deck1.getKeyword("MISCIBLE"); + + const auto& miscible0 = miscible.getRecord(0); + const auto& sgcwmis0 = sgcwmis.getRecord(0); + const auto& sgcwmis1 = sgcwmis.getRecord(1); + + // test number of columns + size_t ntmisc = miscible0.getItem(0).get< int >(0); + Opm::SgcwmisTable sgcwmisTable0(sgcwmis0.getItem(0)); + BOOST_CHECK_EQUAL(sgcwmisTable0.numColumns(),ntmisc); + + // test table input 1 + BOOST_CHECK_EQUAL(3U, sgcwmisTable0.getWaterSaturationColumn().size()); + BOOST_CHECK_EQUAL(0.2, sgcwmisTable0.getWaterSaturationColumn()[1]); + BOOST_CHECK_EQUAL(0.0, sgcwmisTable0.getMiscibleResidualGasColumn()[1]); + + // test table input 2 + Opm::SgcwmisTable sgcwmisTable1(sgcwmis1.getItem(0)); + BOOST_CHECK_EQUAL(sgcwmisTable1.numColumns(),ntmisc); + + BOOST_CHECK_EQUAL(3U, sgcwmisTable1.getWaterSaturationColumn().size()); + BOOST_CHECK_EQUAL(0.8, sgcwmisTable1.getWaterSaturationColumn()[1]); + BOOST_CHECK_EQUAL(0.2, sgcwmisTable1.getMiscibleResidualGasColumn()[1]); +} + +const std::string miscData = R"( +MISCIBLE + 1 3 / + +MISC + 0.0 0.0 + 0.1 0.5 + 1.0 1.0 / +)"; + +const std::string miscOutOfRangeData = R"( +MISCIBLE + 1 3 / + +MISC + 0.0 0.0 + 1.0 0.5 + 2.0 1.0 / +)"; + +const std::string miscTooSmallRangeData = R"( +MISCIBLE + 1 3 / + +MISC + 0.0 0.0 + 1.0 0.5 / +)"; + +BOOST_AUTO_TEST_CASE( MISC ) { + Parser parser; + + // out of range MISC keyword + auto deck1 = parser.parseString(miscOutOfRangeData, ParseContext()); + const auto& item = deck1.getKeyword("MISC").getRecord(0).getItem(0); + Opm::MiscTable miscTable1(item); + + // too litle range of MISC keyword + auto deck2 = parser.parseString(miscTooSmallRangeData, ParseContext()); + const auto& item2 = deck2.getKeyword("MISC").getRecord(0).getItem(0); + Opm::MiscTable miscTable2(item2); + + // test table input + auto deck3 = parser.parseString(miscData, ParseContext()); + const auto& item3 = deck3.getKeyword("MISC").getRecord(0).getItem(0); + Opm::MiscTable miscTable3(item3); + BOOST_CHECK_EQUAL(3U, miscTable3.getSolventFractionColumn().size()); + BOOST_CHECK_EQUAL(0.1, miscTable3.getSolventFractionColumn()[1]); + BOOST_CHECK_EQUAL(0.5, miscTable3.getMiscibilityColumn()[1]); +} + +const std::string pmiscData = R"( +MISCIBLE + 1 3 / + +PMISC + 100 0.0 + 200 0.5 + 500 1.0 / +)"; + +BOOST_AUTO_TEST_CASE( PMISC ) { + Parser parser; + auto deck = parser.parseString(pmiscData, ParseContext()); + Opm::PmiscTable pmiscTable(deck.getKeyword("PMISC").getRecord(0).getItem(0)); + BOOST_CHECK_EQUAL(3U, pmiscTable.getOilPhasePressureColumn().size()); + BOOST_CHECK_EQUAL(200*1e5, pmiscTable.getOilPhasePressureColumn()[1]); + BOOST_CHECK_EQUAL(0.5, pmiscTable.getMiscibilityColumn()[1]); +} + +const std::string msfnData = R"( +TABDIMS + 2 / + +MSFN + 0.0 0.0 1.0 + 1.0 1.0 0.0 / + 0.0 0.0 1.0 + 0.5 0.3 0.7 + 1.0 1.0 0.0 / +)"; + +BOOST_AUTO_TEST_CASE( MSFN ) { + Parser parser; + auto deck = parser.parseString(msfnData, ParseContext()); + + Opm::MsfnTable msfnTable1(deck.getKeyword("MSFN").getRecord(0).getItem(0)); + BOOST_CHECK_EQUAL(2U, msfnTable1.getGasPhaseFractionColumn().size()); + BOOST_CHECK_EQUAL(1.0, msfnTable1.getGasPhaseFractionColumn()[1]); + BOOST_CHECK_EQUAL(1.0, msfnTable1.getGasSolventRelpermMultiplierColumn()[1]); + BOOST_CHECK_EQUAL(0.0, msfnTable1.getOilRelpermMultiplierColumn()[1]); + + Opm::MsfnTable msfnTable2(deck.getKeyword("MSFN").getRecord(1).getItem(0)); + BOOST_CHECK_EQUAL(3U, msfnTable2.getGasPhaseFractionColumn().size()); + BOOST_CHECK_EQUAL(0.5, msfnTable2.getGasPhaseFractionColumn()[1]); + BOOST_CHECK_EQUAL(0.3, msfnTable2.getGasSolventRelpermMultiplierColumn()[1]); + BOOST_CHECK_EQUAL(0.7, msfnTable2.getOilRelpermMultiplierColumn()[1]); +} + +BOOST_AUTO_TEST_CASE( TLPMIXPA ) { + const std::string tlpmixpa = R"( + MISCIBLE + 1 3 / + + TLPMIXPA + 100 0.0 + 200 0.5 + 500 1.0 / + )"; + + Parser parser; + auto deck = parser.parseString(tlpmixpa, ParseContext()); + Opm::TlpmixpaTable tlpmixpaTable(deck.getKeyword("TLPMIXPA").getRecord(0).getItem(0)); + BOOST_CHECK_EQUAL(3U, tlpmixpaTable.getOilPhasePressureColumn().size()); + BOOST_CHECK_EQUAL(200*1e5, tlpmixpaTable.getOilPhasePressureColumn()[1]); + BOOST_CHECK_EQUAL(0.5, tlpmixpaTable.getMiscibilityColumn()[1]); +} + +BOOST_AUTO_TEST_CASE( MULTREGT_ECLIPSE_STATE ) { + ParseContext parseContext; + Parser parser; + auto deck = parser.parseFile(pathprefix() + "MULTREGT/MULTREGT.DATA", parseContext); + EclipseState state(deck , parseContext); + const auto& transMult = state.getTransMult(); + + // Test NONNC + // cell 0 and 1 are neigbours + BOOST_CHECK_EQUAL( 0.10 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::XPlus)); + // cell 0 and 3 are not neigbours ==> 1 + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 3 , FaceDir::DirEnum::XPlus)); + + // Test NNC + // cell 4 and 5 are neigbours ==> 1 + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 4 , 5 , FaceDir::DirEnum::XPlus)); + // cell 4 and 7 are not neigbours + BOOST_CHECK_EQUAL( 0.50 , transMult.getRegionMultiplier( 4 , 7 , FaceDir::DirEnum::XPlus)); + + // Test direction X, returns 1 for directions other than +-X + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::YPlus)); + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::ZPlus)); + BOOST_CHECK_EQUAL( 0.10 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::XMinus)); + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::YMinus)); + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::ZMinus)); + BOOST_CHECK_EQUAL( 0.20 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::XPlus)); + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::YPlus)); + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::ZPlus)); + BOOST_CHECK_EQUAL( 0.20 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::XMinus)); + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::YMinus)); + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::ZMinus)); + + // Multipliers between cells of the same region should return 1 + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 2 , FaceDir::DirEnum::XPlus)); + BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 2 , 0 , FaceDir::DirEnum::XPlus)); + + // Test direcion XYZ, returns values for all directions + BOOST_CHECK_EQUAL( 1.50 , transMult.getRegionMultiplier( 0 , 4 , FaceDir::DirEnum::XPlus)); + BOOST_CHECK_EQUAL( 1.50 , transMult.getRegionMultiplier( 0 , 4 , FaceDir::DirEnum::YPlus)); + BOOST_CHECK_EQUAL( 1.50 , transMult.getRegionMultiplier( 0 , 4 , FaceDir::DirEnum::ZPlus)); + BOOST_CHECK_EQUAL( 1.50 , transMult.getRegionMultiplier( 4 , 0 , FaceDir::DirEnum::XPlus)); + + // The first record is overwritten by the second + BOOST_CHECK_EQUAL( 2.50 , transMult.getRegionMultiplier( 3 , 7 , FaceDir::DirEnum::XPlus)); + BOOST_CHECK_EQUAL( 2.50 , transMult.getRegionMultiplier( 3 , 7 , FaceDir::DirEnum::YPlus)); + + // The 2 4 0.75 Z input is overwritten by 2 4 2.5 XY, ==) that 2 4 Z returns the 4 2 value = 0.6 + BOOST_CHECK_EQUAL( 0.60 , transMult.getRegionMultiplier( 7 , 3 , FaceDir::DirEnum::XPlus)); + BOOST_CHECK_EQUAL( 0.60 , transMult.getRegionMultiplier( 3 , 7 , FaceDir::DirEnum::ZPlus)); +} + +BOOST_AUTO_TEST_CASE( MULTISEGMENT_ABS ) { + Parser parser; + std::string deckFile(pathprefix() + "SCHEDULE/SCHEDULE_MULTISEGMENT_WELL"); + auto deck = parser.parseFile(deckFile, ParseContext()); + // for WELSEGS keyword + const auto& kw = deck.getKeyword("WELSEGS"); + + BOOST_CHECK_EQUAL( 6, kw.size() ); + + // check the information for the top segment and the segment set + { + const auto& rec1 = kw.getRecord(0); // top segment + + const std::string well_name = rec1.getItem("WELL").getTrimmedString(0); + const double depth_top = rec1.getItem("DEPTH").get< double >(0); + const double length_top = rec1.getItem("LENGTH").get< double >(0); + const double volume_top = rec1.getItem("WELLBORE_VOLUME").get< double >(0); + const WellSegment::LengthDepthEnum length_depth_type = WellSegment::LengthDepthEnumFromString(rec1.getItem("INFO_TYPE").getTrimmedString(0)); + const WellSegment::CompPressureDropEnum comp_pressure_drop = WellSegment::CompPressureDropEnumFromString(rec1.getItem("PRESSURE_COMPONENTS").getTrimmedString(0)); + const WellSegment::MultiPhaseModelEnum multiphase_model = WellSegment::MultiPhaseModelEnumFromString(rec1.getItem("FLOW_MODEL").getTrimmedString(0)); + + BOOST_CHECK_EQUAL( "PROD01", well_name ); + BOOST_CHECK_EQUAL( 2512.5, depth_top ); + BOOST_CHECK_EQUAL( 2512.5, length_top ); + BOOST_CHECK_EQUAL( 1.0e-5, volume_top ); + const std::string length_depth_type_string = WellSegment::LengthDepthEnumToString(length_depth_type); + BOOST_CHECK_EQUAL( length_depth_type_string, "ABS" ); + const std::string comp_pressure_drop_string = WellSegment::CompPressureDropEnumToString(comp_pressure_drop); + BOOST_CHECK_EQUAL( comp_pressure_drop_string, "H--" ); + const std::string multiphase_model_string = WellSegment::MultiPhaseModelEnumToString(multiphase_model); + BOOST_CHECK_EQUAL( multiphase_model_string, "HO" ); + } + + // check the information for the other segments + // Here, we check the information for the segment 2 and 6 as samples. + { + const auto& rec2 = kw.getRecord(1); + const int segment1 = rec2.getItem("SEGMENT2").get< int >(0); + const int segment2 = rec2.getItem("SEGMENT2").get< int >(0); + BOOST_CHECK_EQUAL( 2, segment1 ); + BOOST_CHECK_EQUAL( 2, segment2 ); + const int branch = rec2.getItem("BRANCH").get< int >(0); + const int outlet_segment = rec2.getItem("JOIN_SEGMENT").get< int >(0); + const double segment_length = rec2.getItem("SEGMENT_LENGTH").get< double >(0); + const double depth_change = rec2.getItem("DEPTH_CHANGE").get< double >(0); + const double diameter = rec2.getItem("DIAMETER").get< double >(0); + const double roughness = rec2.getItem("ROUGHNESS").get< double >(0); + BOOST_CHECK_EQUAL( 1, branch ); + BOOST_CHECK_EQUAL( 1, outlet_segment ); + BOOST_CHECK_EQUAL( 2537.5, segment_length ); + BOOST_CHECK_EQUAL( 2537.5, depth_change ); + BOOST_CHECK_EQUAL( 0.3, diameter ); + BOOST_CHECK_EQUAL( 0.0001, roughness ); + } + + { + const auto& rec6 = kw.getRecord(5); + const int segment1 = rec6.getItem("SEGMENT2").get< int >(0); + const int segment2 = rec6.getItem("SEGMENT2").get< int >(0); + BOOST_CHECK_EQUAL( 6, segment1 ); + BOOST_CHECK_EQUAL( 6, segment2 ); + const int branch = rec6.getItem("BRANCH").get< int >(0); + const int outlet_segment = rec6.getItem("JOIN_SEGMENT").get< int >(0); + const double segment_length = rec6.getItem("SEGMENT_LENGTH").get< double >(0); + const double depth_change = rec6.getItem("DEPTH_CHANGE").get< double >(0); + const double diameter = rec6.getItem("DIAMETER").get< double >(0); + const double roughness = rec6.getItem("ROUGHNESS").get< double >(0); + BOOST_CHECK_EQUAL( 2, branch ); + BOOST_CHECK_EQUAL( 5, outlet_segment ); + BOOST_CHECK_EQUAL( 3137.5, segment_length ); + BOOST_CHECK_EQUAL( 2537.5, depth_change ); + BOOST_CHECK_EQUAL( 0.2, diameter ); + BOOST_CHECK_EQUAL( 0.0001, roughness ); + } + + // for COMPSEG keyword + const auto& kw1 = deck.getKeyword("COMPSEGS"); + // check the size of the keywords + BOOST_CHECK_EQUAL( 7, kw1.size() ); + // first record only contains the well name + { + const auto& rec1 = kw1.getRecord(0); + const std::string well_name = rec1.getItem("WELL").getTrimmedString(0); + BOOST_CHECK_EQUAL( "PROD01", well_name ); + } + + // check the third record and the seventh record + { + const auto& rec3 = kw1.getRecord(2); + const int i = rec3.getItem("I").get< int >(0); + const int j = rec3.getItem("J").get< int >(0); + const int k = rec3.getItem("K").get< int >(0); + const int branch = rec3.getItem("BRANCH").get< int >(0); + const double distance_start = rec3.getItem("DISTANCE_START").get< double >(0); + const double distance_end = rec3.getItem("DISTANCE_END").get< double >(0); + + BOOST_CHECK_EQUAL( 20, i ); + BOOST_CHECK_EQUAL( 1, j ); + BOOST_CHECK_EQUAL( 2, k ); + BOOST_CHECK_EQUAL( 1, branch ); + BOOST_CHECK_EQUAL( 2525.0, distance_start ); + BOOST_CHECK_EQUAL( 2550.0, distance_end ); + } + + { + const auto& rec7 = kw1.getRecord(6); + const int i = rec7.getItem("I").get< int >(0); + const int j = rec7.getItem("J").get< int >(0); + const int k = rec7.getItem("K").get< int >(0); + const int branch = rec7.getItem("BRANCH").get< int >(0); + const double distance_start = rec7.getItem("DISTANCE_START").get< double >(0); + const double distance_end = rec7.getItem("DISTANCE_END").get< double >(0); + + BOOST_CHECK_EQUAL( 17, i ); + BOOST_CHECK_EQUAL( 1, j ); + BOOST_CHECK_EQUAL( 2, k ); + BOOST_CHECK_EQUAL( 2, branch ); + BOOST_CHECK_EQUAL( 3037.5, distance_start ); + BOOST_CHECK_EQUAL( 3237.5, distance_end ); + } +} + +BOOST_AUTO_TEST_CASE( PLYADS ) { + Parser parser; + auto deck = parser.parseFile(pathprefix() + "POLYMER/plyads.data"); + const auto& kw = deck.getKeyword("PLYADS"); + const auto& rec = kw.getRecord(0); + const auto& item = rec.getItem(0); + + BOOST_CHECK_EQUAL( 0.0 , item.get< double >(0) ); + BOOST_CHECK_EQUAL( 0.25 , item.get< double >(2) ); +} + +BOOST_AUTO_TEST_CASE( PLYADSS ) { + Parser parser; + std::string deckFile(pathprefix() + "POLYMER/plyadss.data"); + auto deck = parser.parseFile(deckFile, ParseContext()); + const auto& kw = deck.getKeyword("PLYADSS"); + BOOST_CHECK_EQUAL( kw.size() , 11U ); +} + +BOOST_AUTO_TEST_CASE( PLYDHFLF ) { + Parser parser; + std::string deckFile(pathprefix() + "POLYMER/plydhflf.data"); + auto deck = parser.parseFile(deckFile, ParseContext()); + const auto& kw = deck.getKeyword("PLYDHFLF"); + const auto& rec = kw.getRecord(0); + const auto& item = rec.getItem(0); + + BOOST_CHECK_EQUAL( 0.0 , item.get< double >(0) ); + BOOST_CHECK_EQUAL( 365.0, item.get< double >(1) ); + BOOST_CHECK_EQUAL( 200.0 , item.get< double >(5) ); +} + +BOOST_AUTO_TEST_CASE( PLYSHLOG ) { + Parser parser; + std::string deckFile(pathprefix() + "POLYMER/plyshlog.data"); + auto deck = parser.parseFile(deckFile, ParseContext()); + const auto& kw = deck.getKeyword("PLYSHLOG"); + const auto& rec1 = kw.getRecord(0); // reference conditions + + const auto& itemRefPolyConc = rec1.getItem("REF_POLYMER_CONCENTRATION"); + const auto& itemRefSali = rec1.getItem("REF_SALINITY"); + const auto& itemRefTemp = rec1.getItem("REF_TEMPERATURE"); + + BOOST_CHECK_EQUAL( true, itemRefPolyConc.hasValue(0) ); + BOOST_CHECK_EQUAL( true, itemRefSali.hasValue(0) ); + BOOST_CHECK_EQUAL( false, itemRefTemp.hasValue(0) ); + + BOOST_CHECK_EQUAL( 1.0, itemRefPolyConc.get< double >(0) ); + BOOST_CHECK_EQUAL( 3.0, itemRefSali.get< double >(0) ); + + const auto& rec2 = kw.getRecord(1); + const auto& itemData = rec2.getItem(0); + + BOOST_CHECK_EQUAL( 1.e-7 , itemData.get< double >(0) ); + BOOST_CHECK_EQUAL( 1.0 , itemData.get< double >(1) ); + BOOST_CHECK_EQUAL( 1.0 , itemData.get< double >(2) ); + BOOST_CHECK_EQUAL( 1.2 , itemData.get< double >(3) ); + BOOST_CHECK_EQUAL( 1.e3 , itemData.get< double >(4) ); + BOOST_CHECK_EQUAL( 2.4 , itemData.get< double >(5) ); +} + +BOOST_AUTO_TEST_CASE( PLYVISC ) { + Parser parser; + std::string deckFile(pathprefix() + "POLYMER/plyvisc.data"); + auto deck = parser.parseFile(deckFile, ParseContext()); + const auto& kw = deck.getKeyword("PLYVISC"); + const auto& rec = kw.getRecord(0); + const auto& item = rec.getItem(0); + + BOOST_CHECK_EQUAL( 0.0 , item.get< double >(0) ); + BOOST_CHECK_EQUAL( 1.25 , item.get< double >(2) ); +} + +BOOST_AUTO_TEST_CASE( PORO_PERMX ) { + Parser parser; + std::string poroFile(pathprefix() + "PORO/PORO1"); + auto deck = parser.parseFile(poroFile, ParseContext()); + const auto& kw1 = deck.getKeyword("PORO" , 0); + const auto& kw2 = deck.getKeyword("PERMX" , 0); + + BOOST_CHECK_THROW( kw1.getIntData() , std::logic_error ); + BOOST_CHECK_THROW( kw1.getStringData() , std::logic_error ); + + const std::vector& poro = kw1.getRawDoubleData(); + BOOST_CHECK_EQUAL( 440U , poro.size() ); + BOOST_CHECK_EQUAL( 0.233782813 , poro[0]); + BOOST_CHECK_EQUAL( 0.251224369 , poro[1]); + BOOST_CHECK_EQUAL( 0.155628711 , poro[439]); + + const std::vector& permx = kw2.getSIDoubleData(); + const std::vector& permxRAW = kw2.getRawDoubleData(); + BOOST_CHECK_EQUAL( 1000U , permx.size() ); + BOOST_CHECK_EQUAL( 1000U , permxRAW.size() ); + + BOOST_CHECK_CLOSE( Metric::Permeability * 1 , permx[0] , 0.001); + BOOST_CHECK_CLOSE( Metric::Permeability * 2 , permx[1] , 0.001); + BOOST_CHECK_CLOSE( Metric::Permeability * 3 , permx[2] , 0.001); + BOOST_CHECK_CLOSE( Metric::Permeability * 10, permx[999] , 0.001); +} + +BOOST_AUTO_TEST_CASE( PRORDER ) { + const std::string input = R"( +-- PROD NO 1 NO 2 NO 3 NO 4 NO 5 +-- ORDER OPTN OPTN OPTN OPTN OPTN +PRORDER + DRILL / + NO / + +PRORDER + DRILL THP REPREF / + NO / + )"; + Parser().parseString( input ); +} + +BOOST_AUTO_TEST_CASE( RSVD ) { + Parser parser; + std::string pvtgFile(pathprefix() + "RSVD/RSVD.txt"); + auto deck = parser.parseFile(pvtgFile, ParseContext()); + const auto& kw1 = deck.getKeyword("RSVD" , 0); + BOOST_CHECK_EQUAL( 6U , kw1.size() ); + + const auto& rec1 = kw1.getRecord(0); + const auto& rec3 = kw1.getRecord(2); + + const auto& item1 = rec1.getItem("table"); + BOOST_CHECK( fabs(item1.getSIDouble(0) - 2382) < 0.001); + + const auto& item3 = rec3.getItem("table"); + BOOST_CHECK( fabs(item3.getSIDouble(7) - 106.77) < 0.001); +} + +BOOST_AUTO_TEST_CASE( PVTG ) { +const std::string pvtgData = R"( +TABDIMS +-- NTSFUN NTPVT NSSFUN NPPVT NTFIP NRPVT + 1 2 30 24 10 20 / + +PVTG +-- + 20.00 0.00002448 0.061895 0.01299 + 0.00001224 0.061810 0.01300 + 0.00000000 0.061725 0.01300 / + 40.00 0.00000628 0.030252 0.01383 + 0.00000314 0.030249 0.01383 + 0.00000000 0.030245 0.01383 / +/ + 197.66 0.00006327 1* 0.02160 + 0.00003164 * 0.02122 + 0.00000000 0.005860 0.02086 / + 231.13 0.00010861 0.005042 0.02477 + 0.00005431 0.005061 0.02389 + 0.00000000 0.005082 0.02306 / +/ +)"; + + Parser parser; + auto deck = parser.parseString(pvtgData, ParseContext()); + const auto& kw1 = deck.getKeyword("PVTG" , 0); + BOOST_CHECK_EQUAL(5U , kw1.size()); + + const auto& record0 = kw1.getRecord(0); + const auto& record1 = kw1.getRecord(1); + const auto& record2 = kw1.getRecord(2); + const auto& record3 = kw1.getRecord(3); + const auto& record4 = kw1.getRecord(4); + + const auto& item0_0 = record0.getItem("GAS_PRESSURE"); + const auto& item0_1 = record0.getItem("DATA"); + BOOST_CHECK_EQUAL(1U , item0_0.size()); + BOOST_CHECK_EQUAL(9U , item0_1.size()); + BOOST_CHECK_EQUAL(2U , record0.size()); + + const auto& item1_0 = record1.getItem("GAS_PRESSURE"); + const auto& item1_1 = record1.getItem("DATA"); + BOOST_CHECK_EQUAL(1U , item1_0.size()); + BOOST_CHECK_EQUAL(9U , item1_1.size()); + BOOST_CHECK_EQUAL(2U , record1.size()); + + const auto& item2_0 = record2.getItem("GAS_PRESSURE"); + const auto& item2_1 = record2.getItem("DATA"); + BOOST_CHECK( item2_0.defaultApplied(0)); + BOOST_CHECK_EQUAL(0U , item2_1.size()); + BOOST_CHECK_EQUAL(2U , record2.size()); + + + const auto& item3_0 = record3.getItem("GAS_PRESSURE"); + const auto& item3_1 = record3.getItem("DATA"); + BOOST_CHECK( !item3_1.defaultApplied(0)); + BOOST_CHECK( item3_1.defaultApplied(1)); + BOOST_CHECK( !item3_1.defaultApplied(2)); + BOOST_CHECK( !item3_1.defaultApplied(3)); + BOOST_CHECK( item3_1.defaultApplied(4)); + BOOST_CHECK( !item3_1.defaultApplied(5)); + BOOST_CHECK_EQUAL(1U , item3_0.size()); + BOOST_CHECK_EQUAL(9U , item3_1.size()); + BOOST_CHECK_EQUAL(2U , record3.size()); + + + const auto& item4_0 = record4.getItem("GAS_PRESSURE"); + const auto& item4_1 = record4.getItem("DATA"); + BOOST_CHECK_EQUAL(1U , item4_0.size()); + BOOST_CHECK_EQUAL(9U , item4_1.size()); + BOOST_CHECK_EQUAL(2U , record4.size()); + + /* + { + Opm::PvtgTable pvtgTable; + pvtgTable.initFORUNITTESTONLY(kw1, 0); + + const auto &outerTable = *pvtgTable.getOuterTable(); + const auto &innerTable0 = *pvtgTable.getInnerTable(0); + + BOOST_CHECK_EQUAL(2U, outerTable.numRows()); + BOOST_CHECK_EQUAL(4U, outerTable.numColumns()); + BOOST_CHECK_EQUAL(3U, innerTable0.numRows()); + BOOST_CHECK_EQUAL(3U, innerTable0.numColumns()); + + BOOST_CHECK_EQUAL(20.0e5, outerTable.getPressureColumn()[0]); + BOOST_CHECK_EQUAL(0.00002448, outerTable.getOilSolubilityColumn()[0]); + BOOST_CHECK_EQUAL(outerTable.getOilSolubilityColumn()[0], innerTable0.getOilSolubilityColumn()[0]); + BOOST_CHECK_EQUAL(0.061895, outerTable.getGasFormationFactorColumn()[0]); + BOOST_CHECK_EQUAL(outerTable.getGasFormationFactorColumn()[0], innerTable0.getGasFormationFactorColumn()[0]); + BOOST_CHECK_EQUAL(1.299e-5, outerTable.getGasViscosityColumn()[0]); + BOOST_CHECK_EQUAL(outerTable.getGasViscosityColumn()[0], innerTable0.getGasViscosityColumn()[0]); + } + */ +} + +BOOST_AUTO_TEST_CASE( PVTO ) { +const std::string pvtoData = R"( +TABDIMS +-- NTSFUN NTPVT NSSFUN NPPVT NTFIP NRPVT + 1 2 30 24 10 20 / + +PVTO +-- Rs PO BO MUO + 1e-3 1 1.01 1.02 + 250 1.15 0.95 + 500 1.20 0.93 / + 1e-2 14.8 1.05 1.03 + 251 1.25 0.98 + 502 1.30 0.95 / +/ + 1e-1 1.1 1.02 1.03 + 253 1.16 0.96 + 504 1.21 0.97 / + 1e00 15 1.06 1.04 + 255 1.26 0.99 + 506 1.31 0.96 / +/ +)"; + + Parser parser; + auto deck = parser.parseString(pvtoData, ParseContext()); + const auto& kw1 = deck.getKeyword("PVTO" , 0); + BOOST_CHECK_EQUAL(5U , kw1.size()); + + const auto& record0 = kw1.getRecord(0); + const auto& record1 = kw1.getRecord(1); + const auto& record2 = kw1.getRecord(2); + const auto& record3 = kw1.getRecord(3); + const auto& record4 = kw1.getRecord(4); + + const auto& item0_0 = record0.getItem("RS"); + const auto& item0_1 = record0.getItem("DATA"); + BOOST_CHECK_EQUAL(1U , item0_0.size()); + BOOST_CHECK_EQUAL(9U , item0_1.size()); + BOOST_CHECK_EQUAL(2U , record0.size()); + + const auto& item1_0 = record1.getItem("RS"); + const auto& item1_1 = record1.getItem("DATA"); + BOOST_CHECK_EQUAL(1U , item1_0.size()); + BOOST_CHECK_EQUAL(9U , item1_1.size()); + BOOST_CHECK_EQUAL(2U , record1.size()); + + const auto& item2_0 = record2.getItem("RS"); + const auto& item2_1 = record2.getItem("DATA"); + BOOST_CHECK(item2_0.defaultApplied(0)); + BOOST_CHECK_EQUAL(0U , item2_1.size()); + BOOST_CHECK_EQUAL(2U , record2.size()); + + const auto& item3_0 = record3.getItem("RS"); + const auto& item3_1 = record3.getItem("DATA"); + BOOST_CHECK_EQUAL(1U , item3_0.size()); + BOOST_CHECK_EQUAL(9U , item3_1.size()); + BOOST_CHECK_EQUAL(2U , record3.size()); + + const auto& item4_0 = record4.getItem("RS"); + const auto& item4_1 = record4.getItem("DATA"); + BOOST_CHECK_EQUAL(1U , item4_0.size()); + BOOST_CHECK_EQUAL(9U , item4_1.size()); + BOOST_CHECK_EQUAL(2U , record4.size()); + + + Opm::PvtoTable pvtoTable(kw1 , 0); + BOOST_CHECK_EQUAL(2, pvtoTable.size()); + + const auto &table0 = pvtoTable.getUnderSaturatedTable(0); + const auto& BO = table0.getColumn( "BO" ); + + BOOST_CHECK_EQUAL( 3, table0.numRows()); + BOOST_CHECK_EQUAL( 3, table0.numColumns()); + BOOST_CHECK_EQUAL( BO.front( ) , 1.01 ); + BOOST_CHECK_EQUAL( BO.back( ) , 1.20 ); + + BOOST_CHECK_CLOSE(1.15 , table0.evaluate( "BO" , 250*1e5 ) , 1e-6); + + BOOST_CHECK_CLOSE( 1.15 , pvtoTable.evaluate( "BO" , 1e-3 , 250*1e5 ) , 1e-6 ); + BOOST_CHECK_CLOSE( 1.15 , pvtoTable.evaluate( "BO" , 0.0 , 250*1e5 ) , 1e-6 ); +} + +BOOST_AUTO_TEST_CASE( SGOF ) { +const std::string parserData = R"( +TABDIMS +-- NTSFUN NTPVT NSSFUN NPPVT NTFIP NRPVT + 1 1 30 1 1 1 / + +-- S_g k_rg k_rog p_cog +SGOF + 0.1 0.0 1.0 0.0 + 0.2 0.1 1.0 1.0 + 0.3 0.2 0.9 2.0 + 0.4 0.3 0.8 3.0 + 0.5 0.5 0.5 4.0 + 0.6 0.6 0.4 5.0 + 0.7 0.8 0.3 6.0 + 0.8 0.9 0.2 7.0 + 0.9 0.5 0.1 8.0 + 1.0 1.0 0.1 9.0 /; +)"; + Parser parser; + auto deck = parser.parseString(parserData, ParseContext()); + + const auto& kw1 = deck.getKeyword("SGOF"); + BOOST_CHECK_EQUAL(1U , kw1.size()); + const auto& record0 = kw1.getRecord(0); + BOOST_CHECK_EQUAL(1U , record0.size()); + const auto& item0 = record0.getItem(0); + BOOST_CHECK_EQUAL(10U * 4, item0.size()); + + Opm::SgofTable sgofTable(deck.getKeyword("SGOF").getRecord(0).getItem(0), false); + BOOST_CHECK_EQUAL(10U, sgofTable.getSgColumn().size()); + BOOST_CHECK_EQUAL(0.1, sgofTable.getSgColumn()[0]); + BOOST_CHECK_EQUAL(0.0, sgofTable.getKrgColumn()[0]); + BOOST_CHECK_EQUAL(1.0, sgofTable.getKrogColumn()[0]); + BOOST_CHECK_EQUAL(0.0, sgofTable.getPcogColumn()[0]); +} + +BOOST_AUTO_TEST_CASE( SWOF ) { + + const std::string parserData = R"( +TABDIMS +-- NTSFUN NTPVT NSSFUN NPPVT NTFIP NRPVT + 1 1 30 1 1 1 / + +-- S_w k_rw k_row p_cow +SWOF + 0.1 2* 0.0 + 0.2 0.1 1.0 1.0 + 0.3 1* 0.9 2.0 + 0.4 0.3 1* 3.0 + 0.5 0.5 0.5 4.0 + 0.6 0.6 0.4 1* + 0.7 0.8 0.3 6.0 + 0.8 0.9 0.2 7.0 + 0.9 0.5 0.1 8.0 + 1.0 1* 0.1 9.0 / +)"; + Parser parser; + auto deck = parser.parseString(parserData, ParseContext()); + + const auto& kw1 = deck.getKeyword("SWOF"); + const auto& record0 = kw1.getRecord(0); + const auto& item0 = record0.getItem(0); + BOOST_CHECK_EQUAL(1U , kw1.size()); + BOOST_CHECK_EQUAL(1U , record0.size()); + BOOST_CHECK_EQUAL(10U * 4, item0.size()); + + Opm::SwofTable swofTable(deck.getKeyword("SWOF").getRecord(0).getItem(0), false); + BOOST_CHECK_EQUAL(10U, swofTable.getSwColumn().size()); + BOOST_CHECK_CLOSE(0.1, swofTable.getSwColumn()[0], 1e-8); + BOOST_CHECK_CLOSE(1.0, swofTable.getSwColumn().back(), 1e-8); + + BOOST_CHECK_CLOSE(0.1, swofTable.getKrwColumn()[0], 1e-8); + BOOST_CHECK_CLOSE(0.1, swofTable.getKrwColumn()[1], 1e-8); + BOOST_CHECK_CLOSE(0.2, swofTable.getKrwColumn()[2], 1e-8); + BOOST_CHECK_CLOSE(0.3, swofTable.getKrwColumn()[3], 1e-8); + BOOST_CHECK_CLOSE(0.5, swofTable.getKrwColumn().back(), 1e-8); + + BOOST_CHECK_CLOSE(1.0, swofTable.getKrowColumn()[0], 1e-8); + BOOST_CHECK_CLOSE(0.9, swofTable.getKrowColumn()[2], 1e-8); + BOOST_CHECK_CLOSE(0.7, swofTable.getKrowColumn()[3], 1e-8); + BOOST_CHECK_CLOSE(0.5, swofTable.getKrowColumn()[4], 1e-8); + + BOOST_CHECK_CLOSE(4.0e5, swofTable.getPcowColumn()[4], 1e-8); + BOOST_CHECK_CLOSE(5.0e5, swofTable.getPcowColumn()[5], 1e-8); + BOOST_CHECK_CLOSE(6.0e5, swofTable.getPcowColumn()[6], 1e-8); + + BOOST_CHECK_CLOSE(0.10, swofTable.evaluate("KRW", -0.1), 1e-8); + BOOST_CHECK_CLOSE(0.15, swofTable.evaluate("KRW", 0.25), 1e-8); + BOOST_CHECK_CLOSE(0.50, swofTable.evaluate("KRW", 1.1), 1e-8); +} + +BOOST_AUTO_TEST_CASE( SLGOF ) { + +const std::string parserData = R"( +TABDIMS +-- NTSFUN NTPVT NSSFUN NPPVT NTFIP NRPVT + 1 1 30 1 1 1 / + +-- S_l k_rg k_rog p_cog +SLGOF + 0.1 1.0 0.0 9.0 + 0.2 0.9 0.2 8.0 + 0.3 0.8 0.3 7.0 + 0.4 0.7 0.3 6.0 + 0.5 0.6 0.4 5.0 + 0.6 0.5 0.5 4.0 + 0.7 0.3 0.8 3.0 + 0.8 0.2 0.9 2.0 + 0.9 0.1 1.0 1.0 + 1.0 0.0 1.0 0.0 /; +)"; + + Parser parser; + auto deck = parser.parseString(parserData, ParseContext()); + + const auto& kw1 = deck.getKeyword("SLGOF"); + const auto& record0 = kw1.getRecord(0); + const auto& item0 = record0.getItem(0); + BOOST_CHECK_EQUAL(1U , kw1.size()); + BOOST_CHECK_EQUAL(1U , record0.size()); + BOOST_CHECK_EQUAL(10U * 4, item0.size()); + + Opm::SlgofTable slgofTable( deck.getKeyword("SLGOF").getRecord(0).getItem(0), false ); + BOOST_CHECK_EQUAL(10U, slgofTable.getSlColumn().size()); + BOOST_CHECK_EQUAL(0.1, slgofTable.getSlColumn()[0]); + BOOST_CHECK_EQUAL(1.0, slgofTable.getSlColumn()[9]); + BOOST_CHECK_EQUAL(0.0, slgofTable.getKrgColumn()[9]); + BOOST_CHECK_EQUAL(1.0, slgofTable.getKrogColumn()[9]); + BOOST_CHECK_EQUAL(0.0, slgofTable.getPcogColumn()[9]); +} + +BOOST_AUTO_TEST_CASE( TITLE ) { + Parser parser; + std::string fileWithTitleKeyword(pathprefix() + "TITLE/TITLE1.txt"); + + auto deck = parser.parseFile(fileWithTitleKeyword, ParseContext()); + + BOOST_CHECK_EQUAL(size_t(2), deck.size()); + BOOST_CHECK_EQUAL (true, deck.hasKeyword("TITLE")); + + const auto& titleKeyword = deck.getKeyword("TITLE"); + const auto& record = titleKeyword.getRecord(0); + const auto& item = record.getItem(0); + + std::vector itemValue = item.getData< std::string >(); + std::string itemValueString = boost::algorithm::join(itemValue, " "); + + BOOST_CHECK_EQUAL(0, itemValueString.compare("This is the title of the model.")); + BOOST_CHECK_EQUAL(true, deck.hasKeyword("START")); +} + +BOOST_AUTO_TEST_CASE( TOPS ) { + Parser parser; + std::string deckFile(pathprefix() + "GRID/TOPS.DATA"); + ParseContext parseContext; + auto deck = parser.parseFile(deckFile, parseContext); + EclipseState state(deck, parseContext); + const auto& grid = state.getInputGrid(); + + BOOST_CHECK_EQUAL( grid.getNX() , 9 ); + BOOST_CHECK_EQUAL( grid.getNY() , 9 ); + BOOST_CHECK_EQUAL( grid.getNZ() , 2 ); + + for (size_t g=0; g < 9*9*2; g++) + BOOST_CHECK_CLOSE( grid.getCellVolume( g ) , 400*300*10 , 0.1); + + for (size_t k=0; k < grid.getNZ(); k++) { + for (size_t j=0; j < grid.getNY(); j++) { + for (size_t i=0; i < grid.getNX(); i++) { + auto pos = grid.getCellCenter( i,j,k ); + BOOST_CHECK_CLOSE( std::get<0>(pos) , i*400 + 200 , 0.10 ); + BOOST_CHECK_CLOSE( std::get<1>(pos) , j*300 + 150 , 0.10 ); + BOOST_CHECK_CLOSE( std::get<2>(pos) , k*10 + 5 + 2202 , 0.10 ); + } + } + } +} + +BOOST_AUTO_TEST_CASE( TRACERS ) { + const std::string input = R"( +RUNSPEC +-- NO OIL NO WAT NO GAS NO ENV DIFF MAX MIN TRACER +-- TRACERS TRACERS TRACERS TRACERS CONTL NONLIN NONLIN NONLIN +TRACERS + 0 0 1 0 'NODIFF' 1* 1* 1* / + +)"; + Parser().parseString( input ); +} + +BOOST_AUTO_TEST_CASE( TUNINGDP ) { + const std::string input = R"( +TUNINGDP +/ +TUNINGDP + 1.0 +/ +TUNINGDP + 1.0 2.0 +/ +TUNINGDP + 1.0 2.0 3.0 +/ +TUNINGDP + 1.0 2.0 3.0 4.0 +/ + +)"; + Parser().parseString( input ); +} + +BOOST_AUTO_TEST_CASE( TVDP ) { + Parser parser; + std::string poroFile(pathprefix() + "TVDP/TVDP1"); + auto deck = parser.parseFile(poroFile, ParseContext()); + + BOOST_CHECK(!deck.hasKeyword("TVDP*")); + BOOST_CHECK( deck.hasKeyword("TVDPA")); + BOOST_CHECK( deck.hasKeyword("TVDP1")); + BOOST_CHECK( deck.hasKeyword("TVDPXX")); + BOOST_CHECK( deck.hasKeyword("TVDPYY")); +} + +BOOST_AUTO_TEST_CASE( VFPPROD ) { + Parser parser; + std::string file(pathprefix() + "VFPPROD/VFPPROD1"); + BOOST_CHECK( parser.isRecognizedKeyword("VFPPROD")); + + auto deck = parser.parseFile(file, ParseContext()); + const auto& VFPPROD1 = deck.getKeyword("VFPPROD" , 0); + const auto& BPR = deck.getKeyword("BPR" , 0); + const auto& VFPPROD2 = deck.getKeyword("VFPPROD" , 1); + + BOOST_CHECK_EQUAL( 573U , VFPPROD1.size() ); + BOOST_CHECK_EQUAL( 1U , BPR.size()); + BOOST_CHECK_EQUAL( 573U , VFPPROD2.size()); + + { + const auto& record = VFPPROD1.getRecord(0); + + BOOST_CHECK_EQUAL( record.getItem("TABLE").get< int >(0) , 32 ); + BOOST_CHECK_EQUAL( record.getItem("DATUM_DEPTH").getSIDouble(0) , 394); + BOOST_CHECK_EQUAL( record.getItem("RATE_TYPE").get< std::string >(0) , "LIQ"); + BOOST_CHECK_EQUAL( record.getItem("WFR").get< std::string >(0) , "WCT"); + BOOST_CHECK_EQUAL( record.getItem("GFR").get< std::string >(0) , "GOR"); + } + + { + const auto& record = VFPPROD1.getRecord(1); + const auto& item = record.getItem("FLOW_VALUES"); + + BOOST_CHECK_EQUAL( item.size() , 12 ); + BOOST_CHECK_EQUAL( item.get< double >(0) , 100 ); + BOOST_CHECK_EQUAL( item.get< double >(11) , 20000 ); + } + + { + const auto& record = VFPPROD1.getRecord(2); + const auto& item = record.getItem("THP_VALUES"); + + BOOST_CHECK_EQUAL( item.size() , 7 ); + BOOST_CHECK_CLOSE( item.get< double >(0) , 16.01 , 0.0001 ); + BOOST_CHECK_CLOSE( item.get< double >(6) , 61.01 , 0.0001 ); + } + + { + const auto& record = VFPPROD1.getRecord(3); + const auto& item = record.getItem("WFR_VALUES"); + + BOOST_CHECK_EQUAL( item.size() , 9 ); + BOOST_CHECK_CLOSE( item.get< double >(1) , 0.1 , 0.0001 ); + BOOST_CHECK_CLOSE( item.get< double >(7) , 0.9 , 0.0001 ); + } + + { + const auto& record = VFPPROD1.getRecord(4); + const auto& item = record.getItem("GFR_VALUES"); + + BOOST_CHECK_EQUAL( item.size() , 9 ); + BOOST_CHECK_EQUAL( item.get< double >(0) , 90 ); + BOOST_CHECK_EQUAL( item.get< double >(8) , 10000 ); + } + + { + const auto& record = VFPPROD1.getRecord(5); + const auto& item = record.getItem("ALQ_VALUES"); + + BOOST_CHECK_EQUAL( item.size() , 1 ); + BOOST_CHECK_EQUAL( item.get< double >(0) , 0 ); + } + + { + const auto& record = VFPPROD1.getRecord(6); + + { + const auto& item = record.getItem("THP_INDEX"); + BOOST_CHECK_EQUAL( item.size() , 1 ); + BOOST_CHECK_EQUAL( item.get< int >(0) , 1 ); + } + + { + const auto& item = record.getItem("WFR_INDEX"); + BOOST_CHECK_EQUAL( item.size() , 1 ); + BOOST_CHECK_EQUAL( item.get< int >(0) , 1 ); + } + { + const auto& item = record.getItem("GFR_INDEX"); + BOOST_CHECK_EQUAL( item.size() , 1 ); + BOOST_CHECK_EQUAL( item.get< int >(0) , 1 ); + } + { + const auto& item = record.getItem("ALQ_INDEX"); + BOOST_CHECK_EQUAL( item.size() , 1 ); + BOOST_CHECK_EQUAL( item.get< int >(0) , 1 ); + } + { + const auto& item = record.getItem("VALUES"); + BOOST_CHECK_EQUAL( item.size() , 12 ); + BOOST_CHECK_EQUAL( item.get< double >(0) , 44.85 ); + BOOST_CHECK_EQUAL( item.get< double >(11) , 115.14 ); + } + } + + { + const auto& record = VFPPROD1.getRecord(572); + { + const auto& item = record.getItem("THP_INDEX"); + BOOST_CHECK_EQUAL( item.size() , 1 ); + BOOST_CHECK_EQUAL( item.get< int >(0) , 7 ); + } + { + const auto& item = record.getItem("WFR_INDEX"); + BOOST_CHECK_EQUAL( item.size() , 1 ); + BOOST_CHECK_EQUAL( item.get< int >(0) , 9 ); + } + { + const auto& item = record.getItem("GFR_INDEX"); + BOOST_CHECK_EQUAL( item.size() , 1 ); + BOOST_CHECK_EQUAL( item.get< int >(0) , 9 ); + } + { + const auto& item = record.getItem("ALQ_INDEX"); + BOOST_CHECK_EQUAL( item.size() , 1 ); + BOOST_CHECK_EQUAL( item.get< int >(0) , 1 ); + } + { + const auto& item = record.getItem("VALUES"); + BOOST_CHECK_EQUAL( item.size() , 12 ); + BOOST_CHECK_EQUAL( item.get< double >(0) , 100.80 ); + BOOST_CHECK_EQUAL( item.get< double >(11) , 147.79 ); + } + } +} + +BOOST_AUTO_TEST_CASE( WCHONHIST ) { + Parser parser; + std::string wconhistFile(pathprefix() + "WCONHIST/WCONHIST1"); + auto deck = parser.parseFile(wconhistFile, ParseContext()); + const auto& kw1 = deck.getKeyword("WCONHIST" , 0); + BOOST_CHECK_EQUAL( 3U , kw1.size() ); + + const auto& rec1 = kw1.getRecord(0); + BOOST_CHECK_EQUAL( 11U , rec1.size() ); + + const auto& rec3 = kw1.getRecord(2); + BOOST_CHECK_EQUAL( 11U , rec3.size() ); + + const auto& item1 = rec1.getItem("WELL"); + const auto& item1_index = rec1.getItem(0); + + BOOST_CHECK_EQUAL( &item1 , &item1_index ); + BOOST_CHECK_EQUAL( "OP_1" , item1.get< std::string >(0)); + + const auto& kw2 = deck.getKeyword( "WCONHIST", 1 ); + BOOST_CHECK_EQUAL( "OP_3" , rec3.getItem("WELL").get< std::string >(0)); + BOOST_CHECK_EQUAL( 2U , deck.count("WCONHIST")); + BOOST_CHECK_EQUAL( "OP_3_B" , kw2.getRecord( 2 ).getItem("WELL").get< std::string >(0)); + BOOST_CHECK( !deck.hasKeyword( "DIMENS" ) ); +} + +BOOST_AUTO_TEST_CASE( WDFACCOR ) { + const std::string input = R"( +-- WELL COEFF POWER POWER +-- NAME A B C +WDFACCOR + '*' 1.200E-3 -1.045 0.0 / +/ +)"; + Parser().parseString( input ); +} + +BOOST_AUTO_TEST_CASE( WEFAC ) { + const std::string input = R"( +-- WELL EFF NETWK +-- NAME FACT OPTN + +WEFAC + '* ' 0.950 / +/ +)"; + Parser().parseString( input ); +} + +BOOST_AUTO_TEST_CASE( WELL_PROBE ) { + const std::string validDeckString = R"( +WBHP + / +WOPR + /; +)"; + Parser parser; + + // TODO: for some reason, the parser does not seem to throw here. Investigate +/* + const char *invalidDeckString = + "WELL_PROBE\n" + "/\n"; + BOOST_CHECK_THROW(parser->parseString(invalidDeckString), std::invalid_argument); +*/ + + auto deck = parser.parseString(validDeckString, ParseContext()); + BOOST_CHECK( !deck.hasKeyword("WELL_PROBE")); + BOOST_CHECK( deck.hasKeyword("WBHP")); + BOOST_CHECK( deck.hasKeyword("WOPR")); + BOOST_CHECK( !deck.hasKeyword("WWPR")); +} + +BOOST_AUTO_TEST_CASE( WCONPROD ) { + Parser parser; + std::string wconprodFile(pathprefix() + "WellWithWildcards/WCONPROD1"); + auto deck = parser.parseFile(wconprodFile, ParseContext()); + EclipseGrid grid(30,30,30); + TableManager table ( deck ); + Eclipse3DProperties eclipseProperties ( deck , table, grid); + Schedule sched(ParseContext(), grid, eclipseProperties, deck, Phases(true, true, true) ); + + BOOST_CHECK_EQUAL(5U, sched.numWells()); + BOOST_CHECK(sched.hasWell("INJE1")); + BOOST_CHECK(sched.hasWell("PROD2")); + BOOST_CHECK(sched.hasWell("PROD3")); + BOOST_CHECK(sched.hasWell("PROD4")); + BOOST_CHECK(sched.hasWell("PROX5")); + + { + auto* well = sched.getWell("PROD2"); + BOOST_CHECK_CLOSE(1000/Metric::Time, well->getProductionProperties(0).OilRate, 0.001); + BOOST_CHECK_CLOSE(1500/Metric::Time, well->getProductionProperties(1).OilRate, 0.001); + } + + { + auto* well = sched.getWell("PROD3"); + BOOST_CHECK_CLOSE(0/Metric::Time, well->getProductionProperties(0).OilRate, 0.001); + BOOST_CHECK_CLOSE(1500/Metric::Time, well->getProductionProperties(1).OilRate, 0.001); + } + + { + auto* well = sched.getWell("PROX5"); + BOOST_CHECK_CLOSE(2000/Metric::Time, well->getProductionProperties(0).OilRate, 0.001); + BOOST_CHECK_CLOSE(2000/Metric::Time, well->getProductionProperties(1).OilRate, 0.001); + } +} + + +BOOST_AUTO_TEST_CASE( WCONINJE ) { + ParseContext parseContext; + Parser parser; + std::string wconprodFile(pathprefix() + "WellWithWildcards/WCONINJE1"); + auto deck = parser.parseFile(wconprodFile, parseContext); + EclipseGrid grid(30,30,30); + TableManager table ( deck ); + Eclipse3DProperties eclipseProperties( deck , table, grid ); + Schedule sched( parseContext, grid, eclipseProperties, deck, Phases(true, true, true) ); + + BOOST_CHECK_EQUAL(5U, sched.numWells()); + BOOST_CHECK(sched.hasWell("PROD1")); + BOOST_CHECK(sched.hasWell("INJE2")); + BOOST_CHECK(sched.hasWell("INJE3")); + BOOST_CHECK(sched.hasWell("PROD4")); + BOOST_CHECK(sched.hasWell("INJX5")); + + { + auto* well = sched.getWell("INJE2"); + BOOST_CHECK_CLOSE(1000/Metric::Time, well->getInjectionProperties(0).surfaceInjectionRate, 0.001); + BOOST_CHECK_CLOSE(1500/Metric::Time, well->getInjectionProperties(1).surfaceInjectionRate, 0.001); + } + + { + auto* well = sched.getWell("INJE3"); + BOOST_CHECK_CLOSE(0/Metric::Time, well->getInjectionProperties(0).surfaceInjectionRate, 0.001); + BOOST_CHECK_CLOSE(1500/Metric::Time, well->getInjectionProperties(1).surfaceInjectionRate, 0.001); + } + + { + auto* well = sched.getWell("INJX5"); + BOOST_CHECK_CLOSE(2000/Metric::Time, well->getInjectionProperties(0).surfaceInjectionRate, 0.001); + BOOST_CHECK_CLOSE(2000/Metric::Time, well->getInjectionProperties(1).surfaceInjectionRate, 0.001); + } +} + +BOOST_AUTO_TEST_CASE( WORKLIM ) { + const std::string input = R"( +WORKLIM + 10.0 +/ +)"; + Parser().parseString( input ); +} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseLGR.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseLGR.cpp deleted file mode 100644 index 1410b78ed..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseLGR.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( parse_LGR ) { - Parser().parseFile( pathprefix() + "LGR/LGR.DATA" ); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseMULTREGT.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseMULTREGT.cpp deleted file mode 100644 index f8b43b3b4..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseMULTREGT.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParseMULTREGT -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -using namespace Opm; - - -inline std::string prefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - - -BOOST_AUTO_TEST_CASE( parse_MULTREGT_OK ) { - Parser parser; - auto deck = parser.parseFile(prefix() + "MULTREGT/MULTREGT", ParseContext()); - BOOST_CHECK_NO_THROW( deck.getKeyword("MULTREGT" , 0); ); -} - - - -BOOST_AUTO_TEST_CASE( MULTREGT_ECLIPSE_STATE ) { - ParseContext parseContext; - Parser parser; - auto deck = parser.parseFile(prefix() + "MULTREGT/MULTREGT.DATA", parseContext); - EclipseState state(deck , parseContext); - const auto& transMult = state.getTransMult(); - - // Test NONNC - // cell 0 and 1 are neigbours - BOOST_CHECK_EQUAL( 0.10 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::XPlus)); - // cell 0 and 3 are not neigbours ==> 1 - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 3 , FaceDir::DirEnum::XPlus)); - - // Test NNC - // cell 4 and 5 are neigbours ==> 1 - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 4 , 5 , FaceDir::DirEnum::XPlus)); - // cell 4 and 7 are not neigbours - BOOST_CHECK_EQUAL( 0.50 , transMult.getRegionMultiplier( 4 , 7 , FaceDir::DirEnum::XPlus)); - - // Test direction X, returns 1 for directions other than +-X - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::YPlus)); - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::ZPlus)); - BOOST_CHECK_EQUAL( 0.10 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::XMinus)); - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::YMinus)); - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 1 , FaceDir::DirEnum::ZMinus)); - BOOST_CHECK_EQUAL( 0.20 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::XPlus)); - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::YPlus)); - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::ZPlus)); - BOOST_CHECK_EQUAL( 0.20 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::XMinus)); - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::YMinus)); - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 1 , 0 , FaceDir::DirEnum::ZMinus)); - - // Multipliers between cells of the same region should return 1 - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 0 , 2 , FaceDir::DirEnum::XPlus)); - BOOST_CHECK_EQUAL( 1.00 , transMult.getRegionMultiplier( 2 , 0 , FaceDir::DirEnum::XPlus)); - - // Test direcion XYZ, returns values for all directions - BOOST_CHECK_EQUAL( 1.50 , transMult.getRegionMultiplier( 0 , 4 , FaceDir::DirEnum::XPlus)); - BOOST_CHECK_EQUAL( 1.50 , transMult.getRegionMultiplier( 0 , 4 , FaceDir::DirEnum::YPlus)); - BOOST_CHECK_EQUAL( 1.50 , transMult.getRegionMultiplier( 0 , 4 , FaceDir::DirEnum::ZPlus)); - BOOST_CHECK_EQUAL( 1.50 , transMult.getRegionMultiplier( 4 , 0 , FaceDir::DirEnum::XPlus)); - - // The first record is overwritten by the second - BOOST_CHECK_EQUAL( 2.50 , transMult.getRegionMultiplier( 3 , 7 , FaceDir::DirEnum::XPlus)); - BOOST_CHECK_EQUAL( 2.50 , transMult.getRegionMultiplier( 3 , 7 , FaceDir::DirEnum::YPlus)); - - // The 2 4 0.75 Z input is overwritten by 2 4 2.5 XY, ==) that 2 4 Z returns the 4 2 value = 0.6 - BOOST_CHECK_EQUAL( 0.60 , transMult.getRegionMultiplier( 7 , 3 , FaceDir::DirEnum::XPlus)); - BOOST_CHECK_EQUAL( 0.60 , transMult.getRegionMultiplier( 3 , 7 , FaceDir::DirEnum::ZPlus)); - -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseMULTSEGWELL.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseMULTSEGWELL.cpp deleted file mode 100644 index b6f2193ad..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseMULTSEGWELL.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - Copyright (C) 2015 SINTEF ICT, Applied Mathematics - - 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 . - */ - -#define BOOST_TEST_MODULE ParseMULTSEGWELL -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( PARSE_MULTISEGMENT_ABS ) { - - Parser parser; - std::string deckFile(pathprefix() + "SCHEDULE/SCHEDULE_MULTISEGMENT_WELL"); - auto deck = parser.parseFile(deckFile, ParseContext()); - // for WELSEGS keyword - const auto& kw = deck.getKeyword("WELSEGS"); - - // check the size of the keywords - BOOST_CHECK_EQUAL( 6, kw.size() ); - - // check the information for the top segment and the segment set - { - const auto& rec1 = kw.getRecord(0); // top segment - - const std::string well_name = rec1.getItem("WELL").getTrimmedString(0); - const double depth_top = rec1.getItem("DEPTH").get< double >(0); - const double length_top = rec1.getItem("LENGTH").get< double >(0); - const double volume_top = rec1.getItem("WELLBORE_VOLUME").get< double >(0); - const WellSegment::LengthDepthEnum length_depth_type = WellSegment::LengthDepthEnumFromString(rec1.getItem("INFO_TYPE").getTrimmedString(0)); - const WellSegment::CompPressureDropEnum comp_pressure_drop = WellSegment::CompPressureDropEnumFromString(rec1.getItem("PRESSURE_COMPONENTS").getTrimmedString(0)); - const WellSegment::MultiPhaseModelEnum multiphase_model = WellSegment::MultiPhaseModelEnumFromString(rec1.getItem("FLOW_MODEL").getTrimmedString(0)); - - BOOST_CHECK_EQUAL( "PROD01", well_name ); - BOOST_CHECK_EQUAL( 2512.5, depth_top ); - BOOST_CHECK_EQUAL( 2512.5, length_top ); - BOOST_CHECK_EQUAL( 1.0e-5, volume_top ); - const std::string length_depth_type_string = WellSegment::LengthDepthEnumToString(length_depth_type); - BOOST_CHECK_EQUAL( length_depth_type_string, "ABS" ); - const std::string comp_pressure_drop_string = WellSegment::CompPressureDropEnumToString(comp_pressure_drop); - BOOST_CHECK_EQUAL( comp_pressure_drop_string, "H--" ); - const std::string multiphase_model_string = WellSegment::MultiPhaseModelEnumToString(multiphase_model); - BOOST_CHECK_EQUAL( multiphase_model_string, "HO" ); - } - - // check the information for the other segments - // Here, we check the information for the segment 2 and 6 as samples. - { - const auto& rec2 = kw.getRecord(1); - const int segment1 = rec2.getItem("SEGMENT2").get< int >(0); - const int segment2 = rec2.getItem("SEGMENT2").get< int >(0); - BOOST_CHECK_EQUAL( 2, segment1 ); - BOOST_CHECK_EQUAL( 2, segment2 ); - const int branch = rec2.getItem("BRANCH").get< int >(0); - const int outlet_segment = rec2.getItem("JOIN_SEGMENT").get< int >(0); - const double segment_length = rec2.getItem("SEGMENT_LENGTH").get< double >(0); - const double depth_change = rec2.getItem("DEPTH_CHANGE").get< double >(0); - const double diameter = rec2.getItem("DIAMETER").get< double >(0); - const double roughness = rec2.getItem("ROUGHNESS").get< double >(0); - BOOST_CHECK_EQUAL( 1, branch ); - BOOST_CHECK_EQUAL( 1, outlet_segment ); - BOOST_CHECK_EQUAL( 2537.5, segment_length ); - BOOST_CHECK_EQUAL( 2537.5, depth_change ); - BOOST_CHECK_EQUAL( 0.3, diameter ); - BOOST_CHECK_EQUAL( 0.0001, roughness ); - } - - { - const auto& rec6 = kw.getRecord(5); - const int segment1 = rec6.getItem("SEGMENT2").get< int >(0); - const int segment2 = rec6.getItem("SEGMENT2").get< int >(0); - BOOST_CHECK_EQUAL( 6, segment1 ); - BOOST_CHECK_EQUAL( 6, segment2 ); - const int branch = rec6.getItem("BRANCH").get< int >(0); - const int outlet_segment = rec6.getItem("JOIN_SEGMENT").get< int >(0); - const double segment_length = rec6.getItem("SEGMENT_LENGTH").get< double >(0); - const double depth_change = rec6.getItem("DEPTH_CHANGE").get< double >(0); - const double diameter = rec6.getItem("DIAMETER").get< double >(0); - const double roughness = rec6.getItem("ROUGHNESS").get< double >(0); - BOOST_CHECK_EQUAL( 2, branch ); - BOOST_CHECK_EQUAL( 5, outlet_segment ); - BOOST_CHECK_EQUAL( 3137.5, segment_length ); - BOOST_CHECK_EQUAL( 2537.5, depth_change ); - BOOST_CHECK_EQUAL( 0.2, diameter ); - BOOST_CHECK_EQUAL( 0.0001, roughness ); - } - - // for COMPSEG keyword - const auto& kw1 = deck.getKeyword("COMPSEGS"); - // check the size of the keywords - BOOST_CHECK_EQUAL( 7, kw1.size() ); - // first record only contains the well name - { - const auto& rec1 = kw1.getRecord(0); - const std::string well_name = rec1.getItem("WELL").getTrimmedString(0); - BOOST_CHECK_EQUAL( "PROD01", well_name ); - } - - // check the third record and the seventh record - { - const auto& rec3 = kw1.getRecord(2); - const int i = rec3.getItem("I").get< int >(0); - const int j = rec3.getItem("J").get< int >(0); - const int k = rec3.getItem("K").get< int >(0); - const int branch = rec3.getItem("BRANCH").get< int >(0); - const double distance_start = rec3.getItem("DISTANCE_START").get< double >(0); - const double distance_end = rec3.getItem("DISTANCE_END").get< double >(0); - - BOOST_CHECK_EQUAL( 20, i ); - BOOST_CHECK_EQUAL( 1, j ); - BOOST_CHECK_EQUAL( 2, k ); - BOOST_CHECK_EQUAL( 1, branch ); - BOOST_CHECK_EQUAL( 2525.0, distance_start ); - BOOST_CHECK_EQUAL( 2550.0, distance_end ); - } - - { - const auto& rec7 = kw1.getRecord(6); - const int i = rec7.getItem("I").get< int >(0); - const int j = rec7.getItem("J").get< int >(0); - const int k = rec7.getItem("K").get< int >(0); - const int branch = rec7.getItem("BRANCH").get< int >(0); - const double distance_start = rec7.getItem("DISTANCE_START").get< double >(0); - const double distance_end = rec7.getItem("DISTANCE_END").get< double >(0); - - BOOST_CHECK_EQUAL( 17, i ); - BOOST_CHECK_EQUAL( 1, j ); - BOOST_CHECK_EQUAL( 2, k ); - BOOST_CHECK_EQUAL( 2, branch ); - BOOST_CHECK_EQUAL( 3037.5, distance_start ); - BOOST_CHECK_EQUAL( 3237.5, distance_end ); - } - - -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseMiscible.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseMiscible.cpp deleted file mode 100644 index f9d1a5925..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseMiscible.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/* - Copyright 2015 IRIS AS. - 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 . - */ - -#define BOOST_TEST_MODULE ParseMiscible -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace Opm; - -const std::string miscibleData = "\n\ -MISCIBLE\n\ -2 3 /\n\ -\n"; - -const std::string miscibleTightData = "\n\ -MISCIBLE\n\ -1 2 /\n\ -\n"; - -const std::string sorwmisData = "\n\ -SORWMIS\n\ -.00 .00 \n\ -.50 .00 \n\ -1.0 .00 /\n\ -.00 .00 \n\ -.30 .20 \n\ -1.0 .80 /\n\ -\n"; - -const std::string sgcwmisData = "\n\ -SGCWMIS\n\ -.00 .00 \n\ -.20 .00 \n\ -1.0 .00 /\n\ -.00 .00 \n\ -.80 .20 \n\ -1.0 .70 /\n\ -\n"; - -BOOST_AUTO_TEST_CASE( PARSE_SORWMIS) { -Parser parser; - -// missing miscible keyword -BOOST_CHECK_THROW (parser.parseString(sorwmisData, ParseContext()), std::invalid_argument ); - -//too many tables -BOOST_CHECK_THROW( parser.parseString(miscibleTightData + sorwmisData, ParseContext()), std::invalid_argument); - -auto deck1 = parser.parseString(miscibleData + sorwmisData, ParseContext()); - -const auto& sorwmis = deck1.getKeyword("SORWMIS"); -const auto& miscible = deck1.getKeyword("MISCIBLE"); - -const auto& miscible0 = miscible.getRecord(0); -const auto& sorwmis0 = sorwmis.getRecord(0); -const auto& sorwmis1 = sorwmis.getRecord(1); - - -// test number of columns -size_t ntmisc = miscible0.getItem(0).get< int >(0); -Opm::SorwmisTable sorwmisTable0(sorwmis0.getItem(0)); -BOOST_CHECK_EQUAL(sorwmisTable0.numColumns(),ntmisc); - -// test table input 1 -BOOST_CHECK_EQUAL(3U, sorwmisTable0.getWaterSaturationColumn().size()); -BOOST_CHECK_EQUAL(1.0, sorwmisTable0.getWaterSaturationColumn()[2]); -BOOST_CHECK_EQUAL(0.0, sorwmisTable0.getMiscibleResidualOilColumn()[2]); - -// test table input 2 - Opm::SorwmisTable sorwmisTable1(sorwmis1.getItem(0)); -BOOST_CHECK_EQUAL(sorwmisTable1.numColumns(),ntmisc); - -BOOST_CHECK_EQUAL(3U, sorwmisTable1.getWaterSaturationColumn().size()); -BOOST_CHECK_EQUAL(0.3, sorwmisTable1.getWaterSaturationColumn()[1]); -BOOST_CHECK_EQUAL(0.8, sorwmisTable1.getMiscibleResidualOilColumn()[2]); -} - -BOOST_AUTO_TEST_CASE( PARSE_SGCWMIS) { - Parser parser; - - auto deck1 = parser.parseString(miscibleData + sgcwmisData, ParseContext()); - - const auto& sgcwmis = deck1.getKeyword("SGCWMIS"); - const auto& miscible = deck1.getKeyword("MISCIBLE"); - - const auto& miscible0 = miscible.getRecord(0); - const auto& sgcwmis0 = sgcwmis.getRecord(0); - const auto& sgcwmis1 = sgcwmis.getRecord(1); - - - // test number of columns - size_t ntmisc = miscible0.getItem(0).get< int >(0); - Opm::SgcwmisTable sgcwmisTable0(sgcwmis0.getItem(0)); - BOOST_CHECK_EQUAL(sgcwmisTable0.numColumns(),ntmisc); - - // test table input 1 - BOOST_CHECK_EQUAL(3U, sgcwmisTable0.getWaterSaturationColumn().size()); - BOOST_CHECK_EQUAL(0.2, sgcwmisTable0.getWaterSaturationColumn()[1]); - BOOST_CHECK_EQUAL(0.0, sgcwmisTable0.getMiscibleResidualGasColumn()[1]); - - // test table input 2 - Opm::SgcwmisTable sgcwmisTable1(sgcwmis1.getItem(0)); - BOOST_CHECK_EQUAL(sgcwmisTable1.numColumns(),ntmisc); - - BOOST_CHECK_EQUAL(3U, sgcwmisTable1.getWaterSaturationColumn().size()); - BOOST_CHECK_EQUAL(0.8, sgcwmisTable1.getWaterSaturationColumn()[1]); - BOOST_CHECK_EQUAL(0.2, sgcwmisTable1.getMiscibleResidualGasColumn()[1]); -} - -const char *miscData = "\n\ -MISCIBLE\n\ -1 3 /\n\ -\n\ -MISC\n\ - 0.0 0.0 \n\ - 0.1 0.5 \n\ - 1.0 1.0 /\n\ -\n"; - -const char *miscOutOfRangeData = "\n\ -MISCIBLE\n\ -1 3 /\n\ -\n\ -MISC\n\ -0.0 0.0 \n\ -1.0 0.5 \n\ -2.0 1.0 /\n\ -\n"; - -const char *miscTooSmallRangeData = "\n\ -MISCIBLE\n\ -1 3 /\n\ -\n\ -MISC\n\ -0.0 0.0 \n\ -1.0 0.5 /\n\ -\n"; - -BOOST_AUTO_TEST_CASE(PARSE_MISC) { - Parser parser; - - // out of range MISC keyword - auto deck1 = parser.parseString(miscOutOfRangeData, ParseContext()); - const auto& item = deck1.getKeyword("MISC").getRecord(0).getItem(0); - Opm::MiscTable miscTable1(item); - - - // too litle range of MISC keyword - auto deck2 = parser.parseString(miscTooSmallRangeData, ParseContext()); - const auto& item2 = deck2.getKeyword("MISC").getRecord(0).getItem(0); - Opm::MiscTable miscTable2(item2); - - // test table input - auto deck3 = parser.parseString(miscData, ParseContext()); - const auto& item3 = deck3.getKeyword("MISC").getRecord(0).getItem(0); - Opm::MiscTable miscTable3(item3); - BOOST_CHECK_EQUAL(3U, miscTable3.getSolventFractionColumn().size()); - BOOST_CHECK_EQUAL(0.1, miscTable3.getSolventFractionColumn()[1]); - BOOST_CHECK_EQUAL(0.5, miscTable3.getMiscibilityColumn()[1]); -} - -const char *pmiscData = "\n\ -MISCIBLE\n\ -1 3 /\n\ -\n\ -PMISC\n\ -100 0.0 \n\ -200 0.5 \n\ -500 1.0 /\n\ -\n"; - -BOOST_AUTO_TEST_CASE(PARSE_PMISC) -{ - Parser parser; - - // test table input - auto deck = parser.parseString(pmiscData, ParseContext()); - Opm::PmiscTable pmiscTable(deck.getKeyword("PMISC").getRecord(0).getItem(0)); - BOOST_CHECK_EQUAL(3U, pmiscTable.getOilPhasePressureColumn().size()); - BOOST_CHECK_EQUAL(200*1e5, pmiscTable.getOilPhasePressureColumn()[1]); - BOOST_CHECK_EQUAL(0.5, pmiscTable.getMiscibilityColumn()[1]); -} - -const char *msfnData = "\n\ -TABDIMS\n\ -2 /\n\ -\n\ -MSFN\n\ -0.0 0.0 1.0 \n\ -1.0 1.0 0.0 /\n\ -0.0 0.0 1.0 \n\ -0.5 0.3 0.7 \n\ -1.0 1.0 0.0 /\n\ -\n"; - -BOOST_AUTO_TEST_CASE(PARSE_MSFN) { -Parser parser; -auto deck = parser.parseString(msfnData, ParseContext()); - -// test table input 1 - Opm::MsfnTable msfnTable1(deck.getKeyword("MSFN").getRecord(0).getItem(0)); - BOOST_CHECK_EQUAL(2U, msfnTable1.getGasPhaseFractionColumn().size()); - BOOST_CHECK_EQUAL(1.0, msfnTable1.getGasPhaseFractionColumn()[1]); - BOOST_CHECK_EQUAL(1.0, msfnTable1.getGasSolventRelpermMultiplierColumn()[1]); - BOOST_CHECK_EQUAL(0.0, msfnTable1.getOilRelpermMultiplierColumn()[1]); - -// test table input 2 -Opm::MsfnTable msfnTable2(deck.getKeyword("MSFN").getRecord(1).getItem(0)); -BOOST_CHECK_EQUAL(3U, msfnTable2.getGasPhaseFractionColumn().size()); -BOOST_CHECK_EQUAL(0.5, msfnTable2.getGasPhaseFractionColumn()[1]); -BOOST_CHECK_EQUAL(0.3, msfnTable2.getGasSolventRelpermMultiplierColumn()[1]); -BOOST_CHECK_EQUAL(0.7, msfnTable2.getOilRelpermMultiplierColumn()[1]); -} - -const char *tlpmixpa = "\n\ -MISCIBLE\n\ -1 3 /\n\ -\n\ -TLPMIXPA\n\ -100 0.0 \n\ -200 0.5 \n\ -500 1.0 /\n\ -\n"; - -BOOST_AUTO_TEST_CASE(PARSE_TLPMIXPA) { - Parser parser; - - // test table input - auto deck = parser.parseString(tlpmixpa, ParseContext()); - Opm::TlpmixpaTable tlpmixpaTable(deck.getKeyword("TLPMIXPA").getRecord(0).getItem(0)); - BOOST_CHECK_EQUAL(3U, tlpmixpaTable.getOilPhasePressureColumn().size()); - BOOST_CHECK_EQUAL(200*1e5, tlpmixpaTable.getOilPhasePressureColumn()[1]); - BOOST_CHECK_EQUAL(0.5, tlpmixpaTable.getMiscibilityColumn()[1]); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParsePLYADS.cpp b/src/opm/parser/eclipse/IntegrationTests/ParsePLYADS.cpp deleted file mode 100644 index 82519d91f..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParsePLYADS.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParsePLYVISC -#include - -#include -#include -#include - -#include -#include -#include -#include - -using namespace Opm; - - -inline std::string prefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( PARSE_PLYADS_OK) { - ParserPtr parser(new Parser()); - std::string deckFile(prefix() + "POLYMER/plyads.data"); - DeckPtr deck = parser->parseFile(deckFile); - const auto& = deck->getKeyword("PLYADS"); - const auto& rec = kw.getRecord(0); - auto* item = rec.getItem(0); - - BOOST_CHECK_EQUAL( 0.0 , item.get< double >(0) ); - BOOST_CHECK_EQUAL( 0.25 , item.get< double >(2) ); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParsePLYADSS.cpp b/src/opm/parser/eclipse/IntegrationTests/ParsePLYADSS.cpp deleted file mode 100644 index 243ffa5a6..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParsePLYADSS.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParsePLYVISC -#include - -#include -#include -#include -#include - -using namespace Opm; - -inline std::string prefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( PARSE_PLYADSS_OK) { - Parser parser; - std::string deckFile(prefix() + "POLYMER/plyadss.data"); - auto deck = parser.parseFile(deckFile, ParseContext()); - const auto& kw = deck.getKeyword("PLYADSS"); - - BOOST_CHECK_EQUAL( kw.size() , 11U ); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParsePLYDHFLF.cpp b/src/opm/parser/eclipse/IntegrationTests/ParsePLYDHFLF.cpp deleted file mode 100644 index a26b8f7bb..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParsePLYDHFLF.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright 2015 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 . - */ - -#define BOOST_TEST_MODULE ParsePLYDHFLF -#include - -#include -#include -#include -#include -#include -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( PARSE_PLYDHFLF_OK) { - Parser parser; - std::string deckFile(pathprefix() + "POLYMER/plydhflf.data"); - auto deck = parser.parseFile(deckFile, ParseContext()); - const auto& kw = deck.getKeyword("PLYDHFLF"); - const auto& rec = kw.getRecord(0); - const auto& item = rec.getItem(0); - - BOOST_CHECK_EQUAL( 0.0 , item.get< double >(0) ); - BOOST_CHECK_EQUAL( 365.0, item.get< double >(1) ); - BOOST_CHECK_EQUAL( 200.0 , item.get< double >(5) ); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParsePLYSHLOG.cpp b/src/opm/parser/eclipse/IntegrationTests/ParsePLYSHLOG.cpp deleted file mode 100644 index fcbb5143d..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParsePLYSHLOG.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright 2015 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 . - */ - -#define BOOST_TEST_MODULE ParsePLYSHLOG -#include - -#include -#include -#include -#include -#include -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( PARSE_PLYSHLOG_OK) { - Parser parser; - std::string deckFile(pathprefix() + "POLYMER/plyshlog.data"); - auto deck = parser.parseFile(deckFile, ParseContext()); - const auto& kw = deck.getKeyword("PLYSHLOG"); - const auto& rec1 = kw.getRecord(0); // reference conditions - - const auto& itemRefPolyConc = rec1.getItem("REF_POLYMER_CONCENTRATION"); - const auto& itemRefSali = rec1.getItem("REF_SALINITY"); - const auto& itemRefTemp = rec1.getItem("REF_TEMPERATURE"); - - BOOST_CHECK_EQUAL( true, itemRefPolyConc.hasValue(0) ); - BOOST_CHECK_EQUAL( true, itemRefSali.hasValue(0) ); - BOOST_CHECK_EQUAL( false, itemRefTemp.hasValue(0) ); - - BOOST_CHECK_EQUAL( 1.0, itemRefPolyConc.get< double >(0) ); - BOOST_CHECK_EQUAL( 3.0, itemRefSali.get< double >(0) ); - - const auto& rec2 = kw.getRecord(1); - const auto& itemData = rec2.getItem(0); - - BOOST_CHECK_EQUAL( 1.e-7 , itemData.get< double >(0) ); - BOOST_CHECK_EQUAL( 1.0 , itemData.get< double >(1) ); - BOOST_CHECK_EQUAL( 1.0 , itemData.get< double >(2) ); - BOOST_CHECK_EQUAL( 1.2 , itemData.get< double >(3) ); - BOOST_CHECK_EQUAL( 1.e3 , itemData.get< double >(4) ); - BOOST_CHECK_EQUAL( 2.4 , itemData.get< double >(5) ); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParsePLYVISC.cpp b/src/opm/parser/eclipse/IntegrationTests/ParsePLYVISC.cpp deleted file mode 100644 index b6d61df31..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParsePLYVISC.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParsePLYVISC -#include - -#include -#include -#include -#include -#include -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( PARSE_PLYVISC_OK) { - Parser parser; - std::string deckFile(pathprefix() + "POLYMER/plyvisc.data"); - auto deck = parser.parseFile(deckFile, ParseContext()); - const auto& kw = deck.getKeyword("PLYVISC"); - const auto& rec = kw.getRecord(0); - const auto& item = rec.getItem(0); - - BOOST_CHECK_EQUAL( 0.0 , item.get< double >(0) ); - BOOST_CHECK_EQUAL( 1.25 , item.get< double >(2) ); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParsePORO.cpp b/src/opm/parser/eclipse/IntegrationTests/ParsePORO.cpp deleted file mode 100644 index a4218fd00..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParsePORO.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE(ParsePOROandPERMX) { - Parser parser; - std::string poroFile(pathprefix() + "PORO/PORO1"); - auto deck = parser.parseFile(poroFile, ParseContext()); - const auto& kw1 = deck.getKeyword("PORO" , 0); - const auto& kw2 = deck.getKeyword("PERMX" , 0); - - BOOST_CHECK_THROW( kw1.getIntData() , std::logic_error ); - BOOST_CHECK_THROW( kw1.getStringData() , std::logic_error ); - - { - const std::vector& poro = kw1.getRawDoubleData(); - BOOST_CHECK_EQUAL( 440U , poro.size() ); - BOOST_CHECK_EQUAL( 0.233782813 , poro[0]); - BOOST_CHECK_EQUAL( 0.251224369 , poro[1]); - BOOST_CHECK_EQUAL( 0.155628711 , poro[439]); - } - - { - const std::vector& permx = kw2.getSIDoubleData(); - const std::vector& permxRAW = kw2.getRawDoubleData(); - BOOST_CHECK_EQUAL( 1000U , permx.size() ); - BOOST_CHECK_EQUAL( 1000U , permxRAW.size() ); - - BOOST_CHECK_CLOSE( Metric::Permeability * 1 , permx[0] , 0.001); - BOOST_CHECK_CLOSE( Metric::Permeability * 2 , permx[1] , 0.001); - BOOST_CHECK_CLOSE( Metric::Permeability * 3 , permx[2] , 0.001); - BOOST_CHECK_CLOSE( Metric::Permeability * 10, permx[999] , 0.001); - } -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParsePRORDER.cpp b/src/opm/parser/eclipse/IntegrationTests/ParsePRORDER.cpp deleted file mode 100644 index 3e302a98e..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParsePRORDER.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - 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 - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE( parse_PRORDER ) { - const std::string input = R"( --- PROD NO 1 NO 2 NO 3 NO 4 NO 5 --- ORDER OPTN OPTN OPTN OPTN OPTN -PRORDER - DRILL / - NO / - -PRORDER - DRILL THP REPREF / - NO / - )"; - Parser().parseString( input ); -} - diff --git a/src/opm/parser/eclipse/IntegrationTests/ParsePVTG.cpp b/src/opm/parser/eclipse/IntegrationTests/ParsePVTG.cpp deleted file mode 100644 index 58434ca0a..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParsePVTG.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - Copyright (C) 2013 by Andreas Lauser - - 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 . -*/ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -using namespace Opm; - -const char *pvtgData = "\n\ -TABDIMS\n\ --- NTSFUN NTPVT NSSFUN NPPVT NTFIP NRPVT\n\ - 1 2 30 24 10 20 /\n\ -\n\ -PVTG\n\ ---\n\ - 20.00 0.00002448 0.061895 0.01299\n\ - 0.00001224 0.061810 0.01300\n\ - 0.00000000 0.061725 0.01300 /\n\ - 40.00 0.00000628 0.030252 0.01383\n\ - 0.00000314 0.030249 0.01383\n\ - 0.00000000 0.030245 0.01383 /\n\ -/\n\ - 197.66 0.00006327 1* 0.02160\n\ - 0.00003164 * 0.02122\n\ - 0.00000000 0.005860 0.02086 /\n\ - 231.13 0.00010861 0.005042 0.02477\n\ - 0.00005431 0.005061 0.02389\n\ - 0.00000000 0.005082 0.02306 /\n\ - /\n"; - -BOOST_AUTO_TEST_CASE( parse_PVTG_OK ) { - Parser parser; - auto deck = parser.parseString(pvtgData, ParseContext()); - const auto& kw1 = deck.getKeyword("PVTG" , 0); - BOOST_CHECK_EQUAL(5U , kw1.size()); - - const auto& record0 = kw1.getRecord(0); - const auto& record1 = kw1.getRecord(1); - const auto& record2 = kw1.getRecord(2); - const auto& record3 = kw1.getRecord(3); - const auto& record4 = kw1.getRecord(4); - - const auto& item0_0 = record0.getItem("GAS_PRESSURE"); - const auto& item0_1 = record0.getItem("DATA"); - BOOST_CHECK_EQUAL(1U , item0_0.size()); - BOOST_CHECK_EQUAL(9U , item0_1.size()); - BOOST_CHECK_EQUAL(2U , record0.size()); - - const auto& item1_0 = record1.getItem("GAS_PRESSURE"); - const auto& item1_1 = record1.getItem("DATA"); - BOOST_CHECK_EQUAL(1U , item1_0.size()); - BOOST_CHECK_EQUAL(9U , item1_1.size()); - BOOST_CHECK_EQUAL(2U , record1.size()); - - const auto& item2_0 = record2.getItem("GAS_PRESSURE"); - const auto& item2_1 = record2.getItem("DATA"); - BOOST_CHECK( item2_0.defaultApplied(0)); - BOOST_CHECK_EQUAL(0U , item2_1.size()); - BOOST_CHECK_EQUAL(2U , record2.size()); - - - const auto& item3_0 = record3.getItem("GAS_PRESSURE"); - const auto& item3_1 = record3.getItem("DATA"); - BOOST_CHECK( !item3_1.defaultApplied(0)); - BOOST_CHECK( item3_1.defaultApplied(1)); - BOOST_CHECK( !item3_1.defaultApplied(2)); - BOOST_CHECK( !item3_1.defaultApplied(3)); - BOOST_CHECK( item3_1.defaultApplied(4)); - BOOST_CHECK( !item3_1.defaultApplied(5)); - BOOST_CHECK_EQUAL(1U , item3_0.size()); - BOOST_CHECK_EQUAL(9U , item3_1.size()); - BOOST_CHECK_EQUAL(2U , record3.size()); - - - const auto& item4_0 = record4.getItem("GAS_PRESSURE"); - const auto& item4_1 = record4.getItem("DATA"); - BOOST_CHECK_EQUAL(1U , item4_0.size()); - BOOST_CHECK_EQUAL(9U , item4_1.size()); - BOOST_CHECK_EQUAL(2U , record4.size()); - - /* - { - Opm::PvtgTable pvtgTable; - pvtgTable.initFORUNITTESTONLY(kw1, 0); - - const auto &outerTable = *pvtgTable.getOuterTable(); - const auto &innerTable0 = *pvtgTable.getInnerTable(0); - - BOOST_CHECK_EQUAL(2U, outerTable.numRows()); - BOOST_CHECK_EQUAL(4U, outerTable.numColumns()); - BOOST_CHECK_EQUAL(3U, innerTable0.numRows()); - BOOST_CHECK_EQUAL(3U, innerTable0.numColumns()); - - BOOST_CHECK_EQUAL(20.0e5, outerTable.getPressureColumn()[0]); - BOOST_CHECK_EQUAL(0.00002448, outerTable.getOilSolubilityColumn()[0]); - BOOST_CHECK_EQUAL(outerTable.getOilSolubilityColumn()[0], innerTable0.getOilSolubilityColumn()[0]); - BOOST_CHECK_EQUAL(0.061895, outerTable.getGasFormationFactorColumn()[0]); - BOOST_CHECK_EQUAL(outerTable.getGasFormationFactorColumn()[0], innerTable0.getGasFormationFactorColumn()[0]); - BOOST_CHECK_EQUAL(1.299e-5, outerTable.getGasViscosityColumn()[0]); - BOOST_CHECK_EQUAL(outerTable.getGasViscosityColumn()[0], innerTable0.getGasViscosityColumn()[0]); - } - */ -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParsePVTO.cpp b/src/opm/parser/eclipse/IntegrationTests/ParsePVTO.cpp deleted file mode 100644 index 194c8a523..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParsePVTO.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - Copyright (C) 2013 by Andreas Lauser - - 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 . -*/ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -using namespace Opm; - -const char *pvtoData = "\n\ -TABDIMS\n\ --- NTSFUN NTPVT NSSFUN NPPVT NTFIP NRPVT\n\ - 1 2 30 24 10 20 /\n\ -\n\ -PVTO\n\ --- Rs PO BO MUO\n\ - 1e-3 1 1.01 1.02\n\ - 250 1.15 0.95\n\ - 500 1.20 0.93 /\n\ - 1e-2 14.8 1.05 1.03\n\ - 251 1.25 0.98\n\ - 502 1.30 0.95 /\n\ -/\n\ - 1e-1 1.1 1.02 1.03\n\ - 253 1.16 0.96\n\ - 504 1.21 0.97 /\n\ - 1e00 15 1.06 1.04\n\ - 255 1.26 0.99\n\ - 506 1.31 0.96 /\n\ -/\n"; - -BOOST_AUTO_TEST_CASE( parse_PVTO_OK ) { - Parser parser; - auto deck = parser.parseString(pvtoData, ParseContext()); - const auto& kw1 = deck.getKeyword("PVTO" , 0); - BOOST_CHECK_EQUAL(5U , kw1.size()); - - const auto& record0 = kw1.getRecord(0); - const auto& record1 = kw1.getRecord(1); - const auto& record2 = kw1.getRecord(2); - const auto& record3 = kw1.getRecord(3); - const auto& record4 = kw1.getRecord(4); - - const auto& item0_0 = record0.getItem("RS"); - const auto& item0_1 = record0.getItem("DATA"); - BOOST_CHECK_EQUAL(1U , item0_0.size()); - BOOST_CHECK_EQUAL(9U , item0_1.size()); - BOOST_CHECK_EQUAL(2U , record0.size()); - - const auto& item1_0 = record1.getItem("RS"); - const auto& item1_1 = record1.getItem("DATA"); - BOOST_CHECK_EQUAL(1U , item1_0.size()); - BOOST_CHECK_EQUAL(9U , item1_1.size()); - BOOST_CHECK_EQUAL(2U , record1.size()); - - const auto& item2_0 = record2.getItem("RS"); - const auto& item2_1 = record2.getItem("DATA"); - BOOST_CHECK(item2_0.defaultApplied(0)); - BOOST_CHECK_EQUAL(0U , item2_1.size()); - BOOST_CHECK_EQUAL(2U , record2.size()); - - const auto& item3_0 = record3.getItem("RS"); - const auto& item3_1 = record3.getItem("DATA"); - BOOST_CHECK_EQUAL(1U , item3_0.size()); - BOOST_CHECK_EQUAL(9U , item3_1.size()); - BOOST_CHECK_EQUAL(2U , record3.size()); - - const auto& item4_0 = record4.getItem("RS"); - const auto& item4_1 = record4.getItem("DATA"); - BOOST_CHECK_EQUAL(1U , item4_0.size()); - BOOST_CHECK_EQUAL(9U , item4_1.size()); - BOOST_CHECK_EQUAL(2U , record4.size()); - - - Opm::PvtoTable pvtoTable(kw1 , 0); - BOOST_CHECK_EQUAL(2, pvtoTable.size()); - - const auto &table0 = pvtoTable.getUnderSaturatedTable(0); - const auto& BO = table0.getColumn( "BO" ); - - BOOST_CHECK_EQUAL( 3, table0.numRows()); - BOOST_CHECK_EQUAL( 3, table0.numColumns()); - BOOST_CHECK_EQUAL( BO.front( ) , 1.01 ); - BOOST_CHECK_EQUAL( BO.back( ) , 1.20 ); - - BOOST_CHECK_CLOSE(1.15 , table0.evaluate( "BO" , 250*1e5 ) , 1e-6); - - BOOST_CHECK_CLOSE( 1.15 , pvtoTable.evaluate( "BO" , 1e-3 , 250*1e5 ) , 1e-6 ); - BOOST_CHECK_CLOSE( 1.15 , pvtoTable.evaluate( "BO" , 0.0 , 250*1e5 ) , 1e-6 ); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseRSVD.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseRSVD.cpp deleted file mode 100644 index 58ee59d91..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseRSVD.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright 2013 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 . -*/ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include -#include -#include -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( parse_EQUIL_OK ) { - Parser parser; - std::string pvtgFile(pathprefix() + "RSVD/RSVD.txt"); - auto deck = parser.parseFile(pvtgFile, ParseContext()); - const auto& kw1 = deck.getKeyword("RSVD" , 0); - BOOST_CHECK_EQUAL( 6U , kw1.size() ); - - - const auto& rec1 = kw1.getRecord(0); - const auto& rec3 = kw1.getRecord(2); - - const auto& item1 = rec1.getItem("table"); - BOOST_CHECK( fabs(item1.getSIDouble(0) - 2382) < 0.001); - - const auto& item3 = rec3.getItem("table"); - BOOST_CHECK( fabs(item3.getSIDouble(7) - 106.77) < 0.001); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseSGOF.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseSGOF.cpp deleted file mode 100644 index f765e5ba0..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseSGOF.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - 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 . -*/ -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include -#include -#include - -#include -#include - -#include - -using namespace Opm; - -// the data which ought to be parsed -const char *parserData = - "TABDIMS\n" - "-- NTSFUN NTPVT NSSFUN NPPVT NTFIP NRPVT\n" - " 1 1 30 1 1 1 /\n" - "\n" - "-- S_g k_rg k_rog p_cog\n" - "SGOF\n" - " 0.1 0.0 1.0 0.0\n" - " 0.2 0.1 1.0 1.0\n" - " 0.3 0.2 0.9 2.0\n" - " 0.4 0.3 0.8 3.0\n" - " 0.5 0.5 0.5 4.0\n" - " 0.6 0.6 0.4 5.0\n" - " 0.7 0.8 0.3 6.0\n" - " 0.8 0.9 0.2 7.0\n" - " 0.9 0.5 0.1 8.0\n" - " 1.0 1.0 0.1 9.0 /\n"; - -BOOST_AUTO_TEST_CASE( parse_SGOF_OK ) { - Parser parser; - auto deck = parser.parseString(parserData, ParseContext()); - - const auto& kw1 = deck.getKeyword("SGOF"); - BOOST_CHECK_EQUAL(1U , kw1.size()); - const auto& record0 = kw1.getRecord(0); - BOOST_CHECK_EQUAL(1U , record0.size()); - const auto& item0 = record0.getItem(0); - BOOST_CHECK_EQUAL(10U * 4, item0.size()); - - Opm::SgofTable sgofTable(deck.getKeyword("SGOF").getRecord(0).getItem(0), false); - BOOST_CHECK_EQUAL(10U, sgofTable.getSgColumn().size()); - BOOST_CHECK_EQUAL(0.1, sgofTable.getSgColumn()[0]); - BOOST_CHECK_EQUAL(0.0, sgofTable.getKrgColumn()[0]); - BOOST_CHECK_EQUAL(1.0, sgofTable.getKrogColumn()[0]); - BOOST_CHECK_EQUAL(0.0, sgofTable.getPcogColumn()[0]); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseSLGOF.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseSLGOF.cpp deleted file mode 100644 index 71f3073ee..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseSLGOF.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - 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 . -*/ -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include -#include -#include - -#include -#include - -#include - -using namespace Opm; - -// the data which ought to be parsed -const char *parserData = - "TABDIMS\n" - "-- NTSFUN NTPVT NSSFUN NPPVT NTFIP NRPVT\n" - " 1 1 30 1 1 1 /\n" - "\n" - "-- S_l k_rg k_rog p_cog\n" - "SLGOF\n" - " 0.1 1.0 0.0 9.0\n" - " 0.2 0.9 0.2 8.0\n" - " 0.3 0.8 0.3 7.0\n" - " 0.4 0.7 0.3 6.0\n" - " 0.5 0.6 0.4 5.0\n" - " 0.6 0.5 0.5 4.0\n" - " 0.7 0.3 0.8 3.0\n" - " 0.8 0.2 0.9 2.0\n" - " 0.9 0.1 1.0 1.0\n" - " 1.0 0.0 1.0 0.0 /\n"; - -BOOST_AUTO_TEST_CASE( parse_SLGOF_OK ) { - Parser parser; - auto deck = parser.parseString(parserData, ParseContext()); - - const auto& kw1 = deck.getKeyword("SLGOF"); - const auto& record0 = kw1.getRecord(0); - const auto& item0 = record0.getItem(0); - BOOST_CHECK_EQUAL(1U , kw1.size()); - BOOST_CHECK_EQUAL(1U , record0.size()); - BOOST_CHECK_EQUAL(10U * 4, item0.size()); - - Opm::SlgofTable slgofTable( deck.getKeyword("SLGOF").getRecord(0).getItem(0), false ); - BOOST_CHECK_EQUAL(10U, slgofTable.getSlColumn().size()); - BOOST_CHECK_EQUAL(0.1, slgofTable.getSlColumn()[0]); - BOOST_CHECK_EQUAL(1.0, slgofTable.getSlColumn()[9]); - BOOST_CHECK_EQUAL(0.0, slgofTable.getKrgColumn()[9]); - BOOST_CHECK_EQUAL(1.0, slgofTable.getKrogColumn()[9]); - BOOST_CHECK_EQUAL(0.0, slgofTable.getPcogColumn()[9]); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseSWOF.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseSWOF.cpp deleted file mode 100644 index cbca31836..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseSWOF.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - Copyright (C) 2013 by Andreas Lauser - - 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 . -*/ - - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include -#include -#include - -#include -#include - -#include - -using namespace Opm; - -// the data which ought to be parsed -const char *parserData = - "TABDIMS\n" - "-- NTSFUN NTPVT NSSFUN NPPVT NTFIP NRPVT\n" - " 1 1 30 1 1 1 /\n" - "\n" - "-- S_w k_rw k_row p_cow\n" - "SWOF\n" - " 0.1 2* 0.0\n" - " 0.2 0.1 1.0 1.0\n" - " 0.3 1* 0.9 2.0\n" - " 0.4 0.3 1* 3.0\n" - " 0.5 0.5 0.5 4.0\n" - " 0.6 0.6 0.4 1*\n" - " 0.7 0.8 0.3 6.0\n" - " 0.8 0.9 0.2 7.0\n" - " 0.9 0.5 0.1 8.0\n" - " 1.0 1* 0.1 9.0 /\n"; - -BOOST_AUTO_TEST_CASE( parse_SWOF_OK ) { - Parser parser; - auto deck = parser.parseString(parserData, ParseContext()); - - const auto& kw1 = deck.getKeyword("SWOF"); - const auto& record0 = kw1.getRecord(0); - const auto& item0 = record0.getItem(0); - BOOST_CHECK_EQUAL(1U , kw1.size()); - BOOST_CHECK_EQUAL(1U , record0.size()); - BOOST_CHECK_EQUAL(10U * 4, item0.size()); - - Opm::SwofTable swofTable(deck.getKeyword("SWOF").getRecord(0).getItem(0), false); - BOOST_CHECK_EQUAL(10U, swofTable.getSwColumn().size()); - BOOST_CHECK_CLOSE(0.1, swofTable.getSwColumn()[0], 1e-8); - BOOST_CHECK_CLOSE(1.0, swofTable.getSwColumn().back(), 1e-8); - - BOOST_CHECK_CLOSE(0.1, swofTable.getKrwColumn()[0], 1e-8); - BOOST_CHECK_CLOSE(0.1, swofTable.getKrwColumn()[1], 1e-8); - BOOST_CHECK_CLOSE(0.2, swofTable.getKrwColumn()[2], 1e-8); - BOOST_CHECK_CLOSE(0.3, swofTable.getKrwColumn()[3], 1e-8); - BOOST_CHECK_CLOSE(0.5, swofTable.getKrwColumn().back(), 1e-8); - - BOOST_CHECK_CLOSE(1.0, swofTable.getKrowColumn()[0], 1e-8); - BOOST_CHECK_CLOSE(0.9, swofTable.getKrowColumn()[2], 1e-8); - BOOST_CHECK_CLOSE(0.7, swofTable.getKrowColumn()[3], 1e-8); - BOOST_CHECK_CLOSE(0.5, swofTable.getKrowColumn()[4], 1e-8); - - BOOST_CHECK_CLOSE(4.0e5, swofTable.getPcowColumn()[4], 1e-8); - BOOST_CHECK_CLOSE(5.0e5, swofTable.getPcowColumn()[5], 1e-8); - BOOST_CHECK_CLOSE(6.0e5, swofTable.getPcowColumn()[6], 1e-8); - - BOOST_CHECK_CLOSE(0.10, swofTable.evaluate("KRW", -0.1), 1e-8); - BOOST_CHECK_CLOSE(0.15, swofTable.evaluate("KRW", 0.25), 1e-8); - BOOST_CHECK_CLOSE(0.50, swofTable.evaluate("KRW", 1.1), 1e-8); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseTITLE.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseTITLE.cpp deleted file mode 100644 index 4e58cfbf2..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseTITLE.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include -#include - -#include -#include -#include - -#include -#include - -using namespace Opm; - - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( parse_TITLE_OK ) { - Parser parser; - std::string fileWithTitleKeyword(pathprefix() + "TITLE/TITLE1.txt"); - - auto deck = parser.parseFile(fileWithTitleKeyword, ParseContext()); - - BOOST_CHECK_EQUAL(size_t(2), deck.size()); - BOOST_CHECK_EQUAL (true, deck.hasKeyword("TITLE")); - - const auto& titleKeyword = deck.getKeyword("TITLE"); - const auto& record = titleKeyword.getRecord(0); - const auto& item = record.getItem(0); - - std::vector itemValue = item.getData< std::string >(); - std::string itemValueString = boost::algorithm::join(itemValue, " "); - - BOOST_CHECK_EQUAL (0, itemValueString.compare("This is the title of the model.")); - BOOST_CHECK_EQUAL (true, deck.hasKeyword("START")); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseTOPS.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseTOPS.cpp deleted file mode 100644 index c92611f4a..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseTOPS.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include -#include -#include -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( PARSE_TOPS_OK) { - Parser parser; - std::string deckFile(pathprefix() + "GRID/TOPS.DATA"); - ParseContext parseContext; - auto deck = parser.parseFile(deckFile, parseContext); - EclipseState state(deck, parseContext); - const auto& grid = state.getInputGrid(); - - BOOST_CHECK_EQUAL( grid.getNX() , 9 ); - BOOST_CHECK_EQUAL( grid.getNY() , 9 ); - BOOST_CHECK_EQUAL( grid.getNZ() , 2 ); - - for (size_t g=0; g < 9*9*2; g++) - BOOST_CHECK_CLOSE( grid.getCellVolume( g ) , 400*300*10 , 0.1); - - for (size_t k=0; k < grid.getNZ(); k++) { - for (size_t j=0; j < grid.getNY(); j++) { - for (size_t i=0; i < grid.getNX(); i++) { - - auto pos = grid.getCellCenter( i,j,k ); - BOOST_CHECK_CLOSE( std::get<0>(pos) , i*400 + 200 , 0.10 ); - BOOST_CHECK_CLOSE( std::get<1>(pos) , j*300 + 150 , 0.10 ); - BOOST_CHECK_CLOSE( std::get<2>(pos) , k*10 + 5 + 2202 , 0.10 ); - - } - } - } -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseTRACERS.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseTRACERS.cpp deleted file mode 100644 index d163f1412..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseTRACERS.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - 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 - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE( parse_TRACERS ) { - const std::string input = R"( -RUNSPEC --- NO OIL NO WAT NO GAS NO ENV DIFF MAX MIN TRACER --- TRACERS TRACERS TRACERS TRACERS CONTL NONLIN NONLIN NONLIN -TRACERS - 0 0 1 0 'NODIFF' 1* 1* 1* / - - )"; - Parser().parseString( input ); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseTUNINGDP.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseTUNINGDP.cpp deleted file mode 100644 index 38003fb5a..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseTUNINGDP.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - 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 - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE( parse_TUNINGDP ) { - const std::string input = R"( -TUNINGDP -/ - -TUNINGDP - 1.0 -/ - - -TUNINGDP - 1.0 2.0 -/ - -TUNINGDP - 1.0 2.0 3.0 -/ - -TUNINGDP - 1.0 2.0 3.0 4.0 -/ - -)"; - Parser().parseString( input ); -} - diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseTVDP.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseTVDP.cpp deleted file mode 100644 index 3486654d7..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseTVDP.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserTVPD -#include - -#include -#include -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE(ParseTVDP) { - Parser parser; - std::string poroFile(pathprefix() + "TVDP/TVDP1"); - auto deck = parser.parseFile(poroFile, ParseContext()); - - BOOST_CHECK(!deck.hasKeyword("TVDP*")); - BOOST_CHECK( deck.hasKeyword("TVDPA")); - BOOST_CHECK( deck.hasKeyword("TVDP1")); - BOOST_CHECK( deck.hasKeyword("TVDPXX")); - BOOST_CHECK( deck.hasKeyword("TVDPYY")); -} - diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseTVPD.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseTVPD.cpp deleted file mode 100644 index 7f46f4e50..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseTVPD.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserTVPD -#include - -#include -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(AddDataKeywordFromJson_correctlyConfigured) { - Parser parser; - std::string poroFile("testdata/integration_tests/TVPD/TVPD1"); - auto deck = parser.parseFile(poroFile); - - BOOST_CHECK( deck.hasKeyword("TVDPA")); - BOOST_CHECK( deck.hasKeyword("TVDP1")); - BOOST_CHECK( deck.hasKeyword("TVDPXX")); - BOOST_CHECK( deck.hasKeyword("TVDPYY")); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseVFPPROD.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseVFPPROD.cpp deleted file mode 100644 index 63b52f393..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseVFPPROD.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include -#include -#include -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( parse_VFPPROD_OK ) { - Parser parser; - std::string file(pathprefix() + "VFPPROD/VFPPROD1"); - BOOST_CHECK( parser.isRecognizedKeyword("VFPPROD")); - - auto deck = parser.parseFile(file, ParseContext()); - - const auto& VFPPROD1 = deck.getKeyword("VFPPROD" , 0); - const auto& BPR = deck.getKeyword("BPR" , 0); - const auto& VFPPROD2 = deck.getKeyword("VFPPROD" , 1); - - BOOST_CHECK_EQUAL( 573U , VFPPROD1.size() ); - BOOST_CHECK_EQUAL( 1U , BPR.size()); - BOOST_CHECK_EQUAL( 573U , VFPPROD2.size()); - - { - const auto& record = VFPPROD1.getRecord(0); - - BOOST_CHECK_EQUAL( record.getItem("TABLE").get< int >(0) , 32 ); - BOOST_CHECK_EQUAL( record.getItem("DATUM_DEPTH").getSIDouble(0) , 394); - BOOST_CHECK_EQUAL( record.getItem("RATE_TYPE").get< std::string >(0) , "LIQ"); - BOOST_CHECK_EQUAL( record.getItem("WFR").get< std::string >(0) , "WCT"); - BOOST_CHECK_EQUAL( record.getItem("GFR").get< std::string >(0) , "GOR"); - } - - { - const auto& record = VFPPROD1.getRecord(1); - const auto& item = record.getItem("FLOW_VALUES"); - - BOOST_CHECK_EQUAL( item.size() , 12 ); - BOOST_CHECK_EQUAL( item.get< double >(0) , 100 ); - BOOST_CHECK_EQUAL( item.get< double >(11) , 20000 ); - } - - { - const auto& record = VFPPROD1.getRecord(2); - const auto& item = record.getItem("THP_VALUES"); - - BOOST_CHECK_EQUAL( item.size() , 7 ); - BOOST_CHECK_CLOSE( item.get< double >(0) , 16.01 , 0.0001 ); - BOOST_CHECK_CLOSE( item.get< double >(6) , 61.01 , 0.0001 ); - } - - { - const auto& record = VFPPROD1.getRecord(3); - const auto& item = record.getItem("WFR_VALUES"); - - BOOST_CHECK_EQUAL( item.size() , 9 ); - BOOST_CHECK_CLOSE( item.get< double >(1) , 0.1 , 0.0001 ); - BOOST_CHECK_CLOSE( item.get< double >(7) , 0.9 , 0.0001 ); - } - - { - const auto& record = VFPPROD1.getRecord(4); - const auto& item = record.getItem("GFR_VALUES"); - - BOOST_CHECK_EQUAL( item.size() , 9 ); - BOOST_CHECK_EQUAL( item.get< double >(0) , 90 ); - BOOST_CHECK_EQUAL( item.get< double >(8) , 10000 ); - } - - { - const auto& record = VFPPROD1.getRecord(5); - const auto& item = record.getItem("ALQ_VALUES"); - - BOOST_CHECK_EQUAL( item.size() , 1 ); - BOOST_CHECK_EQUAL( item.get< double >(0) , 0 ); - } - - { - const auto& record = VFPPROD1.getRecord(6); - - { - const auto& item = record.getItem("THP_INDEX"); - BOOST_CHECK_EQUAL( item.size() , 1 ); - BOOST_CHECK_EQUAL( item.get< int >(0) , 1 ); - } - - { - const auto& item = record.getItem("WFR_INDEX"); - BOOST_CHECK_EQUAL( item.size() , 1 ); - BOOST_CHECK_EQUAL( item.get< int >(0) , 1 ); - } - { - const auto& item = record.getItem("GFR_INDEX"); - BOOST_CHECK_EQUAL( item.size() , 1 ); - BOOST_CHECK_EQUAL( item.get< int >(0) , 1 ); - } - { - const auto& item = record.getItem("ALQ_INDEX"); - BOOST_CHECK_EQUAL( item.size() , 1 ); - BOOST_CHECK_EQUAL( item.get< int >(0) , 1 ); - } - { - const auto& item = record.getItem("VALUES"); - BOOST_CHECK_EQUAL( item.size() , 12 ); - BOOST_CHECK_EQUAL( item.get< double >(0) , 44.85 ); - BOOST_CHECK_EQUAL( item.get< double >(11) , 115.14 ); - } - } - - { - const auto& record = VFPPROD1.getRecord(572); - { - const auto& item = record.getItem("THP_INDEX"); - BOOST_CHECK_EQUAL( item.size() , 1 ); - BOOST_CHECK_EQUAL( item.get< int >(0) , 7 ); - } - { - const auto& item = record.getItem("WFR_INDEX"); - BOOST_CHECK_EQUAL( item.size() , 1 ); - BOOST_CHECK_EQUAL( item.get< int >(0) , 9 ); - } - { - const auto& item = record.getItem("GFR_INDEX"); - BOOST_CHECK_EQUAL( item.size() , 1 ); - BOOST_CHECK_EQUAL( item.get< int >(0) , 9 ); - } - { - const auto& item = record.getItem("ALQ_INDEX"); - BOOST_CHECK_EQUAL( item.size() , 1 ); - BOOST_CHECK_EQUAL( item.get< int >(0) , 1 ); - } - { - const auto& item = record.getItem("VALUES"); - BOOST_CHECK_EQUAL( item.size() , 12 ); - BOOST_CHECK_EQUAL( item.get< double >(0) , 100.80 ); - BOOST_CHECK_EQUAL( item.get< double >(11) , 147.79 ); - } - } -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseWCONHIST.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseWCONHIST.cpp deleted file mode 100644 index b9723ee53..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseWCONHIST.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include -#include -#include -#include - -#include -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( parse_WCHONHIST_OK ) { - Parser parser; - std::string wconhistFile(pathprefix() + "WCONHIST/WCONHIST1"); - auto deck = parser.parseFile(wconhistFile, ParseContext()); - const auto& kw1 = deck.getKeyword("WCONHIST" , 0); - BOOST_CHECK_EQUAL( 3U , kw1.size() ); - - - const auto& rec1 = kw1.getRecord(0); - BOOST_CHECK_EQUAL( 11U , rec1.size() ); - - const auto& rec3 = kw1.getRecord(2); - BOOST_CHECK_EQUAL( 11U , rec3.size() ); - - const auto& item1 = rec1.getItem("WELL"); - const auto& item1_index = rec1.getItem(0); - - BOOST_CHECK_EQUAL( &item1 , &item1_index ); - BOOST_CHECK_EQUAL( "OP_1" , item1.get< std::string >(0)); - - - const auto& kw2 = deck.getKeyword( "WCONHIST", 1 ); - BOOST_CHECK_EQUAL( "OP_3" , rec3.getItem("WELL").get< std::string >(0)); - BOOST_CHECK_EQUAL( 2U , deck.count("WCONHIST")); - BOOST_CHECK_EQUAL( "OP_3_B" , kw2.getRecord( 2 ).getItem("WELL").get< std::string >(0)); - BOOST_CHECK( !deck.hasKeyword( "DIMENS" )); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseWDFACCOR.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseWDFACCOR.cpp deleted file mode 100644 index 43f25f972..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseWDFACCOR.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - 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 - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE( parse_WDFACCOR ) { - const std::string input = R"( --- WELL COEFF POWER POWER --- NAME A B C -WDFACCOR - '*' 1.200E-3 -1.045 0.0 / -/ -)"; - Parser().parseString( input ); -} - diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseWEFAC.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseWEFAC.cpp deleted file mode 100644 index eb34c57fb..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseWEFAC.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - 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 - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE( parse_WEFAC ) { - const std::string input = R"( --- WELL EFF NETWK --- NAME FACT OPTN - -WEFAC - '* ' 0.950 / -/ -)"; - Parser().parseString( input ); -} - diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseWORKLIM.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseWORKLIM.cpp deleted file mode 100644 index 88b9102a9..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseWORKLIM.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - 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 - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE( parse_WORKLIM ) { - const std::string input = R"( -WORKLIM - 10.0 -/ - -)"; - Parser().parseString( input ); -} - diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseWellProbe.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseWellProbe.cpp deleted file mode 100644 index 93a334aef..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseWellProbe.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserWellProbe -#include - -#include -#include -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(ParseWellProbe) { - const char *validDeckString = - "WBHP\n" - "/\n" - "\n" - "WOPR\n" - "/\n"; - - Parser parser; - - // TODO: for some reason, the parser does not seem to throw here. Investigate -/* - const char *invalidDeckString = - "WELL_PROBE\n" - "/\n"; - BOOST_CHECK_THROW(parser->parseString(invalidDeckString), std::invalid_argument); -*/ - - auto deck = parser.parseString(validDeckString, ParseContext()); - BOOST_CHECK( !deck.hasKeyword("WELL_PROBE")); - BOOST_CHECK( deck.hasKeyword("WBHP")); - BOOST_CHECK( deck.hasKeyword("WOPR")); - BOOST_CHECK( !deck.hasKeyword("WWPR")); -} diff --git a/src/opm/parser/eclipse/IntegrationTests/ParseWellWithWildcards.cpp b/src/opm/parser/eclipse/IntegrationTests/ParseWellWithWildcards.cpp deleted file mode 100644 index a63da5735..000000000 --- a/src/opm/parser/eclipse/IntegrationTests/ParseWellWithWildcards.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserIntegrationTests -#include - -#include - -#include -#include - -#include -#include -#include -#include - -using namespace Opm; - -inline std::string pathprefix() { - return boost::unit_test::framework::master_test_suite().argv[1]; -} - -BOOST_AUTO_TEST_CASE( parse_WCONPROD_OK ) { - Parser parser; - std::string wconprodFile(pathprefix() + "WellWithWildcards/WCONPROD1"); - auto deck = parser.parseFile(wconprodFile, ParseContext()); - EclipseGrid grid(30,30,30); - TableManager table ( deck ); - Eclipse3DProperties eclipseProperties ( deck , table, grid); - Schedule sched(ParseContext(), grid, eclipseProperties, deck, Phases(true, true, true) ); - - BOOST_CHECK_EQUAL(5U, sched.numWells()); - BOOST_CHECK(sched.hasWell("INJE1")); - BOOST_CHECK(sched.hasWell("PROD2")); - BOOST_CHECK(sched.hasWell("PROD3")); - BOOST_CHECK(sched.hasWell("PROD4")); - BOOST_CHECK(sched.hasWell("PROX5")); - - { - auto* well = sched.getWell("PROD2"); - BOOST_CHECK_CLOSE(1000/Metric::Time, well->getProductionProperties(0).OilRate, 0.001); - BOOST_CHECK_CLOSE(1500/Metric::Time, well->getProductionProperties(1).OilRate, 0.001); - } - - { - auto* well = sched.getWell("PROD3"); - BOOST_CHECK_CLOSE(0/Metric::Time, well->getProductionProperties(0).OilRate, 0.001); - BOOST_CHECK_CLOSE(1500/Metric::Time, well->getProductionProperties(1).OilRate, 0.001); - } - - { - auto* well = sched.getWell("PROX5"); - BOOST_CHECK_CLOSE(2000/Metric::Time, well->getProductionProperties(0).OilRate, 0.001); - BOOST_CHECK_CLOSE(2000/Metric::Time, well->getProductionProperties(1).OilRate, 0.001); - } -} - - -BOOST_AUTO_TEST_CASE( parse_WCONINJE_OK ) { - ParseContext parseContext; - Parser parser; - std::string wconprodFile(pathprefix() + "WellWithWildcards/WCONINJE1"); - auto deck = parser.parseFile(wconprodFile, parseContext); - EclipseGrid grid(30,30,30); - TableManager table ( deck ); - Eclipse3DProperties eclipseProperties ( deck , table, grid); - Schedule sched( parseContext, grid, eclipseProperties, deck, Phases(true, true, true) ); - - BOOST_CHECK_EQUAL(5U, sched.numWells()); - BOOST_CHECK(sched.hasWell("PROD1")); - BOOST_CHECK(sched.hasWell("INJE2")); - BOOST_CHECK(sched.hasWell("INJE3")); - BOOST_CHECK(sched.hasWell("PROD4")); - BOOST_CHECK(sched.hasWell("INJX5")); - - { - auto* well = sched.getWell("INJE2"); - BOOST_CHECK_CLOSE(1000/Metric::Time, well->getInjectionProperties(0).surfaceInjectionRate, 0.001); - BOOST_CHECK_CLOSE(1500/Metric::Time, well->getInjectionProperties(1).surfaceInjectionRate, 0.001); - } - - { - auto* well = sched.getWell("INJE3"); - BOOST_CHECK_CLOSE(0/Metric::Time, well->getInjectionProperties(0).surfaceInjectionRate, 0.001); - BOOST_CHECK_CLOSE(1500/Metric::Time, well->getInjectionProperties(1).surfaceInjectionRate, 0.001); - } - - { - auto* well = sched.getWell("INJX5"); - BOOST_CHECK_CLOSE(2000/Metric::Time, well->getInjectionProperties(0).surfaceInjectionRate, 0.001); - BOOST_CHECK_CLOSE(2000/Metric::Time, well->getInjectionProperties(1).surfaceInjectionRate, 0.001); - } -} diff --git a/tests/parser/BoxManagerTests.cpp b/tests/parser/BoxManagerTests.cpp deleted file mode 100644 index 6f9145057..000000000 --- a/tests/parser/BoxManagerTests.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - Copyright 2014 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 -#include -#include -#include - -#define BOOST_TEST_MODULE BoxManagerTests -#include -#include - -#include -#include - - -BOOST_AUTO_TEST_CASE(CreateBoxManager) { - Opm::BoxManager boxManager(10,10,10); - Opm::Box box(10,10,10); - - BOOST_CHECK( box.equal( boxManager.getGlobalBox()) ); - BOOST_CHECK( box.equal( boxManager.getActiveBox()) ); - BOOST_CHECK( !boxManager.getInputBox() ); - BOOST_CHECK( !boxManager.getKeywordBox() ); -} - - - - -BOOST_AUTO_TEST_CASE(TestInputBox) { - Opm::BoxManager boxManager(10,10,10); - Opm::Box inputBox( boxManager.getGlobalBox(), 0,4,0,4,0,4); - - boxManager.setInputBox( 0,4,0,4,0,4 ); - BOOST_CHECK( inputBox.equal( boxManager.getInputBox()) ); - BOOST_CHECK( inputBox.equal( boxManager.getActiveBox()) ); - - - boxManager.endSection(); - BOOST_CHECK( !boxManager.getInputBox() ); - BOOST_CHECK( boxManager.getActiveBox().equal( boxManager.getGlobalBox())); -} - - - - -BOOST_AUTO_TEST_CASE(TestKeywordBox) { - Opm::BoxManager boxManager(10,10,10); - Opm::Box inputBox( boxManager.getGlobalBox() , 0,4,0,4,0,4); - Opm::Box keywordBox( boxManager.getGlobalBox() , 0,2,0,2,0,2); - - - boxManager.setInputBox( 0,4,0,4,0,4 ); - boxManager.setKeywordBox( 0,2,0,2,0,2 ); - BOOST_CHECK( inputBox.equal( boxManager.getInputBox()) ); - BOOST_CHECK( keywordBox.equal( boxManager.getKeywordBox()) ); - BOOST_CHECK( keywordBox.equal( boxManager.getActiveBox()) ); - - // Must end keyword first - BOOST_CHECK_THROW( boxManager.endSection() , std::invalid_argument ); - - boxManager.endKeyword(); - BOOST_CHECK( inputBox.equal( boxManager.getActiveBox()) ); - BOOST_CHECK( !boxManager.getKeywordBox() ); - - boxManager.endSection(); - BOOST_CHECK( !boxManager.getInputBox() ); - BOOST_CHECK( boxManager.getActiveBox().equal( boxManager.getGlobalBox())); -} diff --git a/tests/parser/BoxTests.cpp b/tests/parser/BoxTests.cpp index 1adfa714b..c18fbea17 100644 --- a/tests/parser/BoxTests.cpp +++ b/tests/parser/BoxTests.cpp @@ -28,6 +28,7 @@ #include #include +#include BOOST_AUTO_TEST_CASE(CreateBox) { BOOST_CHECK_THROW( new Opm::Box(-1,0,0) , std::invalid_argument); @@ -53,7 +54,7 @@ BOOST_AUTO_TEST_CASE(CreateBox) { for (i=0; i < box.getDim(0); i++) { size_t g = i + j*box.getDim(0) + k*box.getDim(0)*box.getDim(1); BOOST_CHECK_EQUAL( indexList[g] , g); - + } } } @@ -83,19 +84,17 @@ BOOST_AUTO_TEST_CASE(CreateSubBox) { BOOST_CHECK( !subBox2.isGlobal()); BOOST_CHECK_EQUAL( 60U , subBox2.size() ); - { - size_t i,j,k; - size_t d = 0; - const std::vector& indexList = subBox2.getIndexList(); + size_t i,j,k; + size_t d = 0; + const std::vector& indexList = subBox2.getIndexList(); - for (k=0; k < subBox2.getDim(2); k++) { - for (j=0; j < subBox2.getDim(1); j++) { - for (i=0; i < subBox2.getDim(0); i++) { + for (k=0; k < subBox2.getDim(2); k++) { + for (j=0; j < subBox2.getDim(1); j++) { + for (i=0; i < subBox2.getDim(0); i++) { - size_t g = (i + 1) + (j + 1)*globalBox.getDim(0) + (k + 1)*globalBox.getDim(0)*globalBox.getDim(1); - BOOST_CHECK_EQUAL( indexList[d] , g); - d++; - } + size_t g = (i + 1) + (j + 1)*globalBox.getDim(0) + (k + 1)*globalBox.getDim(0)*globalBox.getDim(1); + BOOST_CHECK_EQUAL( indexList[d] , g); + d++; } } } @@ -120,4 +119,56 @@ BOOST_AUTO_TEST_CASE(BoxEqual) { BOOST_CHECK( !subBox4.equal( subBox5 )); } +BOOST_AUTO_TEST_CASE(CreateBoxManager) { + Opm::BoxManager boxManager(10,10,10); + Opm::Box box(10,10,10); + BOOST_CHECK( box.equal( boxManager.getGlobalBox()) ); + BOOST_CHECK( box.equal( boxManager.getActiveBox()) ); + BOOST_CHECK( !boxManager.getInputBox() ); + BOOST_CHECK( !boxManager.getKeywordBox() ); +} + + + + +BOOST_AUTO_TEST_CASE(TestInputBox) { + Opm::BoxManager boxManager(10,10,10); + Opm::Box inputBox( boxManager.getGlobalBox(), 0,4,0,4,0,4); + + boxManager.setInputBox( 0,4,0,4,0,4 ); + BOOST_CHECK( inputBox.equal( boxManager.getInputBox()) ); + BOOST_CHECK( inputBox.equal( boxManager.getActiveBox()) ); + + + boxManager.endSection(); + BOOST_CHECK( !boxManager.getInputBox() ); + BOOST_CHECK( boxManager.getActiveBox().equal( boxManager.getGlobalBox())); +} + + + + +BOOST_AUTO_TEST_CASE(TestKeywordBox) { + Opm::BoxManager boxManager(10,10,10); + Opm::Box inputBox( boxManager.getGlobalBox() , 0,4,0,4,0,4); + Opm::Box keywordBox( boxManager.getGlobalBox() , 0,2,0,2,0,2); + + + boxManager.setInputBox( 0,4,0,4,0,4 ); + boxManager.setKeywordBox( 0,2,0,2,0,2 ); + BOOST_CHECK( inputBox.equal( boxManager.getInputBox()) ); + BOOST_CHECK( keywordBox.equal( boxManager.getKeywordBox()) ); + BOOST_CHECK( keywordBox.equal( boxManager.getActiveBox()) ); + + // Must end keyword first + BOOST_CHECK_THROW( boxManager.endSection() , std::invalid_argument ); + + boxManager.endKeyword(); + BOOST_CHECK( inputBox.equal( boxManager.getActiveBox()) ); + BOOST_CHECK( !boxManager.getKeywordBox() ); + + boxManager.endSection(); + BOOST_CHECK( !boxManager.getInputBox() ); + BOOST_CHECK( boxManager.getActiveBox().equal( boxManager.getGlobalBox())); +} diff --git a/tests/parser/CompletionTests.cpp b/tests/parser/CompletionTests.cpp index a7f4b41d5..b33dcd762 100644 --- a/tests/parser/CompletionTests.cpp +++ b/tests/parser/CompletionTests.cpp @@ -33,8 +33,23 @@ #include #include +#include #include +namespace Opm { + +inline std::ostream& operator<<( std::ostream& stream, const Completion& c ) { + return stream << "(" << c.getI() << "," << c.getJ() << "," << c.getK() << ")"; +} + +inline std::ostream& operator<<( std::ostream& stream, const CompletionSet& cs ) { + stream << "{ "; + for( const auto& c : cs ) stream << c << " "; + return stream << "}"; +} + +} + BOOST_AUTO_TEST_CASE(CreateCompletionOK) { @@ -69,6 +84,74 @@ BOOST_AUTO_TEST_CASE(CompletionTestssameCoordinate) { BOOST_CHECK_EQUAL( false , completion1.sameCoordinate( completion5 )); } +BOOST_AUTO_TEST_CASE(CreateCompletionSetOK) { + Opm::CompletionSet completionSet; + BOOST_CHECK_EQUAL( 0U , completionSet.size() ); +} +BOOST_AUTO_TEST_CASE(AddCompletionSizeCorrect) { + Opm::CompletionSet completionSet; + Opm::Completion completion1( 10,10,10, 1, 0.0,Opm::WellCompletion::OPEN , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); + Opm::Completion completion2( 11,10,10, 1, 0.0,Opm::WellCompletion::OPEN , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); + completionSet.add( completion1 ); + BOOST_CHECK_EQUAL( 1U , completionSet.size() ); + + completionSet.add( completion2 ); + BOOST_CHECK_EQUAL( 2U , completionSet.size() ); + + BOOST_CHECK_EQUAL( completion1 , completionSet.get(0) ); +} + + +BOOST_AUTO_TEST_CASE(CompletionSetGetOutOfRangeThrows) { + Opm::CompletionSet completionSet; + Opm::Completion completion1( 10,10,10,1, 0.0,Opm::WellCompletion::OPEN , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); + Opm::Completion completion2( 11,10,10,1, 0.0,Opm::WellCompletion::OPEN , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); + completionSet.add( completion1 ); + BOOST_CHECK_EQUAL( 1U , completionSet.size() ); + + completionSet.add( completion2 ); + BOOST_CHECK_EQUAL( 2U , completionSet.size() ); + + BOOST_CHECK_THROW( completionSet.get(10) , std::out_of_range ); +} + + + + +BOOST_AUTO_TEST_CASE(AddCompletionSameCellUpdates) { + Opm::CompletionSet completionSet; + Opm::Completion completion1( 10,10,10, 1, 0.0, Opm::WellCompletion::OPEN , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); + Opm::Completion completion2( 10,10,10, 1, 0.0,Opm::WellCompletion::SHUT , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); + + + completionSet.add( completion1 ); + BOOST_CHECK_EQUAL( 1U , completionSet.size() ); + + completionSet.add( completion2 ); + BOOST_CHECK_EQUAL( 1U , completionSet.size() ); +} + + + +BOOST_AUTO_TEST_CASE(AddCompletionCopy) { + Opm::CompletionSet completionSet; + + Opm::Completion completion1( 10,10,10, 1, 0.0, Opm::WellCompletion::OPEN , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); + Opm::Completion completion2( 10,10,11, 1, 0.0, Opm::WellCompletion::SHUT , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); + Opm::Completion completion3( 10,10,12, 1, 0.0, Opm::WellCompletion::SHUT , Opm::Value("ConnectionTransmissibilityFactor",99.88), Opm::Value("D",22.33), Opm::Value("SKIN",33.22), 0); + + completionSet.add( completion1 ); + completionSet.add( completion2 ); + completionSet.add( completion3 ); + BOOST_CHECK_EQUAL( 3U , completionSet.size() ); + + auto copy = completionSet; + BOOST_CHECK_EQUAL( 3U , copy.size() ); + + BOOST_CHECK_EQUAL( completion1 , copy.get(0)); + BOOST_CHECK_EQUAL( completion2 , copy.get(1)); + BOOST_CHECK_EQUAL( completion3 , copy.get(2)); +} diff --git a/tests/parser/DeckDoubleItemTests.cpp b/tests/parser/DeckDoubleItemTests.cpp deleted file mode 100644 index d31e1350b..000000000 --- a/tests/parser/DeckDoubleItemTests.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - Copyright 2013 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 . - */ - - -#define BOOST_TEST_MODULE DeckItemTests - -#include - -#include -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(InitializeDouble) { - BOOST_REQUIRE_NO_THROW( DeckItem( "HEI", double() ) ); -} - -BOOST_AUTO_TEST_CASE(GetDoubleAtIndex_NoData_ExceptionThrown) { - DeckItem deckDoubleItem( "TEST", double() ); - - BOOST_CHECK_THROW(deckDoubleItem.get< double >(0), std::out_of_range); - deckDoubleItem.push_back(1.89); - BOOST_CHECK_THROW(deckDoubleItem.get< double >(1), std::out_of_range); -} - - -BOOST_AUTO_TEST_CASE(sizeDouble_correct) { - DeckItem deckDoubleItem( "TEST", double() ); - - BOOST_CHECK_EQUAL( 0U , deckDoubleItem.size()); - deckDoubleItem.push_back( 100.0 ); - BOOST_CHECK_EQUAL( 1U , deckDoubleItem.size()); - - deckDoubleItem.push_back( 100.0 ); - deckDoubleItem.push_back( 100.0 ); - BOOST_CHECK_EQUAL( 3U , deckDoubleItem.size()); -} - - - -BOOST_AUTO_TEST_CASE(SetInDeck) { - DeckItem deckDoubleItem( "TEST", double() ); - BOOST_CHECK( deckDoubleItem.size() == 0 ); - - deckDoubleItem.push_backDefault( 1.0 ); - BOOST_CHECK( deckDoubleItem.size() == 1 ); - BOOST_CHECK_EQUAL( true , deckDoubleItem.defaultApplied(0) ); - - deckDoubleItem.push_back( 10.0 ); - BOOST_CHECK( deckDoubleItem.size() == 2 ); - BOOST_CHECK_EQUAL( false , deckDoubleItem.defaultApplied(1) ); - - deckDoubleItem.push_backDefault( 1.0 ); - BOOST_CHECK( deckDoubleItem.size() == 3 ); - BOOST_CHECK_EQUAL( true , deckDoubleItem.defaultApplied(2) ); -} - -BOOST_AUTO_TEST_CASE(DummyDefaults) { - DeckItem deckDoubleItem( "TEST", double() ); - BOOST_CHECK_EQUAL(deckDoubleItem.size(), 0); - - deckDoubleItem.push_backDummyDefault(); - BOOST_CHECK_EQUAL(deckDoubleItem.size(), 0); - BOOST_CHECK_EQUAL(true, deckDoubleItem.defaultApplied(0)); - BOOST_CHECK_THROW(deckDoubleItem.get< double >(0), std::out_of_range); -} - -BOOST_AUTO_TEST_CASE(PushBackMultiple) { - DeckItem item( "HEI", double() ); - item.push_back(10.22 , 100 ); - BOOST_CHECK_EQUAL( 100U , item.size() ); - for (size_t i=0; i < 100; i++) - BOOST_CHECK_EQUAL(10.22 , item.get< double >(i)); -} - -BOOST_AUTO_TEST_CASE(PushBackDimension) { - DeckItem item( "HEI", double() ); - Dimension activeDimension{ "Length" , 100 }; - Dimension defaultDimension{ "Length" , 10 }; - - item.push_back(1.234); - item.push_backDimension( activeDimension , defaultDimension); - - item.push_backDefault(5.678); - item.push_backDimension( activeDimension , defaultDimension); -} - -BOOST_AUTO_TEST_CASE(PushBackDimensionInvalidType) { - DeckItem item( "HEI", int() ); - Dimension dim{ "Length" , 100 }; - BOOST_CHECK_THROW( item.push_backDimension( dim , dim ) , std::logic_error ); -} - -BOOST_AUTO_TEST_CASE(GetSIWithoutDimensionThrows) { - DeckItem item( "HEI", double() ); - item.push_back(10.22 , 100 ); - - BOOST_CHECK_THROW( item.getSIDouble(0) , std::invalid_argument ); - BOOST_CHECK_THROW( item.getSIDoubleData() , std::invalid_argument ); -} - -BOOST_AUTO_TEST_CASE(GetSISingleDimensionCorrect) { - DeckItem item( "HEI", double() ); - Dimension dim{ "Length" , 100 }; - - item.push_back(1.0 , 100 ); - item.push_backDimension( dim , dim ); - - BOOST_CHECK_EQUAL( 1.0 , item.get< double >(0) ); - BOOST_CHECK_EQUAL( 100 , item.getSIDouble(0) ); -} - -BOOST_AUTO_TEST_CASE(GetSISingleDefault) { - DeckItem item( "HEI", double() ); - Dimension dim{ "Length" , 1 }; - Dimension defaultDim{ "Length" , 100 }; - - item.push_backDefault( 1.0 ); - item.push_backDimension( dim , defaultDim ); - - BOOST_CHECK_EQUAL( 1 , item.get< double >(0) ); - BOOST_CHECK_EQUAL( 100 , item.getSIDouble(0) ); -} - -BOOST_AUTO_TEST_CASE(GetSIMultipleDim) { - DeckItem item( "HEI", double() ); - Dimension dim1{ "Length" , 2 }; - Dimension dim2{ "Length" , 4 }; - Dimension dim3{ "Length" , 8 }; - Dimension dim4{ "Length" ,16 }; - Dimension defaultDim{ "Length" , 100 }; - - item.push_back( 1.0, 16 ); - item.push_backDimension( dim1 , defaultDim ); - item.push_backDimension( dim2 , defaultDim ); - item.push_backDimension( dim3 , defaultDim ); - item.push_backDimension( dim4 , defaultDim ); - - for (size_t i=0; i < 16; i+= 4) { - BOOST_CHECK_EQUAL( 2 , item.getSIDouble(i) ); - BOOST_CHECK_EQUAL( 4 , item.getSIDouble(i+ 1) ); - BOOST_CHECK_EQUAL( 8 , item.getSIDouble(i+2) ); - BOOST_CHECK_EQUAL(16 , item.getSIDouble(i+3) ); - } -} - diff --git a/tests/parser/DeckIntItemTests.cpp b/tests/parser/DeckIntItemTests.cpp deleted file mode 100644 index cf686505d..000000000 --- a/tests/parser/DeckIntItemTests.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE DeckItemTests - -#include - -#include -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(Initialize) { - BOOST_REQUIRE_NO_THROW( DeckItem m( "TEST", int() ) ); -} - - -BOOST_AUTO_TEST_CASE(HasValue) { - DeckItem deckIntItem( "TEST", int() ); - BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(0) ); - deckIntItem.push_back(1); - BOOST_CHECK_EQUAL( true , deckIntItem.hasValue(0) ); - BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(1) ); -} - -BOOST_AUTO_TEST_CASE(DummyDefaults) { - DeckItem deckIntItem( "TEST", int() ); - BOOST_CHECK_EQUAL(deckIntItem.size(), 0); - - deckIntItem.push_backDummyDefault(); - BOOST_CHECK_EQUAL(deckIntItem.size(), 0); - BOOST_CHECK_EQUAL(true, deckIntItem.defaultApplied(0)); - BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(0)); - BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(1)); - BOOST_CHECK_THROW(deckIntItem.get< int >(0), std::out_of_range); -} - -BOOST_AUTO_TEST_CASE(GetIntAtIndex_NoData_ExceptionThrown) { - DeckItem deckIntItem( "TEST", int() ); - deckIntItem.push_back(100); - BOOST_CHECK(deckIntItem.get< int >(0) == 100); - BOOST_CHECK_THROW(deckIntItem.get< int >(1), std::out_of_range); -} - -BOOST_AUTO_TEST_CASE(InitializeDefaultApplied) { - DeckItem deckIntItem( "TEST", int() ); - BOOST_CHECK( deckIntItem.size() == 0 ); -} - -BOOST_AUTO_TEST_CASE(size_correct) { - DeckItem deckIntItem( "TEST", int() ); - - BOOST_CHECK_EQUAL( 0U , deckIntItem.size()); - deckIntItem.push_back( 100 ); - BOOST_CHECK_EQUAL( 1U , deckIntItem.size()); - - deckIntItem.push_back( 100 ); - deckIntItem.push_back( 100 ); - BOOST_CHECK_EQUAL( 3U , deckIntItem.size()); -} - -BOOST_AUTO_TEST_CASE(DefaultNotApplied) { - DeckItem deckIntItem( "TEST", int() ); - BOOST_CHECK( deckIntItem.size() == 0 ); - - deckIntItem.push_back( 100 ); - BOOST_CHECK( deckIntItem.size() == 1 ); - BOOST_CHECK( deckIntItem.get< int >(0) == 100 ); - BOOST_CHECK( !deckIntItem.defaultApplied(0) ); - - BOOST_CHECK_THROW( deckIntItem.defaultApplied(1), std::out_of_range ); - BOOST_CHECK_THROW( deckIntItem.get< int >(1), std::out_of_range ); -} - -BOOST_AUTO_TEST_CASE(UseDefault) { - DeckItem deckIntItem( "TEST", int() ); - - deckIntItem.push_backDefault( 100 ); - - BOOST_CHECK( deckIntItem.defaultApplied(0) ); - BOOST_CHECK( deckIntItem.get< int >(0) == 100 ); - - BOOST_CHECK_THROW( deckIntItem.defaultApplied(1), std::out_of_range ); - BOOST_CHECK_THROW( deckIntItem.get< int >(1), std::out_of_range ); -} - -BOOST_AUTO_TEST_CASE(DefaultApplied) { - DeckItem deckIntItem( "TEST", int() ); - BOOST_CHECK( deckIntItem.size() == 0 ); - - deckIntItem.push_backDefault( 100 ); - BOOST_CHECK( deckIntItem.size() == 1 ); - BOOST_CHECK( deckIntItem.get< int >(0) == 100 ); - BOOST_CHECK( deckIntItem.defaultApplied(0) ); - deckIntItem.push_back( 10 ); - BOOST_CHECK_EQUAL( false, deckIntItem.defaultApplied(1) ); - deckIntItem.push_backDefault( 1 ); - BOOST_CHECK_EQUAL( true , deckIntItem.defaultApplied(2) ); - BOOST_CHECK_EQUAL( 3 , deckIntItem.size() ); -} - - -BOOST_AUTO_TEST_CASE(PushBackMultiple) { - DeckItem item( "HEI", int() ); - item.push_back(10 , 100U ); - BOOST_CHECK_EQUAL( 100U , item.size() ); - for (size_t i=0; i < 100; i++) - BOOST_CHECK_EQUAL(10 , item.get< int >(i)); -} diff --git a/tests/parser/DeckKeywordTests.cpp b/tests/parser/DeckKeywordTests.cpp deleted file mode 100644 index 9549d71e9..000000000 --- a/tests/parser/DeckKeywordTests.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - Copyright 2013 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 - -#define BOOST_TEST_MODULE DeckKeywordTests - -#include - - -#include -#include -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(Initialize) { - DeckKeyword deckKeyword1("KW"); -} - -BOOST_AUTO_TEST_CASE(DataKeyword) { - DeckKeyword kw("KW"); - BOOST_CHECK_EQUAL( false , kw.isDataKeyword()); - kw.setDataKeyword( ); - BOOST_CHECK_EQUAL( true , kw.isDataKeyword()); - kw.setDataKeyword( false ); - BOOST_CHECK_EQUAL( false , kw.isDataKeyword()); - kw.setDataKeyword( true ); - BOOST_CHECK_EQUAL( true , kw.isDataKeyword()); -} - - - -BOOST_AUTO_TEST_CASE(name_nameSetInConstructor_nameReturned) { - DeckKeyword deckKeyword( "KW" ); - BOOST_CHECK_EQUAL("KW", deckKeyword.name()); -} - -BOOST_AUTO_TEST_CASE(size_noRecords_returnszero) { - DeckKeyword deckKeyword( "KW" ); - BOOST_CHECK_EQUAL(0U, deckKeyword.size()); -} - - -BOOST_AUTO_TEST_CASE(addRecord_onerecord_recordadded) { - DeckKeyword deckKeyword( "KW" ); - deckKeyword.addRecord( DeckRecord() ); - BOOST_CHECK_EQUAL(1U, deckKeyword.size()); - for (auto iter = deckKeyword.begin(); iter != deckKeyword.end(); ++iter) { - // - } - -} - -BOOST_AUTO_TEST_CASE(getRecord_outofrange_exceptionthrown) { - DeckKeyword deckKeyword( "KW" ); - deckKeyword.addRecord(DeckRecord()); - BOOST_CHECK_THROW(deckKeyword.getRecord(1), std::out_of_range); -} - -BOOST_AUTO_TEST_CASE(setUnknown_wasknown_nowunknown) { - DeckKeyword deckKeyword( "KW", false ); - BOOST_CHECK(!deckKeyword.isKnown()); -} - diff --git a/tests/parser/DeckRecordTests.cpp b/tests/parser/DeckRecordTests.cpp deleted file mode 100644 index 5716e96d4..000000000 --- a/tests/parser/DeckRecordTests.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - Copyright 2013 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 . - */ - - -#define BOOST_TEST_MODULE DeckRecordTests - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(Initialize) { - BOOST_CHECK_NO_THROW(DeckRecord deckRecord); -} - -BOOST_AUTO_TEST_CASE(size_defaultConstructor_sizezero) { - DeckRecord deckRecord; - BOOST_CHECK_EQUAL(0U, deckRecord.size()); -} - -BOOST_AUTO_TEST_CASE(addItem_singleItem_sizeone) { - DeckRecord deckRecord; - deckRecord.addItem( DeckItem { "TEST", int() } ); - BOOST_CHECK_EQUAL(1U, deckRecord.size()); -} - -BOOST_AUTO_TEST_CASE(addItem_multipleItems_sizecorrect) { - - DeckRecord deckRecord; - deckRecord.addItem( DeckItem { "TEST", int() } ); - deckRecord.addItem( DeckItem { "TEST2", int() } ); - deckRecord.addItem( DeckItem { "TEST3", int() } ); - - BOOST_CHECK_EQUAL(3U, deckRecord.size()); -} - -BOOST_AUTO_TEST_CASE(addItem_differentItemsSameName_throws) { - DeckRecord deckRecord; - deckRecord.addItem( DeckItem { "TEST", int() } ); - BOOST_CHECK_THROW( deckRecord.addItem( DeckItem { "TEST", int() } ), std::invalid_argument ); - std::vector< DeckItem > items = { DeckItem { "TEST", int() }, DeckItem { "TEST" , int() } }; - BOOST_CHECK_THROW( DeckRecord( std::move( items ) ), std::invalid_argument ); -} - -BOOST_AUTO_TEST_CASE(get_byIndex_returnsItem) { - DeckRecord deckRecord; - deckRecord.addItem( DeckItem { "TEST", int() } ); - BOOST_CHECK_NO_THROW(deckRecord.getItem(0U)); -} - -BOOST_AUTO_TEST_CASE(get_indexoutofbounds_throws) { - DeckRecord deckRecord; - deckRecord.addItem( DeckItem { "TEST", int() } ); - BOOST_CHECK_THROW(deckRecord.getItem(1), std::out_of_range); -} - -BOOST_AUTO_TEST_CASE(get_byName_returnsItem) { - DeckRecord deckRecord; - deckRecord.addItem( DeckItem { "TEST", int() } ); - deckRecord.getItem("TEST"); -} - -BOOST_AUTO_TEST_CASE(get_byNameNonExisting_throws) { - DeckRecord deckRecord; - deckRecord.addItem( DeckItem { "TEST", int() } ); - BOOST_CHECK_THROW(deckRecord.getItem("INVALID"), std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(StringsWithSpaceOK) { - ParserItem itemString("STRINGITEM1", "" ); - ParserRecord record1; - RawRecord rawRecord( " ' VALUE ' " ); - ParseContext parseContext; - MessageContainer msgContainer; - record1.addItem( itemString ); - - - const auto deckRecord = record1.parse( parseContext , msgContainer, rawRecord ); - BOOST_CHECK_EQUAL(" VALUE " , deckRecord.getItem(0).get< std::string >(0)); -} diff --git a/tests/parser/DeckStringItemTests.cpp b/tests/parser/DeckStringItemTests.cpp deleted file mode 100644 index 383ce0fae..000000000 --- a/tests/parser/DeckStringItemTests.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - Copyright 2013 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 - -#define BOOST_TEST_MODULE DeckStringItemTests - -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(InitializeString) { - DeckItem stringItem("TEST", std::string() ); - BOOST_CHECK_EQUAL("TEST", stringItem.name()); -} - -BOOST_AUTO_TEST_CASE(DummyDefaults) { - DeckItem deckStringItem("TEST", std::string() ); - BOOST_CHECK_EQUAL(deckStringItem.size(), 0); - - deckStringItem.push_backDummyDefault(); - BOOST_CHECK_EQUAL(deckStringItem.size(), 0); - BOOST_CHECK_EQUAL(true, deckStringItem.defaultApplied(0)); - BOOST_CHECK_THROW(deckStringItem.get< std::string >(0), std::out_of_range); -} - -BOOST_AUTO_TEST_CASE(GetStringAtIndex_NoData_ExceptionThrown) { - DeckItem deckStringItem( "TEST", std::string() ); - BOOST_CHECK_THROW(deckStringItem.get< std::string >(0), std::out_of_range); - deckStringItem.push_back("SA"); - BOOST_CHECK_THROW(deckStringItem.get< std::string >(1), std::out_of_range); -} - -BOOST_AUTO_TEST_CASE(size_variouspushes_sizecorrect) { - DeckItem deckStringItem( "TEST", std::string() ); - - BOOST_CHECK_EQUAL(0U, deckStringItem.size()); - deckStringItem.push_back("WELL-3"); - BOOST_CHECK_EQUAL(1U, deckStringItem.size()); - - deckStringItem.push_back("WELL-4"); - deckStringItem.push_back("WELL-5"); - BOOST_CHECK_EQUAL(3U, deckStringItem.size()); -} - -BOOST_AUTO_TEST_CASE(DefaultNotApplied) { - DeckItem deckStringItem( "TEST", std::string() ); - BOOST_CHECK( deckStringItem.size() == 0 ); - - deckStringItem.push_back( "FOO") ; - BOOST_CHECK( deckStringItem.size() == 1 ); - BOOST_CHECK( deckStringItem.get< std::string >(0) == "FOO" ); - BOOST_CHECK( !deckStringItem.defaultApplied(0) ); -} - -BOOST_AUTO_TEST_CASE(DefaultApplied) { - DeckItem deckStringItem( "TEST", std::string() ); - BOOST_CHECK( deckStringItem.size() == 0 ); - - deckStringItem.push_backDefault( "FOO" ); - BOOST_CHECK( deckStringItem.size() == 1 ); - BOOST_CHECK( deckStringItem.get< std::string >(0) == "FOO" ); - BOOST_CHECK( deckStringItem.defaultApplied(0) ); -} - - -BOOST_AUTO_TEST_CASE(PushBackMultiple) { - DeckItem stringItem( "TEST", std::string() ); - stringItem.push_back("Heisann ", 100U ); - BOOST_CHECK_EQUAL( 100U , stringItem.size() ); - for (size_t i=0; i < 100; i++) - BOOST_CHECK_EQUAL("Heisann " , stringItem.get< std::string >(i)); -} diff --git a/tests/parser/DeckTests.cpp b/tests/parser/DeckTests.cpp index 9ae356a5d..010efafab 100644 --- a/tests/parser/DeckTests.cpp +++ b/tests/parser/DeckTests.cpp @@ -26,13 +26,13 @@ #include #include +#include +#include +#include +#include using namespace Opm; -BOOST_AUTO_TEST_CASE(Initialize) { - BOOST_REQUIRE_NO_THROW(Deck deck); -} - BOOST_AUTO_TEST_CASE(Initializer_lists) { DeckKeyword foo( "foo" ); DeckKeyword bar( "bar" ); @@ -169,3 +169,393 @@ BOOST_AUTO_TEST_CASE(set_and_get_data_file) { BOOST_CHECK_EQUAL(file, deck.getDataFile()); } +BOOST_AUTO_TEST_CASE(DummyDefaultsString) { + DeckItem deckStringItem("TEST", std::string() ); + BOOST_CHECK_EQUAL(deckStringItem.size(), 0); + + deckStringItem.push_backDummyDefault(); + BOOST_CHECK_EQUAL(deckStringItem.size(), 0); + BOOST_CHECK_EQUAL(true, deckStringItem.defaultApplied(0)); + BOOST_CHECK_THROW(deckStringItem.get< std::string >(0), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(GetStringAtIndex_NoData_ExceptionThrown) { + DeckItem deckStringItem( "TEST", std::string() ); + BOOST_CHECK_THROW(deckStringItem.get< std::string >(0), std::out_of_range); + deckStringItem.push_back("SA"); + BOOST_CHECK_THROW(deckStringItem.get< std::string >(1), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(size_variouspushes_sizecorrect) { + DeckItem deckStringItem( "TEST", std::string() ); + + BOOST_CHECK_EQUAL(0U, deckStringItem.size()); + deckStringItem.push_back("WELL-3"); + BOOST_CHECK_EQUAL(1U, deckStringItem.size()); + + deckStringItem.push_back("WELL-4"); + deckStringItem.push_back("WELL-5"); + BOOST_CHECK_EQUAL(3U, deckStringItem.size()); +} + +BOOST_AUTO_TEST_CASE(DefaultNotAppliedString) { + DeckItem deckStringItem( "TEST", std::string() ); + BOOST_CHECK( deckStringItem.size() == 0 ); + + deckStringItem.push_back( "FOO") ; + BOOST_CHECK( deckStringItem.size() == 1 ); + BOOST_CHECK( deckStringItem.get< std::string >(0) == "FOO" ); + BOOST_CHECK( !deckStringItem.defaultApplied(0) ); +} + +BOOST_AUTO_TEST_CASE(DefaultAppliedString) { + DeckItem deckStringItem( "TEST", std::string() ); + BOOST_CHECK( deckStringItem.size() == 0 ); + + deckStringItem.push_backDefault( "FOO" ); + BOOST_CHECK( deckStringItem.size() == 1 ); + BOOST_CHECK( deckStringItem.get< std::string >(0) == "FOO" ); + BOOST_CHECK( deckStringItem.defaultApplied(0) ); +} + + +BOOST_AUTO_TEST_CASE(PushBackMultipleString) { + DeckItem stringItem( "TEST", std::string() ); + stringItem.push_back("Heisann ", 100U ); + BOOST_CHECK_EQUAL( 100U , stringItem.size() ); + for (size_t i=0; i < 100; i++) + BOOST_CHECK_EQUAL("Heisann " , stringItem.get< std::string >(i)); +} + +BOOST_AUTO_TEST_CASE(GetDoubleAtIndex_NoData_ExceptionThrown) { + DeckItem deckDoubleItem( "TEST", double() ); + + BOOST_CHECK_THROW(deckDoubleItem.get< double >(0), std::out_of_range); + deckDoubleItem.push_back(1.89); + BOOST_CHECK_THROW(deckDoubleItem.get< double >(1), std::out_of_range); +} + + +BOOST_AUTO_TEST_CASE(sizeDouble_correct) { + DeckItem deckDoubleItem( "TEST", double() ); + + BOOST_CHECK_EQUAL( 0U , deckDoubleItem.size()); + deckDoubleItem.push_back( 100.0 ); + BOOST_CHECK_EQUAL( 1U , deckDoubleItem.size()); + + deckDoubleItem.push_back( 100.0 ); + deckDoubleItem.push_back( 100.0 ); + BOOST_CHECK_EQUAL( 3U , deckDoubleItem.size()); +} + + + +BOOST_AUTO_TEST_CASE(SetInDeck) { + DeckItem deckDoubleItem( "TEST", double() ); + BOOST_CHECK( deckDoubleItem.size() == 0 ); + + deckDoubleItem.push_backDefault( 1.0 ); + BOOST_CHECK( deckDoubleItem.size() == 1 ); + BOOST_CHECK_EQUAL( true , deckDoubleItem.defaultApplied(0) ); + + deckDoubleItem.push_back( 10.0 ); + BOOST_CHECK( deckDoubleItem.size() == 2 ); + BOOST_CHECK_EQUAL( false , deckDoubleItem.defaultApplied(1) ); + + deckDoubleItem.push_backDefault( 1.0 ); + BOOST_CHECK( deckDoubleItem.size() == 3 ); + BOOST_CHECK_EQUAL( true , deckDoubleItem.defaultApplied(2) ); +} + +BOOST_AUTO_TEST_CASE(DummyDefaultsDouble) { + DeckItem deckDoubleItem( "TEST", double() ); + BOOST_CHECK_EQUAL(deckDoubleItem.size(), 0); + + deckDoubleItem.push_backDummyDefault(); + BOOST_CHECK_EQUAL(deckDoubleItem.size(), 0); + BOOST_CHECK_EQUAL(true, deckDoubleItem.defaultApplied(0)); + BOOST_CHECK_THROW(deckDoubleItem.get< double >(0), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(PushBackMultipleDouble) { + DeckItem item( "HEI", double() ); + item.push_back(10.22 , 100 ); + BOOST_CHECK_EQUAL( 100U , item.size() ); + for (size_t i=0; i < 100; i++) + BOOST_CHECK_EQUAL(10.22 , item.get< double >(i)); +} + +BOOST_AUTO_TEST_CASE(PushBackDimension) { + DeckItem item( "HEI", double() ); + Dimension activeDimension{ "Length" , 100 }; + Dimension defaultDimension{ "Length" , 10 }; + + item.push_back(1.234); + item.push_backDimension( activeDimension , defaultDimension); + + item.push_backDefault(5.678); + item.push_backDimension( activeDimension , defaultDimension); +} + +BOOST_AUTO_TEST_CASE(PushBackDimensionInvalidType) { + DeckItem item( "HEI", int() ); + Dimension dim{ "Length" , 100 }; + BOOST_CHECK_THROW( item.push_backDimension( dim , dim ) , std::logic_error ); +} + +BOOST_AUTO_TEST_CASE(GetSIWithoutDimensionThrows) { + DeckItem item( "HEI", double() ); + item.push_back(10.22 , 100 ); + + BOOST_CHECK_THROW( item.getSIDouble(0) , std::invalid_argument ); + BOOST_CHECK_THROW( item.getSIDoubleData() , std::invalid_argument ); +} + +BOOST_AUTO_TEST_CASE(GetSISingleDimensionCorrect) { + DeckItem item( "HEI", double() ); + Dimension dim{ "Length" , 100 }; + + item.push_back(1.0 , 100 ); + item.push_backDimension( dim , dim ); + + BOOST_CHECK_EQUAL( 1.0 , item.get< double >(0) ); + BOOST_CHECK_EQUAL( 100 , item.getSIDouble(0) ); +} + +BOOST_AUTO_TEST_CASE(GetSISingleDefault) { + DeckItem item( "HEI", double() ); + Dimension dim{ "Length" , 1 }; + Dimension defaultDim{ "Length" , 100 }; + + item.push_backDefault( 1.0 ); + item.push_backDimension( dim , defaultDim ); + + BOOST_CHECK_EQUAL( 1 , item.get< double >(0) ); + BOOST_CHECK_EQUAL( 100 , item.getSIDouble(0) ); +} + +BOOST_AUTO_TEST_CASE(GetSIMultipleDim) { + DeckItem item( "HEI", double() ); + Dimension dim1{ "Length" , 2 }; + Dimension dim2{ "Length" , 4 }; + Dimension dim3{ "Length" , 8 }; + Dimension dim4{ "Length" ,16 }; + Dimension defaultDim{ "Length" , 100 }; + + item.push_back( 1.0, 16 ); + item.push_backDimension( dim1 , defaultDim ); + item.push_backDimension( dim2 , defaultDim ); + item.push_backDimension( dim3 , defaultDim ); + item.push_backDimension( dim4 , defaultDim ); + + for (size_t i=0; i < 16; i+= 4) { + BOOST_CHECK_EQUAL( 2 , item.getSIDouble(i) ); + BOOST_CHECK_EQUAL( 4 , item.getSIDouble(i+ 1) ); + BOOST_CHECK_EQUAL( 8 , item.getSIDouble(i+2) ); + BOOST_CHECK_EQUAL(16 , item.getSIDouble(i+3) ); + } +} + +BOOST_AUTO_TEST_CASE(HasValue) { + DeckItem deckIntItem( "TEST", int() ); + BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(0) ); + deckIntItem.push_back(1); + BOOST_CHECK_EQUAL( true , deckIntItem.hasValue(0) ); + BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(1) ); +} + +BOOST_AUTO_TEST_CASE(DummyDefaultsInt) { + DeckItem deckIntItem( "TEST", int() ); + BOOST_CHECK_EQUAL(deckIntItem.size(), 0); + + deckIntItem.push_backDummyDefault(); + BOOST_CHECK_EQUAL(deckIntItem.size(), 0); + BOOST_CHECK_EQUAL(true, deckIntItem.defaultApplied(0)); + BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(0)); + BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(1)); + BOOST_CHECK_THROW(deckIntItem.get< int >(0), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(GetIntAtIndex_NoData_ExceptionThrown) { + DeckItem deckIntItem( "TEST", int() ); + deckIntItem.push_back(100); + BOOST_CHECK(deckIntItem.get< int >(0) == 100); + BOOST_CHECK_THROW(deckIntItem.get< int >(1), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(InitializeDefaultApplied) { + DeckItem deckIntItem( "TEST", int() ); + BOOST_CHECK( deckIntItem.size() == 0 ); +} + +BOOST_AUTO_TEST_CASE(size_correct) { + DeckItem deckIntItem( "TEST", int() ); + + BOOST_CHECK_EQUAL( 0U , deckIntItem.size()); + deckIntItem.push_back( 100 ); + BOOST_CHECK_EQUAL( 1U , deckIntItem.size()); + + deckIntItem.push_back( 100 ); + deckIntItem.push_back( 100 ); + BOOST_CHECK_EQUAL( 3U , deckIntItem.size()); +} + +BOOST_AUTO_TEST_CASE(DefaultNotAppliedInt) { + DeckItem deckIntItem( "TEST", int() ); + BOOST_CHECK( deckIntItem.size() == 0 ); + + deckIntItem.push_back( 100 ); + BOOST_CHECK( deckIntItem.size() == 1 ); + BOOST_CHECK( deckIntItem.get< int >(0) == 100 ); + BOOST_CHECK( !deckIntItem.defaultApplied(0) ); + + BOOST_CHECK_THROW( deckIntItem.defaultApplied(1), std::out_of_range ); + BOOST_CHECK_THROW( deckIntItem.get< int >(1), std::out_of_range ); +} + +BOOST_AUTO_TEST_CASE(UseDefault) { + DeckItem deckIntItem( "TEST", int() ); + + deckIntItem.push_backDefault( 100 ); + + BOOST_CHECK( deckIntItem.defaultApplied(0) ); + BOOST_CHECK( deckIntItem.get< int >(0) == 100 ); + + BOOST_CHECK_THROW( deckIntItem.defaultApplied(1), std::out_of_range ); + BOOST_CHECK_THROW( deckIntItem.get< int >(1), std::out_of_range ); +} + +BOOST_AUTO_TEST_CASE(DefaultAppliedInt) { + DeckItem deckIntItem( "TEST", int() ); + BOOST_CHECK( deckIntItem.size() == 0 ); + + deckIntItem.push_backDefault( 100 ); + BOOST_CHECK( deckIntItem.size() == 1 ); + BOOST_CHECK( deckIntItem.get< int >(0) == 100 ); + BOOST_CHECK( deckIntItem.defaultApplied(0) ); + deckIntItem.push_back( 10 ); + BOOST_CHECK_EQUAL( false, deckIntItem.defaultApplied(1) ); + deckIntItem.push_backDefault( 1 ); + BOOST_CHECK_EQUAL( true , deckIntItem.defaultApplied(2) ); + BOOST_CHECK_EQUAL( 3 , deckIntItem.size() ); +} + + +BOOST_AUTO_TEST_CASE(PushBackMultipleInt) { + DeckItem item( "HEI", int() ); + item.push_back(10 , 100U ); + BOOST_CHECK_EQUAL( 100U , item.size() ); + for (size_t i=0; i < 100; i++) + BOOST_CHECK_EQUAL(10 , item.get< int >(i)); +} + +BOOST_AUTO_TEST_CASE(size_defaultConstructor_sizezero) { + DeckRecord deckRecord; + BOOST_CHECK_EQUAL(0U, deckRecord.size()); +} + +BOOST_AUTO_TEST_CASE(addItem_singleItem_sizeone) { + DeckRecord deckRecord; + deckRecord.addItem( DeckItem { "TEST", int() } ); + BOOST_CHECK_EQUAL(1U, deckRecord.size()); +} + +BOOST_AUTO_TEST_CASE(addItem_multipleItems_sizecorrect) { + + DeckRecord deckRecord; + deckRecord.addItem( DeckItem { "TEST", int() } ); + deckRecord.addItem( DeckItem { "TEST2", int() } ); + deckRecord.addItem( DeckItem { "TEST3", int() } ); + + BOOST_CHECK_EQUAL(3U, deckRecord.size()); +} + +BOOST_AUTO_TEST_CASE(addItem_differentItemsSameName_throws) { + DeckRecord deckRecord; + deckRecord.addItem( DeckItem { "TEST", int() } ); + BOOST_CHECK_THROW( deckRecord.addItem( DeckItem { "TEST", int() } ), std::invalid_argument ); + std::vector< DeckItem > items = { DeckItem { "TEST", int() }, DeckItem { "TEST" , int() } }; + BOOST_CHECK_THROW( DeckRecord( std::move( items ) ), std::invalid_argument ); +} + +BOOST_AUTO_TEST_CASE(get_byIndex_returnsItem) { + DeckRecord deckRecord; + deckRecord.addItem( DeckItem { "TEST", int() } ); + BOOST_CHECK_NO_THROW(deckRecord.getItem(0U)); +} + +BOOST_AUTO_TEST_CASE(get_indexoutofbounds_throws) { + DeckRecord deckRecord; + deckRecord.addItem( DeckItem { "TEST", int() } ); + BOOST_CHECK_THROW(deckRecord.getItem(1), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(get_byName_returnsItem) { + DeckRecord deckRecord; + deckRecord.addItem( DeckItem { "TEST", int() } ); + deckRecord.getItem("TEST"); +} + +BOOST_AUTO_TEST_CASE(get_byNameNonExisting_throws) { + DeckRecord deckRecord; + deckRecord.addItem( DeckItem { "TEST", int() } ); + BOOST_CHECK_THROW(deckRecord.getItem("INVALID"), std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(StringsWithSpaceOK) { + ParserItem itemString("STRINGITEM1", "" ); + ParserRecord record1; + RawRecord rawRecord( " ' VALUE ' " ); + ParseContext parseContext; + MessageContainer msgContainer; + record1.addItem( itemString ); + + + const auto deckRecord = record1.parse( parseContext , msgContainer, rawRecord ); + BOOST_CHECK_EQUAL(" VALUE " , deckRecord.getItem(0).get< std::string >(0)); +} + +BOOST_AUTO_TEST_CASE(DataKeyword) { + DeckKeyword kw("KW"); + BOOST_CHECK_EQUAL( false , kw.isDataKeyword()); + kw.setDataKeyword( ); + BOOST_CHECK_EQUAL( true , kw.isDataKeyword()); + kw.setDataKeyword( false ); + BOOST_CHECK_EQUAL( false , kw.isDataKeyword()); + kw.setDataKeyword( true ); + BOOST_CHECK_EQUAL( true , kw.isDataKeyword()); +} + + + +BOOST_AUTO_TEST_CASE(name_nameSetInConstructor_nameReturned) { + DeckKeyword deckKeyword( "KW" ); + BOOST_CHECK_EQUAL("KW", deckKeyword.name()); +} + +BOOST_AUTO_TEST_CASE(size_noRecords_returnszero) { + DeckKeyword deckKeyword( "KW" ); + BOOST_CHECK_EQUAL(0U, deckKeyword.size()); +} + + +BOOST_AUTO_TEST_CASE(addRecord_onerecord_recordadded) { + DeckKeyword deckKeyword( "KW" ); + deckKeyword.addRecord( DeckRecord() ); + BOOST_CHECK_EQUAL(1U, deckKeyword.size()); + for (auto iter = deckKeyword.begin(); iter != deckKeyword.end(); ++iter) { + // + } + +} + +BOOST_AUTO_TEST_CASE(getRecord_outofrange_exceptionthrown) { + DeckKeyword deckKeyword( "KW" ); + deckKeyword.addRecord(DeckRecord()); + BOOST_CHECK_THROW(deckKeyword.getRecord(1), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(setUnknown_wasknown_nowunknown) { + DeckKeyword deckKeyword( "KW", false ); + BOOST_CHECK(!deckKeyword.isKnown()); +} diff --git a/tests/parser/GridPropertiesTests.cpp b/tests/parser/GridPropertiesTests.cpp deleted file mode 100644 index b3724378e..000000000 --- a/tests/parser/GridPropertiesTests.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - Copyright 2014 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 -#include - -#define BOOST_TEST_MODULE EclipseGridTests - -#include -#include -#include - -#include - -#include -#include -#include - -#include - - -BOOST_AUTO_TEST_CASE(Empty) { - typedef Opm::GridProperties::SupportedKeywordInfo SupportedKeywordInfo; - std::vector supportedKeywords = { - SupportedKeywordInfo("SATNUM" , 0, "1"), - SupportedKeywordInfo("FIPNUM" , 2, "1") - }; - - const Opm::EclipseGrid grid(10, 7, 9); - Opm::GridProperties gridProperties(grid, std::move(supportedKeywords)); - - BOOST_CHECK( gridProperties.supportsKeyword("SATNUM") ); - BOOST_CHECK( gridProperties.supportsKeyword("FIPNUM") ); - BOOST_CHECK( !gridProperties.supportsKeyword("FLUXNUM") ); - BOOST_CHECK( !gridProperties.hasKeyword("SATNUM")); - BOOST_CHECK( !gridProperties.hasKeyword("FLUXNUM")); - - BOOST_CHECK_THROW( gridProperties.getDeckKeyword("SATNUM") , std::invalid_argument); - BOOST_CHECK_THROW( gridProperties.getDeckKeyword("NONONO") , std::invalid_argument); -} - - - -BOOST_AUTO_TEST_CASE(addKeyword) { - typedef Opm::GridProperties::SupportedKeywordInfo SupportedKeywordInfo; - std::vector supportedKeywords = { - SupportedKeywordInfo("SATNUM" , 0, "1") - }; - Opm::EclipseGrid grid(10,7,9); - Opm::GridProperties gridProperties(grid, std::move( supportedKeywords )); - - BOOST_CHECK_THROW( gridProperties.addKeyword("NOT-SUPPORTED"), std::invalid_argument); - - BOOST_CHECK( gridProperties.addKeyword("SATNUM")); - BOOST_CHECK( !gridProperties.addKeyword("SATNUM")); - BOOST_CHECK( gridProperties.hasKeyword("SATNUM")); -} - - -BOOST_AUTO_TEST_CASE(hasKeyword_assertKeyword) { - typedef Opm::GridProperties::SupportedKeywordInfo SupportedKeywordInfo; - std::vector supportedKeywords = { - SupportedKeywordInfo("SATNUM" , 0, "1"), - SupportedKeywordInfo("FIPNUM" , 0, "1") - }; - const Opm::EclipseGrid grid(10, 7, 9); - const Opm::GridProperties gridProperties( grid, std::move( supportedKeywords ) ); - - // calling getKeyword() should not change the semantics of hasKeyword()! - BOOST_CHECK(!gridProperties.hasKeyword("SATNUM")); - BOOST_CHECK(!gridProperties.hasKeyword("FIPNUM")); - - gridProperties.assertKeyword("FIPNUM"); - gridProperties.getKeyword("SATNUM"); - BOOST_CHECK(gridProperties.hasKeyword("SATNUM")); - BOOST_CHECK(gridProperties.hasKeyword("FIPNUM")); - - BOOST_CHECK_THROW( gridProperties.getKeyword( "NOT-SUPPORTED" ), std::invalid_argument ); -} - - - diff --git a/tests/parser/GridPropertyTests.cpp b/tests/parser/GridPropertyTests.cpp index 8bc4f8cb2..f4416938c 100644 --- a/tests/parser/GridPropertyTests.cpp +++ b/tests/parser/GridPropertyTests.cpp @@ -496,3 +496,62 @@ BOOST_AUTO_TEST_CASE(CheckLimits) { p1.checkLimits(0,2); BOOST_CHECK_THROW( p1.checkLimits(-2,0) , std::invalid_argument); } + +BOOST_AUTO_TEST_CASE(PropertiesEmpty) { + typedef Opm::GridProperties::SupportedKeywordInfo SupportedKeywordInfo; + std::vector supportedKeywords = { + SupportedKeywordInfo("SATNUM" , 0, "1"), + SupportedKeywordInfo("FIPNUM" , 2, "1") + }; + + const Opm::EclipseGrid grid(10, 7, 9); + Opm::GridProperties gridProperties(grid, std::move(supportedKeywords)); + + BOOST_CHECK( gridProperties.supportsKeyword("SATNUM") ); + BOOST_CHECK( gridProperties.supportsKeyword("FIPNUM") ); + BOOST_CHECK( !gridProperties.supportsKeyword("FLUXNUM") ); + BOOST_CHECK( !gridProperties.hasKeyword("SATNUM")); + BOOST_CHECK( !gridProperties.hasKeyword("FLUXNUM")); + + BOOST_CHECK_THROW( gridProperties.getDeckKeyword("SATNUM") , std::invalid_argument); + BOOST_CHECK_THROW( gridProperties.getDeckKeyword("NONONO") , std::invalid_argument); +} + + + +BOOST_AUTO_TEST_CASE(addKeyword) { + typedef Opm::GridProperties::SupportedKeywordInfo SupportedKeywordInfo; + std::vector supportedKeywords = { + SupportedKeywordInfo("SATNUM" , 0, "1") + }; + Opm::EclipseGrid grid(10,7,9); + Opm::GridProperties gridProperties(grid, std::move( supportedKeywords )); + + BOOST_CHECK_THROW( gridProperties.addKeyword("NOT-SUPPORTED"), std::invalid_argument); + + BOOST_CHECK( gridProperties.addKeyword("SATNUM")); + BOOST_CHECK( !gridProperties.addKeyword("SATNUM")); + BOOST_CHECK( gridProperties.hasKeyword("SATNUM")); +} + + +BOOST_AUTO_TEST_CASE(hasKeyword_assertKeyword) { + typedef Opm::GridProperties::SupportedKeywordInfo SupportedKeywordInfo; + std::vector supportedKeywords = { + SupportedKeywordInfo("SATNUM" , 0, "1"), + SupportedKeywordInfo("FIPNUM" , 0, "1") + }; + const Opm::EclipseGrid grid(10, 7, 9); + const Opm::GridProperties gridProperties( grid, std::move( supportedKeywords ) ); + + // calling getKeyword() should not change the semantics of hasKeyword()! + BOOST_CHECK(!gridProperties.hasKeyword("SATNUM")); + BOOST_CHECK(!gridProperties.hasKeyword("FIPNUM")); + + gridProperties.assertKeyword("FIPNUM"); + gridProperties.getKeyword("SATNUM"); + BOOST_CHECK(gridProperties.hasKeyword("SATNUM")); + BOOST_CHECK(gridProperties.hasKeyword("FIPNUM")); + + BOOST_CHECK_THROW( gridProperties.getKeyword( "NOT-SUPPORTED" ), std::invalid_argument ); +} diff --git a/tests/parser/GroupTests.cpp b/tests/parser/GroupTests.cpp index d5e35c81f..bd73807ff 100644 --- a/tests/parser/GroupTests.cpp +++ b/tests/parser/GroupTests.cpp @@ -292,9 +292,9 @@ BOOST_AUTO_TEST_CASE(createDeckWithGEFAC) { -BOOST_AUTO_TEST_CASE(createDeckWithWGRUPCONandWCONPROD) { - - /* Test deck with well guide rates for group control: +BOOST_AUTO_TEST_CASE(createDeckWithWGRUPCONandWCONPROD) { + + /* Test deck with well guide rates for group control: GRUPCON (well guide rates for group control) WCONPROD (conrol data for production wells) with GRUP control mode */ @@ -314,7 +314,7 @@ BOOST_AUTO_TEST_CASE(createDeckWithWGRUPCONandWCONPROD) { " 'B-43A' 8 8 2 2 'OPEN' 1* 46.825 0.311 4332.346 1* 1* 'X' 22.123 / \n" "/\n" - + "WGRUPCON\n" " 'B-37T2' YES 30 OIL / \n" " 'B-43A' YES 30 OIL / \n" @@ -325,7 +325,7 @@ BOOST_AUTO_TEST_CASE(createDeckWithWGRUPCONandWCONPROD) { " 'B-43A' 'OPEN' 'GRUP' 1200 2* 3000.000 2* 1* 11 0.000 5* / / \n" "/\n"; - + Opm::ParseContext parseContext; auto deck = parser.parseString(input, parseContext); @@ -342,5 +342,56 @@ BOOST_AUTO_TEST_CASE(createDeckWithWGRUPCONandWCONPROD) { BOOST_CHECK_EQUAL(currentWell->getGuideRatePhase(0), Opm::GuideRate::OIL); BOOST_CHECK_EQUAL(currentWell->getGuideRateScalingFactor(0), 1.0); - + +} + +BOOST_AUTO_TEST_CASE(CreateGroupTree_DefaultConstructor_HasFieldNode) { + GroupTree tree; + BOOST_CHECK(tree.exists("FIELD")); +} + +BOOST_AUTO_TEST_CASE(GetNode_NonExistingNode_ReturnsNull) { + GroupTree tree; + BOOST_CHECK(!tree.exists("Non-existing")); +} + +BOOST_AUTO_TEST_CASE(GetNodeAndParent_AllOK) { + GroupTree tree; + tree.update("GRANDPARENT", "FIELD"); + tree.update("PARENT", "GRANDPARENT"); + tree.update("GRANDCHILD", "PARENT"); + + const auto grandchild = tree.exists("GRANDCHILD"); + BOOST_CHECK(grandchild); + auto parent = tree.parent("GRANDCHILD"); + BOOST_CHECK_EQUAL("PARENT", parent); + BOOST_CHECK( tree.children( "PARENT" ).front() == "GRANDCHILD" ); +} + +BOOST_AUTO_TEST_CASE(UpdateTree_ParentNotSpecified_AddedUnderField) { + GroupTree tree; + tree.update("CHILD_OF_FIELD"); + BOOST_CHECK(tree.exists("CHILD_OF_FIELD")); + BOOST_CHECK_EQUAL( "FIELD", tree.parent( "CHILD_OF_FIELD" ) ); +} + +BOOST_AUTO_TEST_CASE(UpdateTree_ParentIsField_AddedUnderField) { + GroupTree tree; + tree.update("CHILD_OF_FIELD", "FIELD"); + BOOST_CHECK( tree.exists( "CHILD_OF_FIELD" ) ); + BOOST_CHECK_EQUAL( "FIELD", tree.parent( "CHILD_OF_FIELD" ) ); +} + +BOOST_AUTO_TEST_CASE(UpdateTree_ParentNotAdded_ChildAndParentAdded) { + GroupTree tree; + tree.update("CHILD", "NEWPARENT"); + BOOST_CHECK( tree.exists("CHILD") ); + BOOST_CHECK_EQUAL( "NEWPARENT", tree.parent( "CHILD" ) ); + BOOST_CHECK_EQUAL( "CHILD", tree.children( "NEWPARENT" ).front() ); +} + +BOOST_AUTO_TEST_CASE(UpdateTree_AddFieldNode_Throws) { + GroupTree tree; + BOOST_CHECK_THROW(tree.update("FIELD", "NEWPARENT"), std::invalid_argument ); + BOOST_CHECK_THROW(tree.update("FIELD"), std::invalid_argument ); } diff --git a/tests/parser/GroupTreeTests.cpp b/tests/parser/GroupTreeTests.cpp deleted file mode 100644 index f1bf268da..000000000 --- a/tests/parser/GroupTreeTests.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright 2013 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 - -#define BOOST_TEST_MODULE GroupTreeTests - -#include - -#include -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(CreateGroupTree_DefaultConstructor_HasFieldNode) { - GroupTree tree; - BOOST_CHECK(tree.exists("FIELD")); -} - -BOOST_AUTO_TEST_CASE(GetNode_NonExistingNode_ReturnsNull) { - GroupTree tree; - BOOST_CHECK(!tree.exists("Non-existing")); -} - -BOOST_AUTO_TEST_CASE(GetNodeAndParent_AllOK) { - GroupTree tree; - tree.update("GRANDPARENT", "FIELD"); - tree.update("PARENT", "GRANDPARENT"); - tree.update("GRANDCHILD", "PARENT"); - - const auto grandchild = tree.exists("GRANDCHILD"); - BOOST_CHECK(grandchild); - auto parent = tree.parent("GRANDCHILD"); - BOOST_CHECK_EQUAL("PARENT", parent); - BOOST_CHECK( tree.children( "PARENT" ).front() == "GRANDCHILD" ); -} - -BOOST_AUTO_TEST_CASE(UpdateTree_ParentNotSpecified_AddedUnderField) { - GroupTree tree; - tree.update("CHILD_OF_FIELD"); - BOOST_CHECK(tree.exists("CHILD_OF_FIELD")); - BOOST_CHECK_EQUAL( "FIELD", tree.parent( "CHILD_OF_FIELD" ) ); -} - -BOOST_AUTO_TEST_CASE(UpdateTree_ParentIsField_AddedUnderField) { - GroupTree tree; - tree.update("CHILD_OF_FIELD", "FIELD"); - BOOST_CHECK( tree.exists( "CHILD_OF_FIELD" ) ); - BOOST_CHECK_EQUAL( "FIELD", tree.parent( "CHILD_OF_FIELD" ) ); -} - -BOOST_AUTO_TEST_CASE(UpdateTree_ParentNotAdded_ChildAndParentAdded) { - GroupTree tree; - tree.update("CHILD", "NEWPARENT"); - BOOST_CHECK( tree.exists("CHILD") ); - BOOST_CHECK_EQUAL( "NEWPARENT", tree.parent( "CHILD" ) ); - BOOST_CHECK_EQUAL( "CHILD", tree.children( "NEWPARENT" ).front() ); -} - -BOOST_AUTO_TEST_CASE(UpdateTree_AddFieldNode_Throws) { - GroupTree tree; - BOOST_CHECK_THROW(tree.update("FIELD", "NEWPARENT"), std::invalid_argument ); - BOOST_CHECK_THROW(tree.update("FIELD"), std::invalid_argument ); -} diff --git a/tests/parser/ParserEnumTests.cpp b/tests/parser/ParserEnumTests.cpp deleted file mode 100644 index 6d25ec74b..000000000 --- a/tests/parser/ParserEnumTests.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - Copyright 2013 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 . - */ - - -#define BOOST_TEST_MODULE ParserEnumTests -#include - -#include - -using namespace Opm; - -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(TestKeywordSizeEnum2String) { - BOOST_CHECK_EQUAL( "SLASH_TERMINATED" , ParserKeywordSizeEnum2String(SLASH_TERMINATED)); - BOOST_CHECK_EQUAL( "FIXED" , ParserKeywordSizeEnum2String(FIXED)); - BOOST_CHECK_EQUAL( "OTHER_KEYWORD_IN_DECK" , ParserKeywordSizeEnum2String(OTHER_KEYWORD_IN_DECK)); - BOOST_CHECK_EQUAL( "UNKNOWN" , ParserKeywordSizeEnum2String(UNKNOWN)); -} - - -BOOST_AUTO_TEST_CASE(TestKeywordSizeEnumFromString) { - BOOST_CHECK_THROW( ParserKeywordSizeEnumFromString("XXX") , std::invalid_argument ); - BOOST_CHECK_EQUAL( FIXED , ParserKeywordSizeEnumFromString("FIXED")); - BOOST_CHECK_EQUAL( SLASH_TERMINATED , ParserKeywordSizeEnumFromString("SLASH_TERMINATED")); - BOOST_CHECK_EQUAL( "OTHER_KEYWORD_IN_DECK" , ParserKeywordSizeEnum2String(OTHER_KEYWORD_IN_DECK)); - BOOST_CHECK_EQUAL( "UNKNOWN" , ParserKeywordSizeEnum2String(UNKNOWN)); -} - - - -BOOST_AUTO_TEST_CASE(TestKeywordSizeEnumLoop) { - BOOST_CHECK_EQUAL( FIXED , ParserKeywordSizeEnumFromString( ParserKeywordSizeEnum2String( FIXED ) )); - BOOST_CHECK_EQUAL( SLASH_TERMINATED , ParserKeywordSizeEnumFromString( ParserKeywordSizeEnum2String( SLASH_TERMINATED ) )); - BOOST_CHECK_EQUAL( OTHER_KEYWORD_IN_DECK , ParserKeywordSizeEnumFromString( ParserKeywordSizeEnum2String( OTHER_KEYWORD_IN_DECK ) )); - BOOST_CHECK_EQUAL( UNKNOWN , ParserKeywordSizeEnumFromString( ParserKeywordSizeEnum2String( UNKNOWN ) )); - - BOOST_CHECK_EQUAL( "FIXED" , ParserKeywordSizeEnum2String(ParserKeywordSizeEnumFromString( "FIXED" ) )); - BOOST_CHECK_EQUAL( "SLASH_TERMINATED" , ParserKeywordSizeEnum2String(ParserKeywordSizeEnumFromString( "SLASH_TERMINATED" ) )); - BOOST_CHECK_EQUAL( "OTHER_KEYWORD_IN_DECK" , ParserKeywordSizeEnum2String(ParserKeywordSizeEnumFromString( "OTHER_KEYWORD_IN_DECK" ) )); - BOOST_CHECK_EQUAL( "UNKNOWN" , ParserKeywordSizeEnum2String(ParserKeywordSizeEnumFromString( "UNKNOWN" ) )); -} - - -/*****************************************************************/ - - -BOOST_AUTO_TEST_CASE(TestValueTypeEnum2String) { - BOOST_CHECK_EQUAL( "INT" , ParserValueTypeEnum2String(INT)); - BOOST_CHECK_EQUAL( "FLOAT" , ParserValueTypeEnum2String(FLOAT)); - BOOST_CHECK_EQUAL( "STRING" , ParserValueTypeEnum2String(STRING)); -} - - -BOOST_AUTO_TEST_CASE(TestValueTypeEnumFromString) { - BOOST_CHECK_THROW( ParserValueTypeEnumFromString("XXX") , std::invalid_argument ); - BOOST_CHECK_EQUAL( INT , ParserValueTypeEnumFromString("INT")); - BOOST_CHECK_EQUAL( STRING , ParserValueTypeEnumFromString("STRING")); - BOOST_CHECK_EQUAL( FLOAT , ParserValueTypeEnumFromString("FLOAT")); -} - - - -BOOST_AUTO_TEST_CASE(TestValueTypeEnumLoop) { - BOOST_CHECK_EQUAL( INT , ParserValueTypeEnumFromString( ParserValueTypeEnum2String( INT ) )); - BOOST_CHECK_EQUAL( FLOAT , ParserValueTypeEnumFromString( ParserValueTypeEnum2String( FLOAT ) )); - BOOST_CHECK_EQUAL( STRING , ParserValueTypeEnumFromString( ParserValueTypeEnum2String( STRING ) )); - - BOOST_CHECK_EQUAL( "INT" , ParserValueTypeEnum2String(ParserValueTypeEnumFromString( "INT" ) )); - BOOST_CHECK_EQUAL( "FLOAT" , ParserValueTypeEnum2String(ParserValueTypeEnumFromString( "FLOAT" ) )); - BOOST_CHECK_EQUAL( "STRING" , ParserValueTypeEnum2String(ParserValueTypeEnumFromString( "STRING" ) )); -} - - -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(TestKeywordActionEnum2String) { - BOOST_CHECK_EQUAL( "INTERNALIZE" , ParserKeywordActionEnum2String(INTERNALIZE)); - BOOST_CHECK_EQUAL( "IGNORE" , ParserKeywordActionEnum2String(IGNORE)); - BOOST_CHECK_EQUAL( "IGNORE_WARNING" , ParserKeywordActionEnum2String(IGNORE_WARNING)); - BOOST_CHECK_EQUAL( "THROW_EXCEPTION" , ParserKeywordActionEnum2String(THROW_EXCEPTION)); -} - - -BOOST_AUTO_TEST_CASE(TestKeywordActionEnumFromString) { - BOOST_CHECK_THROW( ParserKeywordActionEnumFromString("XXX") , std::invalid_argument ); - BOOST_CHECK_EQUAL( INTERNALIZE , ParserKeywordActionEnumFromString("INTERNALIZE")); - BOOST_CHECK_EQUAL( IGNORE_WARNING , ParserKeywordActionEnumFromString("IGNORE_WARNING")); - BOOST_CHECK_EQUAL( IGNORE , ParserKeywordActionEnumFromString("IGNORE")); - BOOST_CHECK_EQUAL( THROW_EXCEPTION , ParserKeywordActionEnumFromString("THROW_EXCEPTION")); -} - - - -BOOST_AUTO_TEST_CASE(TestKeywordActionEnumLoop) { - BOOST_CHECK_EQUAL( INTERNALIZE , ParserKeywordActionEnumFromString( ParserKeywordActionEnum2String( INTERNALIZE ) )); - BOOST_CHECK_EQUAL( IGNORE , ParserKeywordActionEnumFromString( ParserKeywordActionEnum2String( IGNORE ) )); - BOOST_CHECK_EQUAL( IGNORE_WARNING , ParserKeywordActionEnumFromString( ParserKeywordActionEnum2String( IGNORE_WARNING ) )); - BOOST_CHECK_EQUAL( THROW_EXCEPTION , ParserKeywordActionEnumFromString( ParserKeywordActionEnum2String( THROW_EXCEPTION ) )); - - BOOST_CHECK_EQUAL( "INTERNALIZE" , ParserKeywordActionEnum2String(ParserKeywordActionEnumFromString( "INTERNALIZE" ) )); - BOOST_CHECK_EQUAL( "IGNORE" , ParserKeywordActionEnum2String(ParserKeywordActionEnumFromString( "IGNORE" ) )); - BOOST_CHECK_EQUAL( "IGNORE_WARNING" , ParserKeywordActionEnum2String(ParserKeywordActionEnumFromString( "IGNORE_WARNING" ) )); - BOOST_CHECK_EQUAL( "THROW_EXCEPTION" , ParserKeywordActionEnum2String(ParserKeywordActionEnumFromString( "THROW_EXCEPTION" ) )); -} - - diff --git a/tests/parser/ParserItemTests.cpp b/tests/parser/ParserItemTests.cpp deleted file mode 100644 index a620d874d..000000000 --- a/tests/parser/ParserItemTests.cpp +++ /dev/null @@ -1,611 +0,0 @@ -/* - Copyright 2013 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 . - */ - - -#define BOOST_TEST_MODULE ParserItemTests -#include - -#include - -#include -#include - -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(Initialize) { - auto sizeType = ParserItem::item_size::SINGLE; - BOOST_CHECK_NO_THROW(ParserItem item1("ITEM1", sizeType)); -} - -BOOST_AUTO_TEST_CASE(ScalarCheck) { - ParserItem item1("ITEM1", ParserItem::item_size::SINGLE ); - ParserItem item2("ITEM1", ParserItem::item_size::ALL ); - - BOOST_CHECK( item1.scalar()); - BOOST_CHECK( !item2.scalar()); -} - -BOOST_AUTO_TEST_CASE(Initialize_DefaultSizeType) { - ParserItem item1(std::string("ITEM1")); - BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE, item1.sizeType()); -} - - - -BOOST_AUTO_TEST_CASE(Initialize_Default) { - ParserItem item1(std::string("ITEM1")); - ParserItem item2(std::string("ITEM1"), 88); - BOOST_CHECK(!item1.hasDefault()); - BOOST_CHECK_THROW(item1.getDefault< int >(), std::invalid_argument); - BOOST_CHECK(item2.hasDefault()); - BOOST_CHECK_EQUAL(item2.getDefault< int >(), 88); -} - - -BOOST_AUTO_TEST_CASE(Initialize_Default_Double) { - ParserItem item1(std::string("ITEM1")); - ParserItem item2("ITEM1", 88.91); - BOOST_CHECK(!item1.hasDefault()); - BOOST_CHECK_THROW( item1.getDefault< double >(), std::invalid_argument ); - BOOST_CHECK_EQUAL( 88.91 , item2.getDefault< double >()); -} - -BOOST_AUTO_TEST_CASE(Initialize_Default_String) { - ParserItem item1(std::string("ITEM1")); - BOOST_CHECK(!item1.hasDefault()); - BOOST_CHECK_THROW(item1.getDefault< std::string >(), std::invalid_argument); - - ParserItem item2("ITEM1", "String"); - BOOST_CHECK(item2.hasDefault()); - BOOST_CHECK_EQUAL( "String" , item2.getDefault< std::string >()); -} - -BOOST_AUTO_TEST_CASE(scan_PreMatureTerminator_defaultUsed) { - ParserItem itemInt("ITEM2", 123); - - RawRecord rawRecord1( "" ); - const auto defaulted = itemInt.scan(rawRecord1); - - BOOST_CHECK(defaulted.defaultApplied(0)); - BOOST_CHECK_EQUAL(defaulted.get< int >(0), 123); -} - -BOOST_AUTO_TEST_CASE(InitializeIntItem_setDescription_canReadBack) { - ParserItem itemInt("ITEM1"); - std::string description("This is the description"); - itemInt.setDescription(description); - - BOOST_CHECK_EQUAL( description, itemInt.getDescription() ); -} - - -/******************************************************************/ -/* */ -BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_missingName_throws) { - Json::JsonObject jsonConfig("{\"nameX\": \"ITEM1\" , \"size_type\" : \"ALL\"}"); - BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument ); -} - - -BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_defaultSizeType) { - Json::JsonObject jsonConfig("{\"name\": \"ITEM1\", \"value_type\": \"INT\" }"); - ParserItem item1( jsonConfig ); - BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE , item1.sizeType()); -} - - - -BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject) { - Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\", \"value_type\": \"INT\" }"); - ParserItem item1( jsonConfig ); - BOOST_CHECK_EQUAL( "ITEM1" , item1.name() ); - BOOST_CHECK_EQUAL( ParserItem::item_size::ALL, item1.sizeType() ); - BOOST_CHECK(item1.getDefault< int >() < 0); -} - - -BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withDefault) { - Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"SINGLE\", \"default\" : 100, \"value_type\": \"INT\" }"); - ParserItem item1( jsonConfig ); - BOOST_CHECK_EQUAL( 100 , item1.getDefault< int >() ); -} - - -BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withDefaultInvalid_throws) { - Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"SINGLE\", \"default\" : \"100X\"}"); - BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument ); -} - - -BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withSizeTypeALL_throws) { - Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"INT\", \"size_type\" : \"ALL\", \"default\" : 100}"); - BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument ); -} - - - -BOOST_AUTO_TEST_CASE(InitializeIntItem_WithDescription_DescriptionPropertyShouldBePopulated) { - std::string description("Description goes here"); - Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"INT\", \"description\" : \"Description goes here\"}"); - ParserItem item(jsonConfig); - - BOOST_CHECK_EQUAL( "Description goes here", item.getDescription() ); -} - - -BOOST_AUTO_TEST_CASE(InitializeIntItem_WithoutDescription_DescriptionPropertyShouldBeEmpty) { - Json::JsonObject jsonConfig("{\"name\": \"ITEM1\", \"value_type\": \"INT\" }"); - ParserItem item(jsonConfig); - - BOOST_CHECK_EQUAL( "", item.getDescription() ); -} - - - -/* */ -/******************************************************************/ - -/* EQUAL */ - - -BOOST_AUTO_TEST_CASE(IntItem_Equal_ReturnsTrue) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType); - ParserItem item2("ITEM1", sizeType); - ParserItem item3 = item1; - - BOOST_CHECK_EQUAL( item1, item2 ); - BOOST_CHECK_EQUAL( item1, item3 ); -} - - -BOOST_AUTO_TEST_CASE(IntItem_Different_ReturnsFalse) { - ParserItem item1("ITEM1", ParserItem::item_size::ALL); - ParserItem item2("ITEM2", ParserItem::item_size::ALL); - ParserItem item3("ITEM1"); - ParserItem item4("ITEM1" , 42); - - BOOST_CHECK_NE( item1, item2 ); - BOOST_CHECK_NE( item1, item3 ); - BOOST_CHECK_NE( item2, item3 ); - BOOST_CHECK_NE( item4, item3 ); -} - -BOOST_AUTO_TEST_CASE(DoubleItem_DimEqual_ReturnsTrue) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType, 0.0); - ParserItem item2("ITEM1", sizeType, 0.0); - - item1.push_backDimension("Length*Length"); - item2.push_backDimension("Length*Length"); - - BOOST_CHECK_EQUAL( item1, item2 ); -} - - -BOOST_AUTO_TEST_CASE(DoubleItem_DimDifferent_ReturnsFalse) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType, 0.0); // Dim: [] - ParserItem item2("ITEM1", sizeType, 0.0); // Dim: [Length] - ParserItem item3("ITEM1", sizeType, 0.0); // Dim: [Length ,Length] - ParserItem item4("ITEM1", sizeType, 0.0); // Dim: [t] - - item2.push_backDimension("Length"); - item3.push_backDimension("Length"); - item3.push_backDimension("Length"); - item4.push_backDimension("Time"); - - BOOST_CHECK_NE(item1, item2 ); - BOOST_CHECK_NE(item2, item3 ); - BOOST_CHECK_NE(item2, item1 ); - BOOST_CHECK_NE(item2, item4 ); - BOOST_CHECK_NE(item1, item3 ); - BOOST_CHECK_NE(item3, item1 ); - BOOST_CHECK_NE(item4, item2 ); -} - - -BOOST_AUTO_TEST_CASE(DoubleItem_Different_ReturnsFalse) { - ParserItem item1("ITEM1", ParserItem::item_size::ALL, 0.0); - ParserItem item2("ITEM2", ParserItem::item_size::ALL, 0.0); - ParserItem item3("ITEM1", 0.0 ); - ParserItem item4("ITEM1", 42.89); - - BOOST_CHECK_NE( item1, item2 ); - BOOST_CHECK_NE( item1, item3 ); - BOOST_CHECK_NE( item2, item3 ); - BOOST_CHECK_NE( item4, item3 ); -} - - -BOOST_AUTO_TEST_CASE(StringItem_Equal_ReturnsTrue) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType, ""); - ParserItem item2("ITEM1", sizeType, ""); - ParserItem item3 = item1; - - BOOST_CHECK_EQUAL( item1, item2 ); - BOOST_CHECK_EQUAL( item1, item3 ); -} - - -BOOST_AUTO_TEST_CASE(StringItem_Different_ReturnsFalse) { - ParserItem item1("ITEM1", ParserItem::item_size::ALL, ""); - ParserItem item2("ITEM2", ParserItem::item_size::ALL, ""); - ParserItem item3("ITEM1", "" ); - ParserItem item4("ITEM1", "42.89"); - - BOOST_CHECK_NE( item1, item2 ); - BOOST_CHECK_NE( item1, item3 ); - BOOST_CHECK_NE( item2, item3 ); - BOOST_CHECK_NE( item4, item3 ); -} - - - - -/******************************************************************/ - -BOOST_AUTO_TEST_CASE(Name_ReturnsCorrectName) { - auto sizeType = ParserItem::item_size::ALL; - - ParserItem item1("ITEM1", sizeType); - BOOST_CHECK_EQUAL("ITEM1", item1.name()); - - ParserItem item2("", sizeType); - BOOST_CHECK_EQUAL("", item2.name()); -} - -BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeTypeSingle) { - auto sizeType = ParserItem::item_size::SINGLE; - ParserItem item1("ITEM1", sizeType); - BOOST_CHECK_EQUAL(sizeType, item1.sizeType()); -} - -BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeTypeAll) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType); - BOOST_CHECK_EQUAL(sizeType, item1.sizeType()); -} - -BOOST_AUTO_TEST_CASE(Scan_All_CorrectIntSetInDeckItem) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem itemInt("ITEM", sizeType, 0); - - RawRecord rawRecord( "100 443 10*77 10*1 25" ); - const auto deckIntItem = itemInt.scan(rawRecord); - BOOST_CHECK_EQUAL(23U, deckIntItem.size()); - BOOST_CHECK_EQUAL(77, deckIntItem.get< int >(3)); - BOOST_CHECK_EQUAL(1, deckIntItem.get< int >(21)); - BOOST_CHECK_EQUAL(25, deckIntItem.get< int >(22)); -} - -BOOST_AUTO_TEST_CASE(Scan_All_WithDefaults) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem itemInt("ITEM", sizeType); - itemInt.setType( int() ); - - RawRecord rawRecord( "100 10* 10*1 25" ); - const auto deckIntItem = itemInt.scan(rawRecord); - BOOST_CHECK_EQUAL(22U, deckIntItem.size()); - BOOST_CHECK(!deckIntItem.defaultApplied(0)); - BOOST_CHECK( deckIntItem.defaultApplied(1)); - BOOST_CHECK(!deckIntItem.defaultApplied(11)); - BOOST_CHECK(!deckIntItem.defaultApplied(21)); - BOOST_CHECK_EQUAL(1, deckIntItem.get< int >(20)); - BOOST_CHECK_EQUAL(25, deckIntItem.get< int >(21)); -} - -BOOST_AUTO_TEST_CASE(Scan_SINGLE_CorrectIntSetInDeckItem) { - ParserItem itemInt(std::string("ITEM2"), 0); - - RawRecord rawRecord("100 44.3 'Heisann'" ); - const auto deckIntItem = itemInt.scan(rawRecord); - BOOST_CHECK_EQUAL(100, deckIntItem.get< int >(0)); -} - -BOOST_AUTO_TEST_CASE(Scan_SeveralInts_CorrectIntsSetInDeckItem) { - ParserItem itemInt1(std::string("ITEM1"), 0); - ParserItem itemInt2(std::string("ITEM2"), 0); - ParserItem itemInt3(std::string("ITEM3"), 0); - - RawRecord rawRecord( "100 443 338932 222.33 'Heisann' " ); - const auto deckIntItem1 = itemInt1.scan(rawRecord); - BOOST_CHECK_EQUAL(100, deckIntItem1.get< int >(0)); - - const auto deckIntItem2 = itemInt2.scan(rawRecord); - BOOST_CHECK_EQUAL(443, deckIntItem2.get< int >(0)); - - const auto deckIntItem3 = itemInt3.scan(rawRecord); - BOOST_CHECK_EQUAL(338932, deckIntItem3.get< int >(0)); -} - - - - - -BOOST_AUTO_TEST_CASE(Scan_Multiplier_CorrectIntsSetInDeckItem) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem itemInt("ITEM2", sizeType, 0); - - RawRecord rawRecord( "3*4 " ); - const auto deckIntItem = itemInt.scan(rawRecord); - BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(0)); - BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(1)); - BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(2)); -} - -BOOST_AUTO_TEST_CASE(Scan_StarNoMultiplier_ExceptionThrown) { - auto sizeType = ParserItem::item_size::SINGLE; - ParserItem itemInt("ITEM2", sizeType , 100); - - RawRecord rawRecord( "*45 " ); - BOOST_CHECK_THROW(itemInt.scan(rawRecord), std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(Scan_MultipleItems_CorrectIntsSetInDeckItem) { - ParserItem itemInt1(std::string("ITEM1"), 0); - ParserItem itemInt2(std::string("ITEM2"), 0); - - RawRecord rawRecord( "10 20" ); - const auto deckIntItem1 = itemInt1.scan(rawRecord); - const auto deckIntItem2 = itemInt2.scan(rawRecord); - - BOOST_CHECK_EQUAL(10, deckIntItem1.get< int >(0)); - BOOST_CHECK_EQUAL(20, deckIntItem2.get< int >(0)); -} - -BOOST_AUTO_TEST_CASE(Scan_MultipleDefault_CorrectIntsSetInDeckItem) { - ParserItem itemInt1("ITEM1", 10); - ParserItem itemInt2("ITEM2", 20); - - RawRecord rawRecord( "* * " ); - const auto deckIntItem1 = itemInt1.scan(rawRecord); - const auto deckIntItem2 = itemInt2.scan(rawRecord); - - BOOST_CHECK_EQUAL(10, deckIntItem1.get< int >(0)); - BOOST_CHECK_EQUAL(20, deckIntItem2.get< int >(0)); -} - -BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplier_CorrectIntsSetInDeckItem) { - ParserItem itemInt1("ITEM1", 10); - ParserItem itemInt2("ITEM2", 20); - - RawRecord rawRecord( "2*30" ); - const auto deckIntItem1 = itemInt1.scan(rawRecord); - const auto deckIntItem2 = itemInt2.scan(rawRecord); - - BOOST_CHECK_EQUAL(30, deckIntItem1.get< int >(0)); - BOOST_CHECK_EQUAL(30, deckIntItem2.get< int >(0)); -} - -BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplier_Throw) { - ParserItem itemInt1("ITEM1" , 10); - - RawRecord rawRecord( "2.10*30" ); - BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplierChar_Throw) { - ParserItem itemInt1("ITEM1", 10); - - RawRecord rawRecord( "210X30" ); - BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplierDefault_CorrectIntsSetInDeckItem) { - ParserItem itemInt1("ITEM1", 10); - ParserItem itemInt2("ITEM2", 20); - - RawRecord rawRecord( "2*" ); - const auto deckIntItem1 = itemInt1.scan(rawRecord); - const auto deckIntItem2 = itemInt2.scan(rawRecord); - - BOOST_CHECK_EQUAL(10, deckIntItem1.get< int >(0)); - BOOST_CHECK_EQUAL(20, deckIntItem2.get< int >(0)); -} - -BOOST_AUTO_TEST_CASE(Scan_RawRecordErrorInRawData_ExceptionThrown) { - ParserItem itemInt(std::string("ITEM2"), 0); - - // Wrong type - RawRecord rawRecord2( "333.2 /" ); - BOOST_CHECK_THROW(itemInt.scan(rawRecord2), std::invalid_argument); - - // Wrong type - RawRecord rawRecord3( "100X /" ); - BOOST_CHECK_THROW(itemInt.scan(rawRecord3), std::invalid_argument); - - // Wrong type - RawRecord rawRecord5( "astring /" ); - BOOST_CHECK_THROW(itemInt.scan(rawRecord5), std::invalid_argument); -} - -/*********************String************************'*/ -/*****************************************************************/ -/**/ - -BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_missingName_throws) { - Json::JsonObject jsonConfig("{\"nameX\": \"ITEM1\" , \"size_type\" : \"ALL\"}"); - BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument ); -} - -BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_withDefault) { - Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"STRING\", \"size_type\" : \"SINGLE\", \"default\" : \"100\"}"); - ParserItem item1( jsonConfig ); - BOOST_CHECK_EQUAL( "100" , item1.getDefault< std::string >() ); -} - -BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_withDefaultInvalid_throws) { - Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\", \"default\" : [1,2,3]}"); - BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument ); -} -/**/ -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(init_defaultvalue_defaultset) { - ParserItem itemString(std::string("ITEM1") , "DEFAULT"); - RawRecord rawRecord( "'1*'" ); - BOOST_CHECK_EQUAL("1*", itemString.scan( rawRecord ).get< std::string >(0) ); - - RawRecord rawRecord1( "13*" ); - BOOST_CHECK_EQUAL("DEFAULT" , itemString.scan( rawRecord1 ).get< std::string >(0) ); - - RawRecord rawRecord2( "*" ); - BOOST_CHECK_EQUAL("DEFAULT", itemString.scan( rawRecord2 ).get< std::string >(0) ); - - ParserItem itemStringDefaultChanged("ITEM2", "SPECIAL"); - RawRecord rawRecord3( "*" ); - BOOST_CHECK_EQUAL("SPECIAL", itemStringDefaultChanged.scan( rawRecord3 ).get< std::string >(0) ); -} - -BOOST_AUTO_TEST_CASE(scan_all_valuesCorrect) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem itemString("ITEMWITHMANY", sizeType, ""); - RawRecord rawRecord( "'WELL1' FISK BANAN 3*X OPPLEGG_FOR_DATAANALYSE 'Foo$*!% BAR' " ); - const auto deckItem = itemString.scan(rawRecord); - BOOST_CHECK_EQUAL(8U, deckItem.size()); - - BOOST_CHECK_EQUAL("WELL1", deckItem.get< std::string >(0)); - BOOST_CHECK_EQUAL("FISK", deckItem.get< std::string >(1)); - BOOST_CHECK_EQUAL("BANAN", deckItem.get< std::string >(2)); - BOOST_CHECK_EQUAL("X", deckItem.get< std::string >(3)); - BOOST_CHECK_EQUAL("X", deckItem.get< std::string >(4)); - BOOST_CHECK_EQUAL("X", deckItem.get< std::string >(5)); - BOOST_CHECK_EQUAL("OPPLEGG_FOR_DATAANALYSE", deckItem.get< std::string >(6)); - BOOST_CHECK_EQUAL("Foo$*!% BAR", deckItem.get< std::string >(7)); -} - -BOOST_AUTO_TEST_CASE(scan_all_withdefaults) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem itemString("ITEMWITHMANY", sizeType, 0); - RawRecord rawRecord( "10*1 10* 10*2 " ); - const auto deckItem = itemString.scan(rawRecord); - - BOOST_CHECK_EQUAL(30U, deckItem.size()); - - BOOST_CHECK( !deckItem.defaultApplied(0) ); - BOOST_CHECK( !deckItem.defaultApplied(9) ); - BOOST_CHECK( deckItem.defaultApplied(10) ); - BOOST_CHECK( deckItem.defaultApplied(19) ); - BOOST_CHECK( !deckItem.defaultApplied(20) ); - BOOST_CHECK( !deckItem.defaultApplied(29) ); - - BOOST_CHECK_THROW(deckItem.get< int >(30), std::out_of_range); - BOOST_CHECK_THROW(deckItem.defaultApplied(30), std::out_of_range); - - BOOST_CHECK_EQUAL(1, deckItem.get< int >(0)); - BOOST_CHECK_EQUAL(1, deckItem.get< int >(9)); - BOOST_CHECK_EQUAL(2, deckItem.get< int >(20)); - BOOST_CHECK_EQUAL(2, deckItem.get< int >(29)); -} - -BOOST_AUTO_TEST_CASE(scan_single_dataCorrect) { - ParserItem itemString( "ITEM1", ""); - RawRecord rawRecord( "'WELL1' 'WELL2'" ); - const auto deckItem = itemString.scan(rawRecord); - BOOST_CHECK_EQUAL(1U, deckItem.size()); - BOOST_CHECK_EQUAL("WELL1", deckItem.get< std::string >(0)); -} - -BOOST_AUTO_TEST_CASE(scan_singleWithMixedRecord_dataCorrect) { - ParserItem itemString("ITEM1", ""); - ParserItem itemInt("ITEM1", ""); - - RawRecord rawRecord( "2 'WELL1' /" ); - itemInt.scan(rawRecord); - const auto deckItem = itemString.scan(rawRecord); - BOOST_CHECK_EQUAL("WELL1", deckItem.get< std::string >(0)); -} - -/******************String and int**********************/ -BOOST_AUTO_TEST_CASE(scan_intsAndStrings_dataCorrect) { - RawRecord rawRecord( "'WELL1' 2 2 2*3" ); - - auto sizeTypeItemBoxed = ParserItem::item_size::ALL; - - ParserItem itemSingleString(std::string("ITEM1"), ""); - const auto deckItemWell1 = itemSingleString.scan(rawRecord); - BOOST_CHECK_EQUAL("WELL1", deckItemWell1.get< std::string >(0)); - - ParserItem itemSomeInts("SOMEINTS", sizeTypeItemBoxed, 0 ); - const auto deckItemInts = itemSomeInts.scan(rawRecord); - BOOST_CHECK_EQUAL(2, deckItemInts.get< int >(0)); - BOOST_CHECK_EQUAL(2, deckItemInts.get< int >(1)); - BOOST_CHECK_EQUAL(3, deckItemInts.get< int >(2)); - BOOST_CHECK_EQUAL(3, deckItemInts.get< int >(3)); -} - -/*****************************************************************/ - - -BOOST_AUTO_TEST_CASE(ParserDefaultHasDimensionReturnsFalse) { - ParserItem intItem(std::string("SOMEINTS"), 0); - ParserItem stringItem(std::string("SOMESTRING"), ""); - ParserItem doubleItem(std::string("SOMEDOUBLE"), 0.0); - - BOOST_CHECK( !intItem.hasDimension() ); - BOOST_CHECK( !stringItem.hasDimension() ); - BOOST_CHECK( !doubleItem.hasDimension() ); -} - -BOOST_AUTO_TEST_CASE(ParserIntItemGetDimensionThrows) { - ParserItem intItem(std::string("SOMEINT")); - - BOOST_CHECK_THROW( intItem.getDimension(0) , std::invalid_argument ); - BOOST_CHECK_THROW( intItem.push_backDimension("Length") , std::invalid_argument ); -} - - - -BOOST_AUTO_TEST_CASE(ParserDoubleItemAddMultipleDimensionToSIngleSizeThrows) { - ParserItem doubleItem(std::string("SOMEDOUBLE"), 0.0); - - doubleItem.push_backDimension("Length*Length"); - BOOST_CHECK_THROW( doubleItem.push_backDimension("Length*Length"), std::invalid_argument); -} - - -BOOST_AUTO_TEST_CASE(ParserDoubleItemWithDimensionHasReturnsCorrect) { - ParserItem doubleItem("SOMEDOUBLE", 0.0); - - BOOST_CHECK( !doubleItem.hasDimension() ); - doubleItem.push_backDimension("Length*Length"); - BOOST_CHECK( doubleItem.hasDimension() ); -} - -BOOST_AUTO_TEST_CASE(ParserDoubleItemGetDimension) { - ParserItem doubleItem( "SOMEDOUBLE" , ParserItem::item_size::ALL, 0.0 ); - - BOOST_CHECK_THROW( doubleItem.getDimension( 10 ) , std::out_of_range ); - BOOST_CHECK_THROW( doubleItem.getDimension( 0 ) , std::out_of_range ); - - doubleItem.push_backDimension("Length"); - doubleItem.push_backDimension("Length*Length"); - doubleItem.push_backDimension("Length*Length*Length"); - - BOOST_CHECK_EQUAL( "Length" , doubleItem.getDimension(0)); - BOOST_CHECK_EQUAL( "Length*Length" , doubleItem.getDimension(1)); - BOOST_CHECK_EQUAL( "Length*Length*Length" , doubleItem.getDimension(2)); - BOOST_CHECK_THROW( doubleItem.getDimension( 3 ) , std::out_of_range ); -} diff --git a/tests/parser/ParserKeywordTests.cpp b/tests/parser/ParserKeywordTests.cpp deleted file mode 100644 index 10b1d69fe..000000000 --- a/tests/parser/ParserKeywordTests.cpp +++ /dev/null @@ -1,512 +0,0 @@ -/* - Copyright 2013 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 . - */ - - -#define BOOST_TEST_MODULE ParserTests - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Opm; - -namespace { - -std::shared_ptr createFixedSized(const std::string& kw , size_t size) { - std::shared_ptr pkw = std::make_shared(kw); - pkw->setFixedSize( size ); - return pkw; -} - -std::shared_ptr createDynamicSized(const std::string& kw) { - std::shared_ptr pkw = std::make_shared(kw); - pkw->setSizeType(SLASH_TERMINATED); - return pkw; -} - - -std::shared_ptr createTable(const std::string& name, - const std::string& sizeKeyword, - const std::string& sizeItem, - bool isTableCollection) { - std::shared_ptr pkw = std::make_shared(name); - pkw->initSizeKeyword(sizeKeyword , sizeItem); - pkw->setTableCollection(isTableCollection); - return pkw; -} - -} - -BOOST_AUTO_TEST_CASE(construct_withname_nameSet) { - const auto& parserKeyword = createDynamicSized("BPR"); - BOOST_CHECK_EQUAL(parserKeyword->getName(), "BPR"); -} - -BOOST_AUTO_TEST_CASE(NamedInit) { - std::string keyword("KEYWORD"); - const auto& parserKeyword = createFixedSized(keyword, (size_t) 100); - BOOST_CHECK_EQUAL(parserKeyword->getName(), keyword); -} - -BOOST_AUTO_TEST_CASE(ParserKeyword_default_SizeTypedefault) { - std::string keyword("KEYWORD"); - const auto& parserKeyword = createDynamicSized(keyword); - BOOST_CHECK_EQUAL(parserKeyword->getSizeType() , SLASH_TERMINATED); -} - - -BOOST_AUTO_TEST_CASE(ParserKeyword_withSize_SizeTypeFIXED) { - std::string keyword("KEYWORD"); - const auto& parserKeyword = createFixedSized(keyword, (size_t) 100); - BOOST_CHECK_EQUAL(parserKeyword->getSizeType() , FIXED); -} - -BOOST_AUTO_TEST_CASE(ParserKeyword_withOtherSize_SizeTypeOTHER) { - std::string keyword("KEYWORD"); - const auto& parserKeyword = createTable(keyword, "EQUILDIMS" , "NTEQUIL" , false); - const std::pair& sizeKW = parserKeyword->getSizeDefinitionPair(); - BOOST_CHECK_EQUAL(OTHER_KEYWORD_IN_DECK , parserKeyword->getSizeType() ); - BOOST_CHECK_EQUAL("EQUILDIMS", sizeKW.first ); - BOOST_CHECK_EQUAL("NTEQUIL" , sizeKW.second ); -} - -BOOST_AUTO_TEST_CASE(ParserKeyword_validDeckName) { - BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("SUMMARY")); - BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("MixeCase")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("NAMETOOLONG")); - BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("STRING88")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("88STRING")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("KEY.EXT")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("STRING~")); - BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("MINUS-")); - BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("PLUS+")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("SHARP#")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("-MINUS")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("+PLUS")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("#SHARP")); - - BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("TVDP*")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("*")); -} - -BOOST_AUTO_TEST_CASE(ParserKeyword_validInternalName) { - BOOST_CHECK_EQUAL( true , ParserKeyword::validInternalName("SUMMARY")); - BOOST_CHECK_EQUAL( true , ParserKeyword::validInternalName("MixeCase")); - BOOST_CHECK_EQUAL( true , ParserKeyword::validInternalName("NAMEISQUITELONG")); - BOOST_CHECK_EQUAL( true , ParserKeyword::validInternalName("I_have_underscores")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("WHATABOUT+")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("ORMINUS-")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("NOSHARP#")); - BOOST_CHECK_EQUAL( true , ParserKeyword::validInternalName("STRING88")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("88STRING")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("KEY.EXT")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("STRING~")); - - BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("TVDP*")); - BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("*")); -} - -BOOST_AUTO_TEST_CASE(ParserKeywordMatches) { - const auto& parserKeyword = createFixedSized("HELLO", (size_t) 1); - parserKeyword->clearDeckNames(); - parserKeyword->setMatchRegex("WORLD.+"); - BOOST_CHECK_EQUAL( false , parserKeyword->matches("HELLO")); - BOOST_CHECK_EQUAL( false , parserKeyword->matches("WORLD")); - BOOST_CHECK_EQUAL( true , parserKeyword->matches("WORLDABC")); - BOOST_CHECK_EQUAL( false , parserKeyword->matches("WORLD#BC")); - BOOST_CHECK_EQUAL( false , parserKeyword->matches("WORLDIAMTOOLONG")); -} - -BOOST_AUTO_TEST_CASE(AddDataKeyword_correctlyConfigured) { - const auto& parserKeyword = createFixedSized("PORO", (size_t) 1); - ParserItem item( "ACTNUM" , ParserItem::item_size::ALL, 0 ); - ParserRecord record; - - BOOST_CHECK( !parserKeyword->isDataKeyword() ); - record.addDataItem( item ); - parserKeyword->addRecord( record ); - BOOST_CHECK( parserKeyword->isDataKeyword() ); - - BOOST_CHECK( parserKeyword->hasFixedSize() ); - BOOST_CHECK_EQUAL(1U , parserKeyword->getFixedSize() ); -} - -BOOST_AUTO_TEST_CASE(WrongConstructor_addDataItem_throws) { - const auto& parserKeyword = createDynamicSized("PORO"); - ParserItem dataItem( "ACTNUM" , ParserItem::item_size::ALL ); - ParserRecord record; - record.addDataItem( dataItem ); - BOOST_CHECK_THROW( parserKeyword->addDataRecord( record ) , std::invalid_argument); -} - - -BOOST_AUTO_TEST_CASE(DefaultConstructur_setDescription_canReadBack) { - const auto& parserKeyword = createDynamicSized("BPR"); - std::string description("This is the description"); - parserKeyword->setDescription(description); - BOOST_CHECK_EQUAL( description, parserKeyword->getDescription()); -} - -/*****************************************************************/ -/* json */ -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject) { - Json::JsonObject jsonObject("{\"name\": \"XXX\", \"sections\":[], \"size\" : 0}"); - const auto& parserKeyword = std::make_shared(jsonObject); - BOOST_CHECK_EQUAL("XXX" , parserKeyword->getName()); - BOOST_CHECK_EQUAL( true , parserKeyword->hasFixedSize() ); -} - -BOOST_AUTO_TEST_CASE(ConstructMultiNameFromJsonObject) { - const auto jsonString = - "{" - " \"name\": \"XXX\" ," - " \"sections\":[]," - " \"size\" : 0," - " \"deck_names\" : [" - " \"XXA\"," - " \"XXB\"," - " \"XXC\"" - " ]" - "}"; - Json::JsonObject jsonObject(jsonString); - auto parserKeyword = std::make_shared(jsonObject); - BOOST_CHECK_EQUAL("XXX" , parserKeyword->getName()); - BOOST_CHECK(parserKeyword->matches("XXA")); - BOOST_CHECK(parserKeyword->matches("XXB")); - BOOST_CHECK(parserKeyword->hasMultipleDeckNames()); - BOOST_CHECK(!parserKeyword->matches("XXD")); - BOOST_CHECK(!parserKeyword->matches("XXX")); -} - - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withSize) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"DOUBLE\"}]}"); - - const auto& parserKeyword = std::make_shared(jsonObject); - BOOST_CHECK_EQUAL("BPR" , parserKeyword->getName()); - BOOST_CHECK_EQUAL( true , parserKeyword->hasFixedSize() ); - BOOST_CHECK_EQUAL( 100U , parserKeyword->getFixedSize() ); - -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_nosize_notItems_OK) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"]}"); - const auto& parserKeyword = std::make_shared(jsonObject); - BOOST_CHECK_EQUAL( true , parserKeyword->hasFixedSize() ); - BOOST_CHECK_EQUAL( 0U , parserKeyword->getFixedSize()); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withSizeOther) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : {\"keyword\" : \"Bjarne\" , \"item\": \"BjarneIgjen\"}, \"items\" :[{\"name\":\"ItemX\" , \"value_type\" : \"DOUBLE\"}]}"); - const auto& parserKeyword = std::make_shared(jsonObject); - const std::pair& sizeKW = parserKeyword->getSizeDefinitionPair(); - BOOST_CHECK_EQUAL("BPR" , parserKeyword->getName()); - BOOST_CHECK_EQUAL( false , parserKeyword->hasFixedSize() ); - BOOST_CHECK_EQUAL(OTHER_KEYWORD_IN_DECK , parserKeyword->getSizeType()); - BOOST_CHECK_EQUAL("Bjarne", sizeKW.first ); - BOOST_CHECK_EQUAL("BjarneIgjen" , sizeKW.second ); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_missingName_throws) { - Json::JsonObject jsonObject("{\"nameXX\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100}"); - BOOST_CHECK_THROW(std::make_shared(jsonObject) , std::invalid_argument); -} - -/* - "items": [{"name" : "I" , "size_type" : "SINGLE" , "value_type" : "int"}] -*/ -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_invalidItems_throws) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : 100}"); - BOOST_CHECK_THROW(std::make_shared(jsonObject) , std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_ItemMissingName_throws) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"nameX\" : \"I\" , \"value_type\" : \"INT\"}]}"); - BOOST_CHECK_THROW(std::make_shared(jsonObject) , std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_ItemMissingValueType_throws) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"SINGLE\" , \"Xvalue_type\" : \"INT\"}]}"); - BOOST_CHECK_THROW(std::make_shared(jsonObject) , std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_ItemInvalidEnum_throws) { - Json::JsonObject jsonObject1("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"XSINGLE\" , \"value_type\" : \"INT\"}]}"); - Json::JsonObject jsonObject2("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"SINGLE\" , \"value_type\" : \"INTX\"}]}"); - - BOOST_CHECK_THROW(std::make_shared(jsonObject1) , std::invalid_argument); - BOOST_CHECK_THROW(std::make_shared(jsonObject2) , std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObjectItemsOK) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"name\" : \"I\", \"value_type\" : \"INT\"}]}"); - const auto& parserKeyword = std::make_shared(jsonObject); - const auto& record = parserKeyword->getRecord(0); - const auto& item = record.get( 0 ); - BOOST_CHECK_EQUAL( 1U , record.size( ) ); - BOOST_CHECK_EQUAL( "I" , item.name( ) ); - BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE , item.sizeType()); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_sizeFromOther) { - Json::JsonObject jsonConfig("{\"name\": \"EQUILX\", \"sections\":[\"PROPS\"], \"size\" : {\"keyword\":\"EQLDIMS\" , \"item\" : \"NTEQUL\"}, \"items\" :[{\"name\":\"ItemX\" ,\"value_type\" : \"DOUBLE\"}]}"); - BOOST_CHECK_NO_THROW( std::make_shared(jsonConfig) ); -} - -BOOST_AUTO_TEST_CASE(Default_NotData) { - auto parserKeyword = createDynamicSized("BPR"); - BOOST_CHECK_EQUAL( false , parserKeyword->isDataKeyword()); -} - - -BOOST_AUTO_TEST_CASE(AddDataKeywordFromJson_defaultThrows) { - Json::JsonObject jsonConfig("{\"name\": \"ACTNUM\", \"sections\":[\"GRID\"], \"data\" : {\"value_type\": \"INT\" , \"default\" : 100}}"); - BOOST_CHECK_THROW( std::make_shared(jsonConfig) , std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(AddDataKeywordFromJson_correctlyConfigured) { - Json::JsonObject jsonConfig("{\"name\": \"ACTNUM\", \"sections\":[\"GRID\"], \"data\" : {\"value_type\": \"INT\"}}"); - const auto& parserKeyword = std::make_shared(jsonConfig); - const auto& parserRecord = parserKeyword->getRecord(0); - const auto& item = parserRecord.get(0); - - - BOOST_CHECK( parserKeyword->isDataKeyword() ); - BOOST_CHECK( parserKeyword->hasFixedSize( ) ); - BOOST_CHECK_EQUAL(1U , parserKeyword->getFixedSize() ); - - BOOST_CHECK_EQUAL( item.name() , ParserKeywords::ACTNUM::data::itemName ); - BOOST_CHECK_EQUAL( ParserItem::item_size::ALL, item.sizeType() ); -} - -BOOST_AUTO_TEST_CASE(AddkeywordFromJson_numTables_incoorect_throw) { - Json::JsonObject jsonConfig("{\"name\": \"PVTG\", \"sections\":[\"PROPS\"], \"num_tables\" : 100}"); - BOOST_CHECK_THROW(std::make_shared(jsonConfig) , std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(AddkeywordFromJson_isTableCollection) { - Json::JsonObject jsonConfig("{\"name\": \"PVTG\", \"sections\":[\"PROPS\"], \"num_tables\" : {\"keyword\": \"TABDIMS\" , \"item\" : \"NTPVT\"} , \"items\" : [{\"name\" : \"data\", \"value_type\" : \"DOUBLE\"}]}"); - const auto& parserKeyword = std::make_shared(jsonConfig); - - BOOST_CHECK_EQUAL( true , parserKeyword->isTableCollection() ); - BOOST_CHECK_EQUAL( false , parserKeyword->isDataKeyword()); - BOOST_CHECK_EQUAL( false , parserKeyword->hasFixedSize( )); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_InvalidSize_throws) { - Json::JsonObject jsonObject1("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : \"string\" , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"SINGLE\" , \"value_type\" : \"INT\"}]}"); - Json::JsonObject jsonObject2("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : [1,2,3] , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"SINGLE\" , \"value_type\" : \"INT\"}]}"); - - BOOST_CHECK_THROW(std::make_shared(jsonObject1) , std::invalid_argument); - BOOST_CHECK_THROW(std::make_shared(jsonObject2) , std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_SizeUNKNOWN_OK) { - Json::JsonObject jsonObject1("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : \"UNKNOWN\" , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"SINGLE\" , \"value_type\" : \"INT\"}]}"); - auto parserKeyword = std::make_shared(jsonObject1); - - BOOST_CHECK_EQUAL( UNKNOWN , parserKeyword->getSizeType() ); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_WithDescription_DescriptionPropertyShouldBePopulated) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"description\" : \"Description\"}"); - auto parserKeyword = std::make_shared(jsonObject); - - BOOST_CHECK_EQUAL( "Description", parserKeyword->getDescription() ); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_WithoutDescription_DescriptionPropertyShouldBeEmpty) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"]}"); - auto parserKeyword = std::make_shared(jsonObject); - - BOOST_CHECK_EQUAL( "", parserKeyword->getDescription() ); -} - -/* */ -/*****************************************************************/ -BOOST_AUTO_TEST_CASE(getFixedSize_sizeObjectHasFixedSize_sizeReturned) { - const auto& parserKeyword = createFixedSized("JA", (size_t) 3); - BOOST_CHECK_EQUAL(3U, parserKeyword->getFixedSize()); - -} - -BOOST_AUTO_TEST_CASE(getFixedSize_sizeObjectDoesNotHaveFixedSizeObjectSet_ExceptionThrown) { - const auto& parserKeyword = createDynamicSized("JA"); - BOOST_CHECK_THROW(parserKeyword->getFixedSize(), std::logic_error); -} - -BOOST_AUTO_TEST_CASE(hasFixedSize_hasFixedSizeObject_returnstrue) { - const auto& parserKeyword = createFixedSized("JA", (size_t) 2); - BOOST_CHECK(parserKeyword->hasFixedSize()); -} - -BOOST_AUTO_TEST_CASE(hasFixedSize_sizeObjectDoesNotHaveFixedSize_returnsfalse) { - const auto& parserKeyword = createDynamicSized("JA"); - BOOST_CHECK(!parserKeyword->hasFixedSize()); -} - -/******/ -/* Tables: */ -BOOST_AUTO_TEST_CASE(DefaultIsNot_TableKeyword) { - const auto& parserKeyword = createDynamicSized("JA"); - BOOST_CHECK(!parserKeyword->isTableCollection()); -} - -BOOST_AUTO_TEST_CASE(ConstructorIsTableCollection) { - const auto& parserKeyword = createTable("JA" , "TABDIMS" , "NTPVT" , true); - const std::pair& sizeKW = parserKeyword->getSizeDefinitionPair(); - BOOST_CHECK(parserKeyword->isTableCollection()); - BOOST_CHECK(!parserKeyword->hasFixedSize()); - - BOOST_CHECK_EQUAL( parserKeyword->getSizeType() , OTHER_KEYWORD_IN_DECK); - BOOST_CHECK_EQUAL("TABDIMS", sizeKW.first ); - BOOST_CHECK_EQUAL("NTPVT" , sizeKW.second ); -} - -BOOST_AUTO_TEST_CASE(ParseEmptyRecord) { - const auto& tabdimsKeyword = createFixedSized("TEST" , 1); - ParserRecord record; - ParserItem item("ITEM", ParserItem::item_size::ALL ); - item.setType( int() ); - auto rawkeyword = std::make_shared< RawKeyword >( tabdimsKeyword->getName() , "FILE" , 10U , 1 ); - ParseContext parseContext; - MessageContainer msgContainer; - - BOOST_CHECK_EQUAL( Raw::FIXED , rawkeyword->getSizeType()); - rawkeyword->addRawRecordString("/"); - record.addItem(item); - tabdimsKeyword->addRecord( record ); - - const auto deckKeyword = tabdimsKeyword->parse( parseContext , msgContainer, rawkeyword ); - BOOST_REQUIRE_EQUAL( 1U , deckKeyword.size()); - - const auto& deckRecord = deckKeyword.getRecord(0); - BOOST_REQUIRE_EQUAL( 1U , deckRecord.size()); - - BOOST_CHECK_EQUAL(0U , deckRecord.getItem( 0 ).size()); -} - - - -/*****************************************************************/ -/* Dimension */ -BOOST_AUTO_TEST_CASE(ParseKeywordHasDimensionCorrect) { - const auto& parserKeyword = createDynamicSized("JA"); - ParserItem item1("I", ParserItem::item_size::SINGLE, 0 ); - ParserItem item2("ID", ParserItem::item_size::SINGLE, 0.0 ); - ParserRecord record; - - BOOST_CHECK( !parserKeyword->hasDimension()); - - record.addItem( item1 ); - parserKeyword->addRecord( record ); - BOOST_CHECK( !parserKeyword->hasDimension() ); - BOOST_CHECK_EQUAL( 0U , item1.numDimensions() ); - - item2.push_backDimension("Length*Length/Time"); - record.addItem( item2 ); - const auto& parserKeyword2 = createDynamicSized("JA"); - parserKeyword2->addRecord( record ); - BOOST_CHECK( parserKeyword2->hasDimension() ); - BOOST_CHECK_EQUAL( 1U , item2.numDimensions() ); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withDimension) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"DOUBLE\" , \"dimension\" : \"Length*Length/Time\"}]}"); - const auto& parserKeyword = std::make_shared(jsonObject); - const auto& record = parserKeyword->getRecord(0); - const auto& item = record.get("ItemX"); - - BOOST_CHECK_EQUAL("BPR" , parserKeyword->getName()); - BOOST_CHECK( parserKeyword->hasFixedSize() ); - BOOST_CHECK_EQUAL( 100U , parserKeyword->getFixedSize() ); - - BOOST_CHECK( parserKeyword->hasDimension() ); - BOOST_CHECK( item.hasDimension() ); - BOOST_CHECK_EQUAL( 1U , item.numDimensions() ); -} - -BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withDimensionList) { - Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"ALL\" , \"value_type\" : \"DOUBLE\" , \"dimension\" : [\"Length*Length/Time\" , \"Time\", \"1\"]}]}"); - const auto& parserKeyword = std::make_shared(jsonObject); - const auto& record = parserKeyword->getRecord(0); - const auto& item = record.get("ItemX"); - - BOOST_CHECK_EQUAL("BPR" , parserKeyword->getName()); - BOOST_CHECK_EQUAL( true , parserKeyword->hasFixedSize() ); - BOOST_CHECK_EQUAL( 100U , parserKeyword->getFixedSize() ); - - BOOST_CHECK( parserKeyword->hasDimension() ); - BOOST_CHECK( item.hasDimension() ); - BOOST_CHECK_EQUAL( 3U , item.numDimensions() ); -} - - - - - -BOOST_AUTO_TEST_CASE(ConstructFromJson_withRecords) { - const std::string json_string1 = "{\"name\" : \"MULTFLT\", \"sections\" : [\"GRID\", \"EDIT\", \"SCHEDULE\"], \"records\" : [[" - "{\"name\" : \"fault\" , \"value_type\" : \"STRING\"}," - "{\"name\" : \"factor\" , \"value_type\" : \"DOUBLE\"}]]}"; - - const std::string json_string2 = "{\"name\" : \"MULTFLT\", \"sections\" : [\"GRID\", \"EDIT\", \"SCHEDULE\"], \"items\" : [" - "{\"name\" : \"fault\" , \"value_type\" : \"STRING\"}," - "{\"name\" : \"factor\" , \"value_type\" : \"DOUBLE\"}]}"; - - - Json::JsonObject jsonObject1( json_string1 ); - Json::JsonObject jsonObject2( json_string2 ); - auto kw1 = std::make_shared( jsonObject1 ); - auto kw2 = std::make_shared( jsonObject2 ); - - BOOST_CHECK_EQUAL( *kw1, *kw2 ); - -} - -BOOST_AUTO_TEST_CASE(ConstructFromJson_withRecords_and_items_throws) { - const std::string json_string = "{\"name\" : \"MULTFLT\", \"sections\" : [\"GRID\", \"EDIT\", \"SCHEDULE\"], \"records\" : [[" - "{\"name\" : \"fault\" , \"value_type\" : \"STRING\"}," - "{\"name\" : \"factor\" , \"value_type\" : \"DOUBLE\"}]],\"items\" : [" - "{\"name\" : \"fault\" , \"value_type\" : \"STRING\"}," - "{\"name\" : \"factor\" , \"value_type\" : \"DOUBLE\"}]}"; - Json::JsonObject jsonObject( json_string ); - BOOST_CHECK_THROW( std::make_shared( jsonObject ) , std::invalid_argument); -} - - -BOOST_AUTO_TEST_CASE(Create1Arg) { - ParserKeyword kw("GRID"); - BOOST_CHECK_EQUAL( false , kw.hasDimension() ); - BOOST_CHECK( kw.hasFixedSize() ); - BOOST_CHECK_EQUAL( kw.getFixedSize( ) , 0 ); - - BOOST_CHECK_THROW( kw.getRecord( 0 ) , std::invalid_argument ); -} diff --git a/tests/parser/ParserRecordTests.cpp b/tests/parser/ParserRecordTests.cpp deleted file mode 100644 index 23deeab8f..000000000 --- a/tests/parser/ParserRecordTests.cpp +++ /dev/null @@ -1,373 +0,0 @@ -/* - Copyright 2013 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 . - */ - - -#define BOOST_TEST_MODULE ParserTests -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "opm/parser/eclipse/RawDeck/RawKeyword.hpp" -#include "opm/parser/eclipse/Parser/ParserKeyword.hpp" - - -using namespace Opm; - - -const static auto SINGLE = ParserItem::item_size::SINGLE; -const static auto ALL = ParserItem::item_size::ALL; - -BOOST_AUTO_TEST_CASE(DefaultConstructor_NoParams_NoThrow) { - BOOST_CHECK_NO_THROW(ParserRecord record); -} - -BOOST_AUTO_TEST_CASE(Size_NoElements_ReturnsZero) { - ParserRecord record; - BOOST_CHECK_EQUAL(0U, record.size()); -} - -BOOST_AUTO_TEST_CASE(Size_OneItem_Return1) { - ParserItem itemInt("ITEM1", SINGLE ); - ParserRecord record; - record.addItem(itemInt); - BOOST_CHECK_EQUAL(1U, record.size()); -} - -BOOST_AUTO_TEST_CASE(Get_OneItem_Return1) { - ParserItem itemInt("ITEM1", SINGLE); - ParserRecord record; - record.addItem(itemInt); - - BOOST_CHECK_EQUAL(record.get(0), itemInt); -} - -BOOST_AUTO_TEST_CASE(Get_outOfRange_Throw) { - BOOST_CHECK_THROW(ParserRecord{}.get(0), std::out_of_range); -} - -BOOST_AUTO_TEST_CASE(Get_KeyNotFound_Throw) { - ParserRecord record; - BOOST_CHECK_THROW(record.get("Hei"), std::out_of_range ); -} - -BOOST_AUTO_TEST_CASE(Get_KeyFound_OK) { - ParserItem itemInt("ITEM1", SINGLE ); - ParserRecord record; - record.addItem(itemInt); - BOOST_CHECK_EQUAL(record.get("ITEM1"), itemInt); -} - -BOOST_AUTO_TEST_CASE(Get_GetByNameAndIndex_OK) { - ParserItem itemInt("ITEM1", SINGLE); - ParserRecord record; - record.addItem(itemInt); - - const auto& itemByName = record.get("ITEM1"); - const auto& itemByIndex = record.get(0); - BOOST_CHECK_EQUAL(itemInt, itemByName); - BOOST_CHECK_EQUAL(itemInt, itemByIndex); -} - -BOOST_AUTO_TEST_CASE(addItem_SameName_Throw) { - ParserItem itemInt1("ITEM1", SINGLE); - ParserItem itemInt2("ITEM1", SINGLE); - ParserRecord record; - record.addItem(itemInt1); - BOOST_CHECK_THROW(record.addItem(itemInt2), std::invalid_argument); -} - -static ParserRecord createSimpleParserRecord() { - ParserItem itemInt1("ITEM1", SINGLE, 0 ); - ParserItem itemInt2("ITEM2", SINGLE, 0 ); - ParserRecord record; - - record.addItem(itemInt1); - record.addItem(itemInt2); - return record; -} - -BOOST_AUTO_TEST_CASE(parse_validRecord_noThrow) { - auto record = createSimpleParserRecord(); - ParseContext parseContext; - RawRecord raw( string_view( "100 443" ) ); - MessageContainer msgContainer; - BOOST_CHECK_NO_THROW(record.parse(parseContext, msgContainer, raw ) ); -} - -BOOST_AUTO_TEST_CASE(parse_validRecord_deckRecordCreated) { - auto record = createSimpleParserRecord(); - RawRecord rawRecord( string_view( "100 443" ) ); - ParseContext parseContext; - MessageContainer msgContainer; - const auto deckRecord = record.parse(parseContext , msgContainer, rawRecord); - BOOST_CHECK_EQUAL(2U, deckRecord.size()); -} - - -// INT INT DOUBLE DOUBLE INT DOUBLE - -static ParserRecord createMixedParserRecord() { - - auto sizeType = SINGLE; - ParserItem itemInt1( "INTITEM1", sizeType, 0 ); - ParserItem itemInt2( "INTITEM2", sizeType, 0 ); - ParserItem itemInt3( "INTITEM3", sizeType, 0 ); - ParserItem itemDouble1( "DOUBLEITEM1", sizeType, 0.0 ); - ParserItem itemDouble2( "DOUBLEITEM2", sizeType, 0.0 ); - ParserItem itemDouble3( "DOUBLEITEM3", sizeType, 0.0 ); - - ParserRecord record; - record.addItem(itemInt1); - record.addItem(itemInt2); - record.addItem(itemDouble1); - record.addItem(itemDouble2); - record.addItem(itemInt3); - record.addItem(itemDouble3); - - return record; -} - -BOOST_AUTO_TEST_CASE(parse_validMixedRecord_noThrow) { - auto record = createMixedParserRecord(); - RawRecord rawRecord( string_view( "1 2 10.0 20.0 4 90.0") ); - ParseContext parseContext; - MessageContainer msgContainer; - BOOST_CHECK_NO_THROW(record.parse(parseContext , msgContainer, rawRecord)); -} - -BOOST_AUTO_TEST_CASE(Equal_Equal_ReturnsTrue) { - auto record1 = createMixedParserRecord(); - auto record2 = createMixedParserRecord(); - - BOOST_CHECK(record1.equal(record1)); - BOOST_CHECK(record1.equal(record2)); -} - -BOOST_AUTO_TEST_CASE(Equal_Different_ReturnsFalse) { - auto sizeType = SINGLE; - ParserItem itemInt( "INTITEM1", sizeType, 0 ); - ParserItem itemDouble( "DOUBLEITEM1", sizeType, 0.0 ); - ParserItem itemString( "STRINGITEM1", sizeType, "" ); - ParserRecord record1; - ParserRecord record2; - ParserRecord record3; - - record1.addItem(itemInt); - record1.addItem(itemDouble); - - record2.addItem(itemInt); - record2.addItem(itemDouble); - record2.addItem(itemString); - - record3.addItem(itemDouble); - record3.addItem(itemInt); - BOOST_CHECK(!record1.equal(record2)); - BOOST_CHECK(!record1.equal(record3)); - -} - -BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) { - ParserRecord parserRecord; - ParserItem itemInt("ITEM1", SINGLE , 100 ); - ParserItem itemString("ITEM2", SINGLE , "DEFAULT" ); - ParserItem itemDouble("ITEM3", SINGLE , 3.14 ); - - parserRecord.addItem(itemInt); - parserRecord.addItem(itemString); - parserRecord.addItem(itemDouble); - - // according to the RM, this is invalid ("an asterisk by itself is not sufficient"), - // but it seems to appear in the wild. Thus, we interpret this as "1*"... - { - RawRecord rawRecord( "* " ); - const auto& deckStringItem = itemString.scan(rawRecord); - const auto& deckIntItem = itemInt.scan(rawRecord); - const auto& deckDoubleItem = itemDouble.scan(rawRecord); - - BOOST_CHECK(deckStringItem.size() == 1); - BOOST_CHECK(deckIntItem.size() == 1); - BOOST_CHECK(deckDoubleItem.size() == 1); - - BOOST_CHECK(deckStringItem.defaultApplied(0)); - BOOST_CHECK(deckIntItem.defaultApplied(0)); - BOOST_CHECK(deckDoubleItem.defaultApplied(0)); - } - - { - RawRecord rawRecord( "" ); - const auto deckStringItem = itemString.scan(rawRecord); - const auto deckIntItem = itemInt.scan(rawRecord); - const auto deckDoubleItem = itemDouble.scan(rawRecord); - - BOOST_CHECK_EQUAL(deckStringItem.size(), 1); - BOOST_CHECK_EQUAL(deckIntItem.size(), 1); - BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1); - - BOOST_CHECK(deckStringItem.defaultApplied(0)); - BOOST_CHECK(deckIntItem.defaultApplied(0)); - BOOST_CHECK(deckDoubleItem.defaultApplied(0)); - } - - - { - RawRecord rawRecord( "TRYGVE 10 2.9 " ); - - // let the raw record be "consumed" by the items. Note that the scan() method - // modifies the rawRecord object! - const auto& deckStringItem = itemString.scan(rawRecord); - const auto& deckIntItem = itemInt.scan(rawRecord); - const auto& deckDoubleItem = itemDouble.scan(rawRecord); - - BOOST_CHECK_EQUAL(deckStringItem.size(), 1); - BOOST_CHECK_EQUAL(deckIntItem.size(), 1); - BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1); - - BOOST_CHECK(!deckStringItem.defaultApplied(0)); - BOOST_CHECK(!deckIntItem.defaultApplied(0)); - BOOST_CHECK(!deckDoubleItem.defaultApplied(0)); - } - - // again this is invalid according to the RM, but it is used anyway in the wild... - { - RawRecord rawRecord( "* * *" ); - const auto deckStringItem = itemString.scan(rawRecord); - const auto deckIntItem = itemInt.scan(rawRecord); - const auto deckDoubleItem = itemDouble.scan(rawRecord); - - BOOST_CHECK_EQUAL(deckStringItem.size(), 1); - BOOST_CHECK_EQUAL(deckIntItem.size(), 1); - BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1); - - BOOST_CHECK(deckStringItem.defaultApplied(0)); - BOOST_CHECK(deckIntItem.defaultApplied(0)); - BOOST_CHECK(deckDoubleItem.defaultApplied(0)); - } - - { - RawRecord rawRecord( "3*" ); - const auto deckStringItem = itemString.scan(rawRecord); - const auto deckIntItem = itemInt.scan(rawRecord); - const auto deckDoubleItem = itemDouble.scan(rawRecord); - - BOOST_CHECK_EQUAL(deckStringItem.size(), 1); - BOOST_CHECK_EQUAL(deckIntItem.size(), 1); - BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1); - - BOOST_CHECK(deckStringItem.defaultApplied(0)); - BOOST_CHECK(deckIntItem.defaultApplied(0)); - BOOST_CHECK(deckDoubleItem.defaultApplied(0)); - } -} - -BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) { - ParserRecord parserRecord; - ParserItem itemI( "I", SINGLE, 0 ); - ParserItem itemJ( "J", SINGLE, 0 ); - ParserItem itemK( "K", SINGLE, 0 ); - ParseContext parseContext; - - parserRecord.addItem(itemI); - parserRecord.addItem(itemJ); - parserRecord.addItem(itemK); - - - RawRecord rawRecord( "3 3 3 " ); - MessageContainer msgContainer; - - BOOST_CHECK_NO_THROW(parserRecord.parse(parseContext , msgContainer, rawRecord)); - - RawRecord rawRecordOneExtra( "3 3 3 4 " ); - BOOST_CHECK_THROW(parserRecord.parse(parseContext , msgContainer, rawRecordOneExtra), std::invalid_argument); - - RawRecord rawRecordForgotRecordTerminator( "3 3 3 \n 4 4 4 " ); - BOOST_CHECK_THROW(parserRecord.parse(parseContext , msgContainer, rawRecordForgotRecordTerminator), std::invalid_argument); - -} - - -BOOST_AUTO_TEST_CASE(Parse_RawRecordTooFewItems) { - ParserRecord parserRecord; - ParserItem itemI( "I", SINGLE ); - ParserItem itemJ( "J", SINGLE ); - ParserItem itemK( "K", SINGLE ); - itemI.setType( int() ); - itemJ.setType( int() ); - itemK.setType( int() ); - - parserRecord.addItem(itemI); - parserRecord.addItem(itemJ); - parserRecord.addItem(itemK); - - ParseContext parseContext; - RawRecord rawRecord( "3 3 " ); - // no default specified for the third item, record can be parsed just fine but trying - // to access the data will raise an exception... - MessageContainer msgContainer; - BOOST_CHECK_NO_THROW(parserRecord.parse(parseContext , msgContainer, rawRecord)); - auto record = parserRecord.parse(parseContext , msgContainer, rawRecord); - BOOST_CHECK_NO_THROW(record.getItem(2)); - BOOST_CHECK_THROW(record.getItem(2).get< int >(0), std::out_of_range); -} - - - -BOOST_AUTO_TEST_CASE(ParseRecordHasDimensionCorrect) { - ParserRecord parserRecord; - ParserItem itemI( "I", SINGLE, 0.0 ); - - BOOST_CHECK( !parserRecord.hasDimension() ); - - parserRecord.addItem( itemI ); - BOOST_CHECK( !parserRecord.hasDimension() ); - - ParserItem item2( "ID", SINGLE, 0.0 ); - item2.push_backDimension("Length*Length/Time"); - parserRecord.addItem( item2 ); - BOOST_CHECK( parserRecord.hasDimension() ); -} - - -BOOST_AUTO_TEST_CASE(DefaultNotDataRecord) { - ParserRecord record; - BOOST_CHECK_EQUAL( false , record.isDataRecord() ); -} - -BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws1) { - ParserRecord record; - ParserItem dataItem( "ACTNUM" , ALL ); - ParserItem item ( "XXX" , ALL ); - record.addDataItem( dataItem ); - BOOST_CHECK_THROW( record.addItem( item ) , std::invalid_argument); - BOOST_CHECK_THROW( record.addItem( dataItem ) , std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws2) { - ParserRecord record; - ParserItem dataItem( "ACTNUM" , ALL); - ParserItem item ( "XXX" , ALL); - - record.addItem( item ); - BOOST_CHECK_THROW( record.addDataItem( dataItem ) , std::invalid_argument); -} diff --git a/tests/parser/ParserTests.cpp b/tests/parser/ParserTests.cpp index 8a7e1c419..a5424025e 100644 --- a/tests/parser/ParserTests.cpp +++ b/tests/parser/ParserTests.cpp @@ -17,9 +17,6 @@ along with OPM. If not, see . */ -#include -#include -#include #define BOOST_TEST_MODULE ParserTests #include @@ -27,24 +24,45 @@ #include #include - #include #include #include +#include #include +#include +#include using namespace Opm; -inline std::string prefix() { +namespace { + +std::string prefix() { return boost::unit_test::framework::master_test_suite().argv[1]; } -inline std::unique_ptr< ParserKeyword > createDynamicSized(const std::string& kw) { +std::unique_ptr< ParserKeyword > createDynamicSized(const std::string& kw) { std::unique_ptr< ParserKeyword > pkw( new ParserKeyword( kw ) ); pkw->setSizeType(SLASH_TERMINATED); return pkw; } +std::shared_ptr createFixedSized(const std::string& kw , size_t size) { + std::shared_ptr pkw = std::make_shared(kw); + pkw->setFixedSize( size ); + return pkw; +} + +std::shared_ptr createTable(const std::string& name, + const std::string& sizeKeyword, + const std::string& sizeItem, + bool isTableCollection) { + std::shared_ptr pkw = std::make_shared(name); + pkw->initSizeKeyword(sizeKeyword , sizeItem); + pkw->setTableCollection(isTableCollection); + return pkw; +} + +} /************************Basic structural tests**********************'*/ @@ -363,3 +381,1451 @@ BOOST_AUTO_TEST_CASE(ParseTNUM) { BOOST_CHECK( deck.hasKeyword("TNUMFXXX")); } +BOOST_AUTO_TEST_CASE(ScalarCheck) { + ParserItem item1("ITEM1", ParserItem::item_size::SINGLE ); + ParserItem item2("ITEM1", ParserItem::item_size::ALL ); + + BOOST_CHECK( item1.scalar()); + BOOST_CHECK( !item2.scalar()); +} + +BOOST_AUTO_TEST_CASE(Initialize_DefaultSizeType) { + ParserItem item1(std::string("ITEM1")); + BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE, item1.sizeType()); +} + + + +BOOST_AUTO_TEST_CASE(Initialize_Default) { + ParserItem item1(std::string("ITEM1")); + ParserItem item2(std::string("ITEM1"), 88); + BOOST_CHECK(!item1.hasDefault()); + BOOST_CHECK_THROW(item1.getDefault< int >(), std::invalid_argument); + BOOST_CHECK(item2.hasDefault()); + BOOST_CHECK_EQUAL(item2.getDefault< int >(), 88); +} + + +BOOST_AUTO_TEST_CASE(Initialize_Default_Double) { + ParserItem item1(std::string("ITEM1")); + ParserItem item2("ITEM1", 88.91); + BOOST_CHECK(!item1.hasDefault()); + BOOST_CHECK_THROW( item1.getDefault< double >(), std::invalid_argument ); + BOOST_CHECK_EQUAL( 88.91 , item2.getDefault< double >()); +} + +BOOST_AUTO_TEST_CASE(Initialize_Default_String) { + ParserItem item1(std::string("ITEM1")); + BOOST_CHECK(!item1.hasDefault()); + BOOST_CHECK_THROW(item1.getDefault< std::string >(), std::invalid_argument); + + ParserItem item2("ITEM1", "String"); + BOOST_CHECK(item2.hasDefault()); + BOOST_CHECK_EQUAL( "String" , item2.getDefault< std::string >()); +} + +BOOST_AUTO_TEST_CASE(scan_PreMatureTerminator_defaultUsed) { + ParserItem itemInt("ITEM2", 123); + + RawRecord rawRecord1( "" ); + const auto defaulted = itemInt.scan(rawRecord1); + + BOOST_CHECK(defaulted.defaultApplied(0)); + BOOST_CHECK_EQUAL(defaulted.get< int >(0), 123); +} + +BOOST_AUTO_TEST_CASE(InitializeIntItem_setDescription_canReadBack) { + ParserItem itemInt("ITEM1"); + std::string description("This is the description"); + itemInt.setDescription(description); + + BOOST_CHECK_EQUAL( description, itemInt.getDescription() ); +} + + +/******************************************************************/ +/* */ +BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_missingName_throws) { + Json::JsonObject jsonConfig("{\"nameX\": \"ITEM1\" , \"size_type\" : \"ALL\"}"); + BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument ); +} + + +BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_defaultSizeType) { + Json::JsonObject jsonConfig("{\"name\": \"ITEM1\", \"value_type\": \"INT\" }"); + ParserItem item1( jsonConfig ); + BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE , item1.sizeType()); +} + + + +BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject) { + Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\", \"value_type\": \"INT\" }"); + ParserItem item1( jsonConfig ); + BOOST_CHECK_EQUAL( "ITEM1" , item1.name() ); + BOOST_CHECK_EQUAL( ParserItem::item_size::ALL, item1.sizeType() ); + BOOST_CHECK(item1.getDefault< int >() < 0); +} + + +BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withDefault) { + Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"SINGLE\", \"default\" : 100, \"value_type\": \"INT\" }"); + ParserItem item1( jsonConfig ); + BOOST_CHECK_EQUAL( 100 , item1.getDefault< int >() ); +} + + +BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withDefaultInvalid_throws) { + Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"SINGLE\", \"default\" : \"100X\"}"); + BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument ); +} + + +BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withSizeTypeALL_throws) { + Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"INT\", \"size_type\" : \"ALL\", \"default\" : 100}"); + BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument ); +} + + + +BOOST_AUTO_TEST_CASE(InitializeIntItem_WithDescription_DescriptionPropertyShouldBePopulated) { + std::string description("Description goes here"); + Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"INT\", \"description\" : \"Description goes here\"}"); + ParserItem item(jsonConfig); + + BOOST_CHECK_EQUAL( "Description goes here", item.getDescription() ); +} + + +BOOST_AUTO_TEST_CASE(InitializeIntItem_WithoutDescription_DescriptionPropertyShouldBeEmpty) { + Json::JsonObject jsonConfig("{\"name\": \"ITEM1\", \"value_type\": \"INT\" }"); + ParserItem item(jsonConfig); + + BOOST_CHECK_EQUAL( "", item.getDescription() ); +} + + + +/* */ +/******************************************************************/ + +/* EQUAL */ + + +BOOST_AUTO_TEST_CASE(IntItem_Equal_ReturnsTrue) { + auto sizeType = ParserItem::item_size::ALL; + ParserItem item1("ITEM1", sizeType); + ParserItem item2("ITEM1", sizeType); + ParserItem item3 = item1; + + BOOST_CHECK_EQUAL( item1, item2 ); + BOOST_CHECK_EQUAL( item1, item3 ); +} + + +BOOST_AUTO_TEST_CASE(IntItem_Different_ReturnsFalse) { + ParserItem item1("ITEM1", ParserItem::item_size::ALL); + ParserItem item2("ITEM2", ParserItem::item_size::ALL); + ParserItem item3("ITEM1"); + ParserItem item4("ITEM1" , 42); + + BOOST_CHECK_NE( item1, item2 ); + BOOST_CHECK_NE( item1, item3 ); + BOOST_CHECK_NE( item2, item3 ); + BOOST_CHECK_NE( item4, item3 ); +} + +BOOST_AUTO_TEST_CASE(DoubleItem_DimEqual_ReturnsTrue) { + auto sizeType = ParserItem::item_size::ALL; + ParserItem item1("ITEM1", sizeType, 0.0); + ParserItem item2("ITEM1", sizeType, 0.0); + + item1.push_backDimension("Length*Length"); + item2.push_backDimension("Length*Length"); + + BOOST_CHECK_EQUAL( item1, item2 ); +} + + +BOOST_AUTO_TEST_CASE(DoubleItem_DimDifferent_ReturnsFalse) { + auto sizeType = ParserItem::item_size::ALL; + ParserItem item1("ITEM1", sizeType, 0.0); // Dim: [] + ParserItem item2("ITEM1", sizeType, 0.0); // Dim: [Length] + ParserItem item3("ITEM1", sizeType, 0.0); // Dim: [Length ,Length] + ParserItem item4("ITEM1", sizeType, 0.0); // Dim: [t] + + item2.push_backDimension("Length"); + item3.push_backDimension("Length"); + item3.push_backDimension("Length"); + item4.push_backDimension("Time"); + + BOOST_CHECK_NE(item1, item2 ); + BOOST_CHECK_NE(item2, item3 ); + BOOST_CHECK_NE(item2, item1 ); + BOOST_CHECK_NE(item2, item4 ); + BOOST_CHECK_NE(item1, item3 ); + BOOST_CHECK_NE(item3, item1 ); + BOOST_CHECK_NE(item4, item2 ); +} + + +BOOST_AUTO_TEST_CASE(DoubleItem_Different_ReturnsFalse) { + ParserItem item1("ITEM1", ParserItem::item_size::ALL, 0.0); + ParserItem item2("ITEM2", ParserItem::item_size::ALL, 0.0); + ParserItem item3("ITEM1", 0.0 ); + ParserItem item4("ITEM1", 42.89); + + BOOST_CHECK_NE( item1, item2 ); + BOOST_CHECK_NE( item1, item3 ); + BOOST_CHECK_NE( item2, item3 ); + BOOST_CHECK_NE( item4, item3 ); +} + + +BOOST_AUTO_TEST_CASE(StringItem_Equal_ReturnsTrue) { + auto sizeType = ParserItem::item_size::ALL; + ParserItem item1("ITEM1", sizeType, ""); + ParserItem item2("ITEM1", sizeType, ""); + ParserItem item3 = item1; + + BOOST_CHECK_EQUAL( item1, item2 ); + BOOST_CHECK_EQUAL( item1, item3 ); +} + + +BOOST_AUTO_TEST_CASE(StringItem_Different_ReturnsFalse) { + ParserItem item1("ITEM1", ParserItem::item_size::ALL, ""); + ParserItem item2("ITEM2", ParserItem::item_size::ALL, ""); + ParserItem item3("ITEM1", "" ); + ParserItem item4("ITEM1", "42.89"); + + BOOST_CHECK_NE( item1, item2 ); + BOOST_CHECK_NE( item1, item3 ); + BOOST_CHECK_NE( item2, item3 ); + BOOST_CHECK_NE( item4, item3 ); +} + + + + +/******************************************************************/ + +BOOST_AUTO_TEST_CASE(Name_ReturnsCorrectName) { + auto sizeType = ParserItem::item_size::ALL; + + ParserItem item1("ITEM1", sizeType); + BOOST_CHECK_EQUAL("ITEM1", item1.name()); + + ParserItem item2("", sizeType); + BOOST_CHECK_EQUAL("", item2.name()); +} + +BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeTypeSingle) { + auto sizeType = ParserItem::item_size::SINGLE; + ParserItem item1("ITEM1", sizeType); + BOOST_CHECK_EQUAL(sizeType, item1.sizeType()); +} + +BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeTypeAll) { + auto sizeType = ParserItem::item_size::ALL; + ParserItem item1("ITEM1", sizeType); + BOOST_CHECK_EQUAL(sizeType, item1.sizeType()); +} + +BOOST_AUTO_TEST_CASE(Scan_All_CorrectIntSetInDeckItem) { + auto sizeType = ParserItem::item_size::ALL; + ParserItem itemInt("ITEM", sizeType, 0); + + RawRecord rawRecord( "100 443 10*77 10*1 25" ); + const auto deckIntItem = itemInt.scan(rawRecord); + BOOST_CHECK_EQUAL(23U, deckIntItem.size()); + BOOST_CHECK_EQUAL(77, deckIntItem.get< int >(3)); + BOOST_CHECK_EQUAL(1, deckIntItem.get< int >(21)); + BOOST_CHECK_EQUAL(25, deckIntItem.get< int >(22)); +} + +BOOST_AUTO_TEST_CASE(Scan_All_WithDefaults) { + auto sizeType = ParserItem::item_size::ALL; + ParserItem itemInt("ITEM", sizeType); + itemInt.setType( int() ); + + RawRecord rawRecord( "100 10* 10*1 25" ); + const auto deckIntItem = itemInt.scan(rawRecord); + BOOST_CHECK_EQUAL(22U, deckIntItem.size()); + BOOST_CHECK(!deckIntItem.defaultApplied(0)); + BOOST_CHECK( deckIntItem.defaultApplied(1)); + BOOST_CHECK(!deckIntItem.defaultApplied(11)); + BOOST_CHECK(!deckIntItem.defaultApplied(21)); + BOOST_CHECK_EQUAL(1, deckIntItem.get< int >(20)); + BOOST_CHECK_EQUAL(25, deckIntItem.get< int >(21)); +} + +BOOST_AUTO_TEST_CASE(Scan_SINGLE_CorrectIntSetInDeckItem) { + ParserItem itemInt(std::string("ITEM2"), 0); + + RawRecord rawRecord("100 44.3 'Heisann'" ); + const auto deckIntItem = itemInt.scan(rawRecord); + BOOST_CHECK_EQUAL(100, deckIntItem.get< int >(0)); +} + +BOOST_AUTO_TEST_CASE(Scan_SeveralInts_CorrectIntsSetInDeckItem) { + ParserItem itemInt1(std::string("ITEM1"), 0); + ParserItem itemInt2(std::string("ITEM2"), 0); + ParserItem itemInt3(std::string("ITEM3"), 0); + + RawRecord rawRecord( "100 443 338932 222.33 'Heisann' " ); + const auto deckIntItem1 = itemInt1.scan(rawRecord); + BOOST_CHECK_EQUAL(100, deckIntItem1.get< int >(0)); + + const auto deckIntItem2 = itemInt2.scan(rawRecord); + BOOST_CHECK_EQUAL(443, deckIntItem2.get< int >(0)); + + const auto deckIntItem3 = itemInt3.scan(rawRecord); + BOOST_CHECK_EQUAL(338932, deckIntItem3.get< int >(0)); +} + + + + + +BOOST_AUTO_TEST_CASE(Scan_Multiplier_CorrectIntsSetInDeckItem) { + auto sizeType = ParserItem::item_size::ALL; + ParserItem itemInt("ITEM2", sizeType, 0); + + RawRecord rawRecord( "3*4 " ); + const auto deckIntItem = itemInt.scan(rawRecord); + BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(0)); + BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(1)); + BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(2)); +} + +BOOST_AUTO_TEST_CASE(Scan_StarNoMultiplier_ExceptionThrown) { + auto sizeType = ParserItem::item_size::SINGLE; + ParserItem itemInt("ITEM2", sizeType , 100); + + RawRecord rawRecord( "*45 " ); + BOOST_CHECK_THROW(itemInt.scan(rawRecord), std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(Scan_MultipleItems_CorrectIntsSetInDeckItem) { + ParserItem itemInt1(std::string("ITEM1"), 0); + ParserItem itemInt2(std::string("ITEM2"), 0); + + RawRecord rawRecord( "10 20" ); + const auto deckIntItem1 = itemInt1.scan(rawRecord); + const auto deckIntItem2 = itemInt2.scan(rawRecord); + + BOOST_CHECK_EQUAL(10, deckIntItem1.get< int >(0)); + BOOST_CHECK_EQUAL(20, deckIntItem2.get< int >(0)); +} + +BOOST_AUTO_TEST_CASE(Scan_MultipleDefault_CorrectIntsSetInDeckItem) { + ParserItem itemInt1("ITEM1", 10); + ParserItem itemInt2("ITEM2", 20); + + RawRecord rawRecord( "* * " ); + const auto deckIntItem1 = itemInt1.scan(rawRecord); + const auto deckIntItem2 = itemInt2.scan(rawRecord); + + BOOST_CHECK_EQUAL(10, deckIntItem1.get< int >(0)); + BOOST_CHECK_EQUAL(20, deckIntItem2.get< int >(0)); +} + +BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplier_CorrectIntsSetInDeckItem) { + ParserItem itemInt1("ITEM1", 10); + ParserItem itemInt2("ITEM2", 20); + + RawRecord rawRecord( "2*30" ); + const auto deckIntItem1 = itemInt1.scan(rawRecord); + const auto deckIntItem2 = itemInt2.scan(rawRecord); + + BOOST_CHECK_EQUAL(30, deckIntItem1.get< int >(0)); + BOOST_CHECK_EQUAL(30, deckIntItem2.get< int >(0)); +} + +BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplier_Throw) { + ParserItem itemInt1("ITEM1" , 10); + + RawRecord rawRecord( "2.10*30" ); + BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplierChar_Throw) { + ParserItem itemInt1("ITEM1", 10); + + RawRecord rawRecord( "210X30" ); + BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplierDefault_CorrectIntsSetInDeckItem) { + ParserItem itemInt1("ITEM1", 10); + ParserItem itemInt2("ITEM2", 20); + + RawRecord rawRecord( "2*" ); + const auto deckIntItem1 = itemInt1.scan(rawRecord); + const auto deckIntItem2 = itemInt2.scan(rawRecord); + + BOOST_CHECK_EQUAL(10, deckIntItem1.get< int >(0)); + BOOST_CHECK_EQUAL(20, deckIntItem2.get< int >(0)); +} + +BOOST_AUTO_TEST_CASE(Scan_RawRecordErrorInRawData_ExceptionThrown) { + ParserItem itemInt(std::string("ITEM2"), 0); + + // Wrong type + RawRecord rawRecord2( "333.2 /" ); + BOOST_CHECK_THROW(itemInt.scan(rawRecord2), std::invalid_argument); + + // Wrong type + RawRecord rawRecord3( "100X /" ); + BOOST_CHECK_THROW(itemInt.scan(rawRecord3), std::invalid_argument); + + // Wrong type + RawRecord rawRecord5( "astring /" ); + BOOST_CHECK_THROW(itemInt.scan(rawRecord5), std::invalid_argument); +} + +/*********************String************************'*/ +/*****************************************************************/ +/**/ + +BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_missingName_throws) { + Json::JsonObject jsonConfig("{\"nameX\": \"ITEM1\" , \"size_type\" : \"ALL\"}"); + BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument ); +} + +BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_withDefault) { + Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"STRING\", \"size_type\" : \"SINGLE\", \"default\" : \"100\"}"); + ParserItem item1( jsonConfig ); + BOOST_CHECK_EQUAL( "100" , item1.getDefault< std::string >() ); +} + +BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_withDefaultInvalid_throws) { + Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\", \"default\" : [1,2,3]}"); + BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument ); +} +/**/ +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(init_defaultvalue_defaultset) { + ParserItem itemString(std::string("ITEM1") , "DEFAULT"); + RawRecord rawRecord( "'1*'" ); + BOOST_CHECK_EQUAL("1*", itemString.scan( rawRecord ).get< std::string >(0) ); + + RawRecord rawRecord1( "13*" ); + BOOST_CHECK_EQUAL("DEFAULT" , itemString.scan( rawRecord1 ).get< std::string >(0) ); + + RawRecord rawRecord2( "*" ); + BOOST_CHECK_EQUAL("DEFAULT", itemString.scan( rawRecord2 ).get< std::string >(0) ); + + ParserItem itemStringDefaultChanged("ITEM2", "SPECIAL"); + RawRecord rawRecord3( "*" ); + BOOST_CHECK_EQUAL("SPECIAL", itemStringDefaultChanged.scan( rawRecord3 ).get< std::string >(0) ); +} + +BOOST_AUTO_TEST_CASE(scan_all_valuesCorrect) { + auto sizeType = ParserItem::item_size::ALL; + ParserItem itemString("ITEMWITHMANY", sizeType, ""); + RawRecord rawRecord( "'WELL1' FISK BANAN 3*X OPPLEGG_FOR_DATAANALYSE 'Foo$*!% BAR' " ); + const auto deckItem = itemString.scan(rawRecord); + BOOST_CHECK_EQUAL(8U, deckItem.size()); + + BOOST_CHECK_EQUAL("WELL1", deckItem.get< std::string >(0)); + BOOST_CHECK_EQUAL("FISK", deckItem.get< std::string >(1)); + BOOST_CHECK_EQUAL("BANAN", deckItem.get< std::string >(2)); + BOOST_CHECK_EQUAL("X", deckItem.get< std::string >(3)); + BOOST_CHECK_EQUAL("X", deckItem.get< std::string >(4)); + BOOST_CHECK_EQUAL("X", deckItem.get< std::string >(5)); + BOOST_CHECK_EQUAL("OPPLEGG_FOR_DATAANALYSE", deckItem.get< std::string >(6)); + BOOST_CHECK_EQUAL("Foo$*!% BAR", deckItem.get< std::string >(7)); +} + +BOOST_AUTO_TEST_CASE(scan_all_withdefaults) { + auto sizeType = ParserItem::item_size::ALL; + ParserItem itemString("ITEMWITHMANY", sizeType, 0); + RawRecord rawRecord( "10*1 10* 10*2 " ); + const auto deckItem = itemString.scan(rawRecord); + + BOOST_CHECK_EQUAL(30U, deckItem.size()); + + BOOST_CHECK( !deckItem.defaultApplied(0) ); + BOOST_CHECK( !deckItem.defaultApplied(9) ); + BOOST_CHECK( deckItem.defaultApplied(10) ); + BOOST_CHECK( deckItem.defaultApplied(19) ); + BOOST_CHECK( !deckItem.defaultApplied(20) ); + BOOST_CHECK( !deckItem.defaultApplied(29) ); + + BOOST_CHECK_THROW(deckItem.get< int >(30), std::out_of_range); + BOOST_CHECK_THROW(deckItem.defaultApplied(30), std::out_of_range); + + BOOST_CHECK_EQUAL(1, deckItem.get< int >(0)); + BOOST_CHECK_EQUAL(1, deckItem.get< int >(9)); + BOOST_CHECK_EQUAL(2, deckItem.get< int >(20)); + BOOST_CHECK_EQUAL(2, deckItem.get< int >(29)); +} + +BOOST_AUTO_TEST_CASE(scan_single_dataCorrect) { + ParserItem itemString( "ITEM1", ""); + RawRecord rawRecord( "'WELL1' 'WELL2'" ); + const auto deckItem = itemString.scan(rawRecord); + BOOST_CHECK_EQUAL(1U, deckItem.size()); + BOOST_CHECK_EQUAL("WELL1", deckItem.get< std::string >(0)); +} + +BOOST_AUTO_TEST_CASE(scan_singleWithMixedRecord_dataCorrect) { + ParserItem itemString("ITEM1", ""); + ParserItem itemInt("ITEM1", ""); + + RawRecord rawRecord( "2 'WELL1' /" ); + itemInt.scan(rawRecord); + const auto deckItem = itemString.scan(rawRecord); + BOOST_CHECK_EQUAL("WELL1", deckItem.get< std::string >(0)); +} + +/******************String and int**********************/ +BOOST_AUTO_TEST_CASE(scan_intsAndStrings_dataCorrect) { + RawRecord rawRecord( "'WELL1' 2 2 2*3" ); + + auto sizeTypeItemBoxed = ParserItem::item_size::ALL; + + ParserItem itemSingleString(std::string("ITEM1"), ""); + const auto deckItemWell1 = itemSingleString.scan(rawRecord); + BOOST_CHECK_EQUAL("WELL1", deckItemWell1.get< std::string >(0)); + + ParserItem itemSomeInts("SOMEINTS", sizeTypeItemBoxed, 0 ); + const auto deckItemInts = itemSomeInts.scan(rawRecord); + BOOST_CHECK_EQUAL(2, deckItemInts.get< int >(0)); + BOOST_CHECK_EQUAL(2, deckItemInts.get< int >(1)); + BOOST_CHECK_EQUAL(3, deckItemInts.get< int >(2)); + BOOST_CHECK_EQUAL(3, deckItemInts.get< int >(3)); +} + +/*****************************************************************/ + + +BOOST_AUTO_TEST_CASE(ParserDefaultHasDimensionReturnsFalse) { + ParserItem intItem(std::string("SOMEINTS"), 0); + ParserItem stringItem(std::string("SOMESTRING"), ""); + ParserItem doubleItem(std::string("SOMEDOUBLE"), 0.0); + + BOOST_CHECK( !intItem.hasDimension() ); + BOOST_CHECK( !stringItem.hasDimension() ); + BOOST_CHECK( !doubleItem.hasDimension() ); +} + +BOOST_AUTO_TEST_CASE(ParserIntItemGetDimensionThrows) { + ParserItem intItem(std::string("SOMEINT")); + + BOOST_CHECK_THROW( intItem.getDimension(0) , std::invalid_argument ); + BOOST_CHECK_THROW( intItem.push_backDimension("Length") , std::invalid_argument ); +} + + + +BOOST_AUTO_TEST_CASE(ParserDoubleItemAddMultipleDimensionToSIngleSizeThrows) { + ParserItem doubleItem(std::string("SOMEDOUBLE"), 0.0); + + doubleItem.push_backDimension("Length*Length"); + BOOST_CHECK_THROW( doubleItem.push_backDimension("Length*Length"), std::invalid_argument); +} + + +BOOST_AUTO_TEST_CASE(ParserDoubleItemWithDimensionHasReturnsCorrect) { + ParserItem doubleItem("SOMEDOUBLE", 0.0); + + BOOST_CHECK( !doubleItem.hasDimension() ); + doubleItem.push_backDimension("Length*Length"); + BOOST_CHECK( doubleItem.hasDimension() ); +} + +BOOST_AUTO_TEST_CASE(ParserDoubleItemGetDimension) { + ParserItem doubleItem( "SOMEDOUBLE" , ParserItem::item_size::ALL, 0.0 ); + + BOOST_CHECK_THROW( doubleItem.getDimension( 10 ) , std::out_of_range ); + BOOST_CHECK_THROW( doubleItem.getDimension( 0 ) , std::out_of_range ); + + doubleItem.push_backDimension("Length"); + doubleItem.push_backDimension("Length*Length"); + doubleItem.push_backDimension("Length*Length*Length"); + + BOOST_CHECK_EQUAL( "Length" , doubleItem.getDimension(0)); + BOOST_CHECK_EQUAL( "Length*Length" , doubleItem.getDimension(1)); + BOOST_CHECK_EQUAL( "Length*Length*Length" , doubleItem.getDimension(2)); + BOOST_CHECK_THROW( doubleItem.getDimension( 3 ) , std::out_of_range ); +} + +const static auto SINGLE = ParserItem::item_size::SINGLE; +const static auto ALL = ParserItem::item_size::ALL; + +BOOST_AUTO_TEST_CASE(DefaultConstructor_NoParams_NoThrow) { + BOOST_CHECK_NO_THROW(ParserRecord record); +} + +BOOST_AUTO_TEST_CASE(Size_NoElements_ReturnsZero) { + ParserRecord record; + BOOST_CHECK_EQUAL(0U, record.size()); +} + +BOOST_AUTO_TEST_CASE(Size_OneItem_Return1) { + ParserItem itemInt("ITEM1", SINGLE ); + ParserRecord record; + record.addItem(itemInt); + BOOST_CHECK_EQUAL(1U, record.size()); +} + +BOOST_AUTO_TEST_CASE(Get_OneItem_Return1) { + ParserItem itemInt("ITEM1", SINGLE); + ParserRecord record; + record.addItem(itemInt); + + BOOST_CHECK_EQUAL(record.get(0), itemInt); +} + +BOOST_AUTO_TEST_CASE(Get_outOfRange_Throw) { + BOOST_CHECK_THROW(ParserRecord{}.get(0), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(Get_KeyNotFound_Throw) { + ParserRecord record; + BOOST_CHECK_THROW(record.get("Hei"), std::out_of_range ); +} + +BOOST_AUTO_TEST_CASE(Get_KeyFound_OK) { + ParserItem itemInt("ITEM1", SINGLE ); + ParserRecord record; + record.addItem(itemInt); + BOOST_CHECK_EQUAL(record.get("ITEM1"), itemInt); +} + +BOOST_AUTO_TEST_CASE(Get_GetByNameAndIndex_OK) { + ParserItem itemInt("ITEM1", SINGLE); + ParserRecord record; + record.addItem(itemInt); + + const auto& itemByName = record.get("ITEM1"); + const auto& itemByIndex = record.get(0); + BOOST_CHECK_EQUAL(itemInt, itemByName); + BOOST_CHECK_EQUAL(itemInt, itemByIndex); +} + +BOOST_AUTO_TEST_CASE(addItem_SameName_Throw) { + ParserItem itemInt1("ITEM1", SINGLE); + ParserItem itemInt2("ITEM1", SINGLE); + ParserRecord record; + record.addItem(itemInt1); + BOOST_CHECK_THROW(record.addItem(itemInt2), std::invalid_argument); +} + +static ParserRecord createSimpleParserRecord() { + ParserItem itemInt1("ITEM1", SINGLE, 0 ); + ParserItem itemInt2("ITEM2", SINGLE, 0 ); + ParserRecord record; + + record.addItem(itemInt1); + record.addItem(itemInt2); + return record; +} + +BOOST_AUTO_TEST_CASE(parse_validRecord_noThrow) { + auto record = createSimpleParserRecord(); + ParseContext parseContext; + RawRecord raw( string_view( "100 443" ) ); + MessageContainer msgContainer; + BOOST_CHECK_NO_THROW(record.parse(parseContext, msgContainer, raw ) ); +} + +BOOST_AUTO_TEST_CASE(parse_validRecord_deckRecordCreated) { + auto record = createSimpleParserRecord(); + RawRecord rawRecord( string_view( "100 443" ) ); + ParseContext parseContext; + MessageContainer msgContainer; + const auto deckRecord = record.parse(parseContext , msgContainer, rawRecord); + BOOST_CHECK_EQUAL(2U, deckRecord.size()); +} + + +// INT INT DOUBLE DOUBLE INT DOUBLE + +static ParserRecord createMixedParserRecord() { + + auto sizeType = SINGLE; + ParserItem itemInt1( "INTITEM1", sizeType, 0 ); + ParserItem itemInt2( "INTITEM2", sizeType, 0 ); + ParserItem itemInt3( "INTITEM3", sizeType, 0 ); + ParserItem itemDouble1( "DOUBLEITEM1", sizeType, 0.0 ); + ParserItem itemDouble2( "DOUBLEITEM2", sizeType, 0.0 ); + ParserItem itemDouble3( "DOUBLEITEM3", sizeType, 0.0 ); + + ParserRecord record; + record.addItem(itemInt1); + record.addItem(itemInt2); + record.addItem(itemDouble1); + record.addItem(itemDouble2); + record.addItem(itemInt3); + record.addItem(itemDouble3); + + return record; +} + +BOOST_AUTO_TEST_CASE(parse_validMixedRecord_noThrow) { + auto record = createMixedParserRecord(); + RawRecord rawRecord( string_view( "1 2 10.0 20.0 4 90.0") ); + ParseContext parseContext; + MessageContainer msgContainer; + BOOST_CHECK_NO_THROW(record.parse(parseContext , msgContainer, rawRecord)); +} + +BOOST_AUTO_TEST_CASE(Equal_Equal_ReturnsTrue) { + auto record1 = createMixedParserRecord(); + auto record2 = createMixedParserRecord(); + + BOOST_CHECK(record1.equal(record1)); + BOOST_CHECK(record1.equal(record2)); +} + +BOOST_AUTO_TEST_CASE(Equal_Different_ReturnsFalse) { + auto sizeType = SINGLE; + ParserItem itemInt( "INTITEM1", sizeType, 0 ); + ParserItem itemDouble( "DOUBLEITEM1", sizeType, 0.0 ); + ParserItem itemString( "STRINGITEM1", sizeType, "" ); + ParserRecord record1; + ParserRecord record2; + ParserRecord record3; + + record1.addItem(itemInt); + record1.addItem(itemDouble); + + record2.addItem(itemInt); + record2.addItem(itemDouble); + record2.addItem(itemString); + + record3.addItem(itemDouble); + record3.addItem(itemInt); + BOOST_CHECK(!record1.equal(record2)); + BOOST_CHECK(!record1.equal(record3)); + +} + +BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) { + ParserRecord parserRecord; + ParserItem itemInt("ITEM1", SINGLE , 100 ); + ParserItem itemString("ITEM2", SINGLE , "DEFAULT" ); + ParserItem itemDouble("ITEM3", SINGLE , 3.14 ); + + parserRecord.addItem(itemInt); + parserRecord.addItem(itemString); + parserRecord.addItem(itemDouble); + + // according to the RM, this is invalid ("an asterisk by itself is not sufficient"), + // but it seems to appear in the wild. Thus, we interpret this as "1*"... + { + RawRecord rawRecord( "* " ); + const auto& deckStringItem = itemString.scan(rawRecord); + const auto& deckIntItem = itemInt.scan(rawRecord); + const auto& deckDoubleItem = itemDouble.scan(rawRecord); + + BOOST_CHECK(deckStringItem.size() == 1); + BOOST_CHECK(deckIntItem.size() == 1); + BOOST_CHECK(deckDoubleItem.size() == 1); + + BOOST_CHECK(deckStringItem.defaultApplied(0)); + BOOST_CHECK(deckIntItem.defaultApplied(0)); + BOOST_CHECK(deckDoubleItem.defaultApplied(0)); + } + + { + RawRecord rawRecord( "" ); + const auto deckStringItem = itemString.scan(rawRecord); + const auto deckIntItem = itemInt.scan(rawRecord); + const auto deckDoubleItem = itemDouble.scan(rawRecord); + + BOOST_CHECK_EQUAL(deckStringItem.size(), 1); + BOOST_CHECK_EQUAL(deckIntItem.size(), 1); + BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1); + + BOOST_CHECK(deckStringItem.defaultApplied(0)); + BOOST_CHECK(deckIntItem.defaultApplied(0)); + BOOST_CHECK(deckDoubleItem.defaultApplied(0)); + } + + + { + RawRecord rawRecord( "TRYGVE 10 2.9 " ); + + // let the raw record be "consumed" by the items. Note that the scan() method + // modifies the rawRecord object! + const auto& deckStringItem = itemString.scan(rawRecord); + const auto& deckIntItem = itemInt.scan(rawRecord); + const auto& deckDoubleItem = itemDouble.scan(rawRecord); + + BOOST_CHECK_EQUAL(deckStringItem.size(), 1); + BOOST_CHECK_EQUAL(deckIntItem.size(), 1); + BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1); + + BOOST_CHECK(!deckStringItem.defaultApplied(0)); + BOOST_CHECK(!deckIntItem.defaultApplied(0)); + BOOST_CHECK(!deckDoubleItem.defaultApplied(0)); + } + + // again this is invalid according to the RM, but it is used anyway in the wild... + { + RawRecord rawRecord( "* * *" ); + const auto deckStringItem = itemString.scan(rawRecord); + const auto deckIntItem = itemInt.scan(rawRecord); + const auto deckDoubleItem = itemDouble.scan(rawRecord); + + BOOST_CHECK_EQUAL(deckStringItem.size(), 1); + BOOST_CHECK_EQUAL(deckIntItem.size(), 1); + BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1); + + BOOST_CHECK(deckStringItem.defaultApplied(0)); + BOOST_CHECK(deckIntItem.defaultApplied(0)); + BOOST_CHECK(deckDoubleItem.defaultApplied(0)); + } + + { + RawRecord rawRecord( "3*" ); + const auto deckStringItem = itemString.scan(rawRecord); + const auto deckIntItem = itemInt.scan(rawRecord); + const auto deckDoubleItem = itemDouble.scan(rawRecord); + + BOOST_CHECK_EQUAL(deckStringItem.size(), 1); + BOOST_CHECK_EQUAL(deckIntItem.size(), 1); + BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1); + + BOOST_CHECK(deckStringItem.defaultApplied(0)); + BOOST_CHECK(deckIntItem.defaultApplied(0)); + BOOST_CHECK(deckDoubleItem.defaultApplied(0)); + } +} + +BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) { + ParserRecord parserRecord; + ParserItem itemI( "I", SINGLE, 0 ); + ParserItem itemJ( "J", SINGLE, 0 ); + ParserItem itemK( "K", SINGLE, 0 ); + ParseContext parseContext; + + parserRecord.addItem(itemI); + parserRecord.addItem(itemJ); + parserRecord.addItem(itemK); + + + RawRecord rawRecord( "3 3 3 " ); + MessageContainer msgContainer; + + BOOST_CHECK_NO_THROW(parserRecord.parse(parseContext , msgContainer, rawRecord)); + + RawRecord rawRecordOneExtra( "3 3 3 4 " ); + BOOST_CHECK_THROW(parserRecord.parse(parseContext , msgContainer, rawRecordOneExtra), std::invalid_argument); + + RawRecord rawRecordForgotRecordTerminator( "3 3 3 \n 4 4 4 " ); + BOOST_CHECK_THROW(parserRecord.parse(parseContext , msgContainer, rawRecordForgotRecordTerminator), std::invalid_argument); + +} + + +BOOST_AUTO_TEST_CASE(Parse_RawRecordTooFewItems) { + ParserRecord parserRecord; + ParserItem itemI( "I", SINGLE ); + ParserItem itemJ( "J", SINGLE ); + ParserItem itemK( "K", SINGLE ); + itemI.setType( int() ); + itemJ.setType( int() ); + itemK.setType( int() ); + + parserRecord.addItem(itemI); + parserRecord.addItem(itemJ); + parserRecord.addItem(itemK); + + ParseContext parseContext; + RawRecord rawRecord( "3 3 " ); + // no default specified for the third item, record can be parsed just fine but trying + // to access the data will raise an exception... + MessageContainer msgContainer; + BOOST_CHECK_NO_THROW(parserRecord.parse(parseContext , msgContainer, rawRecord)); + auto record = parserRecord.parse(parseContext , msgContainer, rawRecord); + BOOST_CHECK_NO_THROW(record.getItem(2)); + BOOST_CHECK_THROW(record.getItem(2).get< int >(0), std::out_of_range); +} + + + +BOOST_AUTO_TEST_CASE(ParseRecordHasDimensionCorrect) { + ParserRecord parserRecord; + ParserItem itemI( "I", SINGLE, 0.0 ); + + BOOST_CHECK( !parserRecord.hasDimension() ); + + parserRecord.addItem( itemI ); + BOOST_CHECK( !parserRecord.hasDimension() ); + + ParserItem item2( "ID", SINGLE, 0.0 ); + item2.push_backDimension("Length*Length/Time"); + parserRecord.addItem( item2 ); + BOOST_CHECK( parserRecord.hasDimension() ); +} + + +BOOST_AUTO_TEST_CASE(DefaultNotDataRecord) { + ParserRecord record; + BOOST_CHECK_EQUAL( false , record.isDataRecord() ); +} + +BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws1) { + ParserRecord record; + ParserItem dataItem( "ACTNUM" , ALL ); + ParserItem item ( "XXX" , ALL ); + record.addDataItem( dataItem ); + BOOST_CHECK_THROW( record.addItem( item ) , std::invalid_argument); + BOOST_CHECK_THROW( record.addItem( dataItem ) , std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws2) { + ParserRecord record; + ParserItem dataItem( "ACTNUM" , ALL); + ParserItem item ( "XXX" , ALL); + + record.addItem( item ); + BOOST_CHECK_THROW( record.addDataItem( dataItem ) , std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(construct_withname_nameSet) { + const auto& parserKeyword = createDynamicSized("BPR"); + BOOST_CHECK_EQUAL(parserKeyword->getName(), "BPR"); +} + +BOOST_AUTO_TEST_CASE(NamedInit) { + std::string keyword("KEYWORD"); + const auto& parserKeyword = createFixedSized(keyword, (size_t) 100); + BOOST_CHECK_EQUAL(parserKeyword->getName(), keyword); +} + +BOOST_AUTO_TEST_CASE(ParserKeyword_default_SizeTypedefault) { + std::string keyword("KEYWORD"); + const auto& parserKeyword = createDynamicSized(keyword); + BOOST_CHECK_EQUAL(parserKeyword->getSizeType() , SLASH_TERMINATED); +} + + +BOOST_AUTO_TEST_CASE(ParserKeyword_withSize_SizeTypeFIXED) { + std::string keyword("KEYWORD"); + const auto& parserKeyword = createFixedSized(keyword, (size_t) 100); + BOOST_CHECK_EQUAL(parserKeyword->getSizeType() , FIXED); +} + +BOOST_AUTO_TEST_CASE(ParserKeyword_withOtherSize_SizeTypeOTHER) { + std::string keyword("KEYWORD"); + const auto& parserKeyword = createTable(keyword, "EQUILDIMS" , "NTEQUIL" , false); + const std::pair& sizeKW = parserKeyword->getSizeDefinitionPair(); + BOOST_CHECK_EQUAL(OTHER_KEYWORD_IN_DECK , parserKeyword->getSizeType() ); + BOOST_CHECK_EQUAL("EQUILDIMS", sizeKW.first ); + BOOST_CHECK_EQUAL("NTEQUIL" , sizeKW.second ); +} + +BOOST_AUTO_TEST_CASE(ParserKeyword_validDeckName) { + BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("SUMMARY")); + BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("MixeCase")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("NAMETOOLONG")); + BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("STRING88")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("88STRING")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("KEY.EXT")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("STRING~")); + BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("MINUS-")); + BOOST_CHECK_EQUAL( true , ParserKeyword::validDeckName("PLUS+")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("SHARP#")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("-MINUS")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("+PLUS")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("#SHARP")); + + BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("TVDP*")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validDeckName("*")); +} + +BOOST_AUTO_TEST_CASE(ParserKeyword_validInternalName) { + BOOST_CHECK_EQUAL( true , ParserKeyword::validInternalName("SUMMARY")); + BOOST_CHECK_EQUAL( true , ParserKeyword::validInternalName("MixeCase")); + BOOST_CHECK_EQUAL( true , ParserKeyword::validInternalName("NAMEISQUITELONG")); + BOOST_CHECK_EQUAL( true , ParserKeyword::validInternalName("I_have_underscores")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("WHATABOUT+")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("ORMINUS-")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("NOSHARP#")); + BOOST_CHECK_EQUAL( true , ParserKeyword::validInternalName("STRING88")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("88STRING")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("KEY.EXT")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("STRING~")); + + BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("TVDP*")); + BOOST_CHECK_EQUAL( false , ParserKeyword::validInternalName("*")); +} + +BOOST_AUTO_TEST_CASE(ParserKeywordMatches) { + const auto& parserKeyword = createFixedSized("HELLO", (size_t) 1); + parserKeyword->clearDeckNames(); + parserKeyword->setMatchRegex("WORLD.+"); + BOOST_CHECK_EQUAL( false , parserKeyword->matches("HELLO")); + BOOST_CHECK_EQUAL( false , parserKeyword->matches("WORLD")); + BOOST_CHECK_EQUAL( true , parserKeyword->matches("WORLDABC")); + BOOST_CHECK_EQUAL( false , parserKeyword->matches("WORLD#BC")); + BOOST_CHECK_EQUAL( false , parserKeyword->matches("WORLDIAMTOOLONG")); +} + +BOOST_AUTO_TEST_CASE(AddDataKeyword_correctlyConfigured) { + const auto& parserKeyword = createFixedSized("PORO", (size_t) 1); + ParserItem item( "ACTNUM" , ParserItem::item_size::ALL, 0 ); + ParserRecord record; + + BOOST_CHECK( !parserKeyword->isDataKeyword() ); + record.addDataItem( item ); + parserKeyword->addRecord( record ); + BOOST_CHECK( parserKeyword->isDataKeyword() ); + + BOOST_CHECK( parserKeyword->hasFixedSize() ); + BOOST_CHECK_EQUAL(1U , parserKeyword->getFixedSize() ); +} + +BOOST_AUTO_TEST_CASE(WrongConstructor_addDataItem_throws) { + const auto& parserKeyword = createDynamicSized("PORO"); + ParserItem dataItem( "ACTNUM" , ParserItem::item_size::ALL ); + ParserRecord record; + record.addDataItem( dataItem ); + BOOST_CHECK_THROW( parserKeyword->addDataRecord( record ) , std::invalid_argument); +} + + +BOOST_AUTO_TEST_CASE(DefaultConstructur_setDescription_canReadBack) { + const auto& parserKeyword = createDynamicSized("BPR"); + std::string description("This is the description"); + parserKeyword->setDescription(description); + BOOST_CHECK_EQUAL( description, parserKeyword->getDescription()); +} + +/*****************************************************************/ +/* json */ +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject) { + Json::JsonObject jsonObject("{\"name\": \"XXX\", \"sections\":[], \"size\" : 0}"); + const auto& parserKeyword = std::make_shared(jsonObject); + BOOST_CHECK_EQUAL("XXX" , parserKeyword->getName()); + BOOST_CHECK_EQUAL( true , parserKeyword->hasFixedSize() ); +} + +BOOST_AUTO_TEST_CASE(ConstructMultiNameFromJsonObject) { + const auto jsonString = + "{" + " \"name\": \"XXX\" ," + " \"sections\":[]," + " \"size\" : 0," + " \"deck_names\" : [" + " \"XXA\"," + " \"XXB\"," + " \"XXC\"" + " ]" + "}"; + Json::JsonObject jsonObject(jsonString); + auto parserKeyword = std::make_shared(jsonObject); + BOOST_CHECK_EQUAL("XXX" , parserKeyword->getName()); + BOOST_CHECK(parserKeyword->matches("XXA")); + BOOST_CHECK(parserKeyword->matches("XXB")); + BOOST_CHECK(parserKeyword->hasMultipleDeckNames()); + BOOST_CHECK(!parserKeyword->matches("XXD")); + BOOST_CHECK(!parserKeyword->matches("XXX")); +} + + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withSize) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"DOUBLE\"}]}"); + + const auto& parserKeyword = std::make_shared(jsonObject); + BOOST_CHECK_EQUAL("BPR" , parserKeyword->getName()); + BOOST_CHECK_EQUAL( true , parserKeyword->hasFixedSize() ); + BOOST_CHECK_EQUAL( 100U , parserKeyword->getFixedSize() ); + +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_nosize_notItems_OK) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"]}"); + const auto& parserKeyword = std::make_shared(jsonObject); + BOOST_CHECK_EQUAL( true , parserKeyword->hasFixedSize() ); + BOOST_CHECK_EQUAL( 0U , parserKeyword->getFixedSize()); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withSizeOther) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : {\"keyword\" : \"Bjarne\" , \"item\": \"BjarneIgjen\"}, \"items\" :[{\"name\":\"ItemX\" , \"value_type\" : \"DOUBLE\"}]}"); + const auto& parserKeyword = std::make_shared(jsonObject); + const std::pair& sizeKW = parserKeyword->getSizeDefinitionPair(); + BOOST_CHECK_EQUAL("BPR" , parserKeyword->getName()); + BOOST_CHECK_EQUAL( false , parserKeyword->hasFixedSize() ); + BOOST_CHECK_EQUAL(OTHER_KEYWORD_IN_DECK , parserKeyword->getSizeType()); + BOOST_CHECK_EQUAL("Bjarne", sizeKW.first ); + BOOST_CHECK_EQUAL("BjarneIgjen" , sizeKW.second ); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_missingName_throws) { + Json::JsonObject jsonObject("{\"nameXX\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100}"); + BOOST_CHECK_THROW(std::make_shared(jsonObject) , std::invalid_argument); +} + +/* + "items": [{"name" : "I" , "size_type" : "SINGLE" , "value_type" : "int"}] +*/ +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_invalidItems_throws) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : 100}"); + BOOST_CHECK_THROW(std::make_shared(jsonObject) , std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_ItemMissingName_throws) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"nameX\" : \"I\" , \"value_type\" : \"INT\"}]}"); + BOOST_CHECK_THROW(std::make_shared(jsonObject) , std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_ItemMissingValueType_throws) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"SINGLE\" , \"Xvalue_type\" : \"INT\"}]}"); + BOOST_CHECK_THROW(std::make_shared(jsonObject) , std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_ItemInvalidEnum_throws) { + Json::JsonObject jsonObject1("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"XSINGLE\" , \"value_type\" : \"INT\"}]}"); + Json::JsonObject jsonObject2("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"SINGLE\" , \"value_type\" : \"INTX\"}]}"); + + BOOST_CHECK_THROW(std::make_shared(jsonObject1) , std::invalid_argument); + BOOST_CHECK_THROW(std::make_shared(jsonObject2) , std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObjectItemsOK) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"name\" : \"I\", \"value_type\" : \"INT\"}]}"); + const auto& parserKeyword = std::make_shared(jsonObject); + const auto& record = parserKeyword->getRecord(0); + const auto& item = record.get( 0 ); + BOOST_CHECK_EQUAL( 1U , record.size( ) ); + BOOST_CHECK_EQUAL( "I" , item.name( ) ); + BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE , item.sizeType()); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_sizeFromOther) { + Json::JsonObject jsonConfig("{\"name\": \"EQUILX\", \"sections\":[\"PROPS\"], \"size\" : {\"keyword\":\"EQLDIMS\" , \"item\" : \"NTEQUL\"}, \"items\" :[{\"name\":\"ItemX\" ,\"value_type\" : \"DOUBLE\"}]}"); + BOOST_CHECK_NO_THROW( std::make_shared(jsonConfig) ); +} + +BOOST_AUTO_TEST_CASE(Default_NotData) { + auto parserKeyword = createDynamicSized("BPR"); + BOOST_CHECK_EQUAL( false , parserKeyword->isDataKeyword()); +} + + +BOOST_AUTO_TEST_CASE(AddDataKeywordFromJson_defaultThrows) { + Json::JsonObject jsonConfig("{\"name\": \"ACTNUM\", \"sections\":[\"GRID\"], \"data\" : {\"value_type\": \"INT\" , \"default\" : 100}}"); + BOOST_CHECK_THROW( std::make_shared(jsonConfig) , std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(AddDataKeywordFromJson_correctlyConfigured) { + Json::JsonObject jsonConfig("{\"name\": \"ACTNUM\", \"sections\":[\"GRID\"], \"data\" : {\"value_type\": \"INT\"}}"); + const auto& parserKeyword = std::make_shared(jsonConfig); + const auto& parserRecord = parserKeyword->getRecord(0); + const auto& item = parserRecord.get(0); + + + BOOST_CHECK( parserKeyword->isDataKeyword() ); + BOOST_CHECK( parserKeyword->hasFixedSize( ) ); + BOOST_CHECK_EQUAL(1U , parserKeyword->getFixedSize() ); + + BOOST_CHECK_EQUAL( item.name() , ParserKeywords::ACTNUM::data::itemName ); + BOOST_CHECK_EQUAL( ParserItem::item_size::ALL, item.sizeType() ); +} + +BOOST_AUTO_TEST_CASE(AddkeywordFromJson_numTables_incoorect_throw) { + Json::JsonObject jsonConfig("{\"name\": \"PVTG\", \"sections\":[\"PROPS\"], \"num_tables\" : 100}"); + BOOST_CHECK_THROW(std::make_shared(jsonConfig) , std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(AddkeywordFromJson_isTableCollection) { + Json::JsonObject jsonConfig("{\"name\": \"PVTG\", \"sections\":[\"PROPS\"], \"num_tables\" : {\"keyword\": \"TABDIMS\" , \"item\" : \"NTPVT\"} , \"items\" : [{\"name\" : \"data\", \"value_type\" : \"DOUBLE\"}]}"); + const auto& parserKeyword = std::make_shared(jsonConfig); + + BOOST_CHECK_EQUAL( true , parserKeyword->isTableCollection() ); + BOOST_CHECK_EQUAL( false , parserKeyword->isDataKeyword()); + BOOST_CHECK_EQUAL( false , parserKeyword->hasFixedSize( )); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_InvalidSize_throws) { + Json::JsonObject jsonObject1("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : \"string\" , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"SINGLE\" , \"value_type\" : \"INT\"}]}"); + Json::JsonObject jsonObject2("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : [1,2,3] , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"SINGLE\" , \"value_type\" : \"INT\"}]}"); + + BOOST_CHECK_THROW(std::make_shared(jsonObject1) , std::invalid_argument); + BOOST_CHECK_THROW(std::make_shared(jsonObject2) , std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_SizeUNKNOWN_OK) { + Json::JsonObject jsonObject1("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : \"UNKNOWN\" , \"items\" : [{\"name\" : \"I\" , \"size_type\" : \"SINGLE\" , \"value_type\" : \"INT\"}]}"); + auto parserKeyword = std::make_shared(jsonObject1); + + BOOST_CHECK_EQUAL( UNKNOWN , parserKeyword->getSizeType() ); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_WithDescription_DescriptionPropertyShouldBePopulated) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"description\" : \"Description\"}"); + auto parserKeyword = std::make_shared(jsonObject); + + BOOST_CHECK_EQUAL( "Description", parserKeyword->getDescription() ); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_WithoutDescription_DescriptionPropertyShouldBeEmpty) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"]}"); + auto parserKeyword = std::make_shared(jsonObject); + + BOOST_CHECK_EQUAL( "", parserKeyword->getDescription() ); +} + +/* */ +/*****************************************************************/ +BOOST_AUTO_TEST_CASE(getFixedSize_sizeObjectHasFixedSize_sizeReturned) { + const auto& parserKeyword = createFixedSized("JA", (size_t) 3); + BOOST_CHECK_EQUAL(3U, parserKeyword->getFixedSize()); + +} + +BOOST_AUTO_TEST_CASE(getFixedSize_sizeObjectDoesNotHaveFixedSizeObjectSet_ExceptionThrown) { + const auto& parserKeyword = createDynamicSized("JA"); + BOOST_CHECK_THROW(parserKeyword->getFixedSize(), std::logic_error); +} + +BOOST_AUTO_TEST_CASE(hasFixedSize_hasFixedSizeObject_returnstrue) { + const auto& parserKeyword = createFixedSized("JA", (size_t) 2); + BOOST_CHECK(parserKeyword->hasFixedSize()); +} + +BOOST_AUTO_TEST_CASE(hasFixedSize_sizeObjectDoesNotHaveFixedSize_returnsfalse) { + const auto& parserKeyword = createDynamicSized("JA"); + BOOST_CHECK(!parserKeyword->hasFixedSize()); +} + +/******/ +/* Tables: */ +BOOST_AUTO_TEST_CASE(DefaultIsNot_TableKeyword) { + const auto& parserKeyword = createDynamicSized("JA"); + BOOST_CHECK(!parserKeyword->isTableCollection()); +} + +BOOST_AUTO_TEST_CASE(ConstructorIsTableCollection) { + const auto& parserKeyword = createTable("JA" , "TABDIMS" , "NTPVT" , true); + const std::pair& sizeKW = parserKeyword->getSizeDefinitionPair(); + BOOST_CHECK(parserKeyword->isTableCollection()); + BOOST_CHECK(!parserKeyword->hasFixedSize()); + + BOOST_CHECK_EQUAL( parserKeyword->getSizeType() , OTHER_KEYWORD_IN_DECK); + BOOST_CHECK_EQUAL("TABDIMS", sizeKW.first ); + BOOST_CHECK_EQUAL("NTPVT" , sizeKW.second ); +} + +BOOST_AUTO_TEST_CASE(ParseEmptyRecord) { + const auto& tabdimsKeyword = createFixedSized("TEST" , 1); + ParserRecord record; + ParserItem item("ITEM", ParserItem::item_size::ALL ); + item.setType( int() ); + auto rawkeyword = std::make_shared< RawKeyword >( tabdimsKeyword->getName() , "FILE" , 10U , 1 ); + ParseContext parseContext; + MessageContainer msgContainer; + + BOOST_CHECK_EQUAL( Raw::FIXED , rawkeyword->getSizeType()); + rawkeyword->addRawRecordString("/"); + record.addItem(item); + tabdimsKeyword->addRecord( record ); + + const auto deckKeyword = tabdimsKeyword->parse( parseContext , msgContainer, rawkeyword ); + BOOST_REQUIRE_EQUAL( 1U , deckKeyword.size()); + + const auto& deckRecord = deckKeyword.getRecord(0); + BOOST_REQUIRE_EQUAL( 1U , deckRecord.size()); + + BOOST_CHECK_EQUAL(0U , deckRecord.getItem( 0 ).size()); +} + + + +/*****************************************************************/ +/* Dimension */ +BOOST_AUTO_TEST_CASE(ParseKeywordHasDimensionCorrect) { + const auto& parserKeyword = createDynamicSized("JA"); + ParserItem item1("I", ParserItem::item_size::SINGLE, 0 ); + ParserItem item2("ID", ParserItem::item_size::SINGLE, 0.0 ); + ParserRecord record; + + BOOST_CHECK( !parserKeyword->hasDimension()); + + record.addItem( item1 ); + parserKeyword->addRecord( record ); + BOOST_CHECK( !parserKeyword->hasDimension() ); + BOOST_CHECK_EQUAL( 0U , item1.numDimensions() ); + + item2.push_backDimension("Length*Length/Time"); + record.addItem( item2 ); + const auto& parserKeyword2 = createDynamicSized("JA"); + parserKeyword2->addRecord( record ); + BOOST_CHECK( parserKeyword2->hasDimension() ); + BOOST_CHECK_EQUAL( 1U , item2.numDimensions() ); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withDimension) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"DOUBLE\" , \"dimension\" : \"Length*Length/Time\"}]}"); + const auto& parserKeyword = std::make_shared(jsonObject); + const auto& record = parserKeyword->getRecord(0); + const auto& item = record.get("ItemX"); + + BOOST_CHECK_EQUAL("BPR" , parserKeyword->getName()); + BOOST_CHECK( parserKeyword->hasFixedSize() ); + BOOST_CHECK_EQUAL( 100U , parserKeyword->getFixedSize() ); + + BOOST_CHECK( parserKeyword->hasDimension() ); + BOOST_CHECK( item.hasDimension() ); + BOOST_CHECK_EQUAL( 1U , item.numDimensions() ); +} + +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withDimensionList) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"ALL\" , \"value_type\" : \"DOUBLE\" , \"dimension\" : [\"Length*Length/Time\" , \"Time\", \"1\"]}]}"); + const auto& parserKeyword = std::make_shared(jsonObject); + const auto& record = parserKeyword->getRecord(0); + const auto& item = record.get("ItemX"); + + BOOST_CHECK_EQUAL("BPR" , parserKeyword->getName()); + BOOST_CHECK_EQUAL( true , parserKeyword->hasFixedSize() ); + BOOST_CHECK_EQUAL( 100U , parserKeyword->getFixedSize() ); + + BOOST_CHECK( parserKeyword->hasDimension() ); + BOOST_CHECK( item.hasDimension() ); + BOOST_CHECK_EQUAL( 3U , item.numDimensions() ); +} + + + + + +BOOST_AUTO_TEST_CASE(ConstructFromJson_withRecords) { + const std::string json_string1 = "{\"name\" : \"MULTFLT\", \"sections\" : [\"GRID\", \"EDIT\", \"SCHEDULE\"], \"records\" : [[" + "{\"name\" : \"fault\" , \"value_type\" : \"STRING\"}," + "{\"name\" : \"factor\" , \"value_type\" : \"DOUBLE\"}]]}"; + + const std::string json_string2 = "{\"name\" : \"MULTFLT\", \"sections\" : [\"GRID\", \"EDIT\", \"SCHEDULE\"], \"items\" : [" + "{\"name\" : \"fault\" , \"value_type\" : \"STRING\"}," + "{\"name\" : \"factor\" , \"value_type\" : \"DOUBLE\"}]}"; + + + Json::JsonObject jsonObject1( json_string1 ); + Json::JsonObject jsonObject2( json_string2 ); + auto kw1 = std::make_shared( jsonObject1 ); + auto kw2 = std::make_shared( jsonObject2 ); + + BOOST_CHECK_EQUAL( *kw1, *kw2 ); + +} + +BOOST_AUTO_TEST_CASE(ConstructFromJson_withRecords_and_items_throws) { + const std::string json_string = "{\"name\" : \"MULTFLT\", \"sections\" : [\"GRID\", \"EDIT\", \"SCHEDULE\"], \"records\" : [[" + "{\"name\" : \"fault\" , \"value_type\" : \"STRING\"}," + "{\"name\" : \"factor\" , \"value_type\" : \"DOUBLE\"}]],\"items\" : [" + "{\"name\" : \"fault\" , \"value_type\" : \"STRING\"}," + "{\"name\" : \"factor\" , \"value_type\" : \"DOUBLE\"}]}"; + Json::JsonObject jsonObject( json_string ); + BOOST_CHECK_THROW( std::make_shared( jsonObject ) , std::invalid_argument); +} + + +BOOST_AUTO_TEST_CASE(Create1Arg) { + ParserKeyword kw("GRID"); + BOOST_CHECK_EQUAL( false , kw.hasDimension() ); + BOOST_CHECK( kw.hasFixedSize() ); + BOOST_CHECK_EQUAL( kw.getFixedSize( ) , 0 ); + + BOOST_CHECK_THROW( kw.getRecord( 0 ) , std::invalid_argument ); +} + +BOOST_AUTO_TEST_CASE(TestKeywordSizeEnum2String) { + BOOST_CHECK_EQUAL( "SLASH_TERMINATED" , ParserKeywordSizeEnum2String(SLASH_TERMINATED)); + BOOST_CHECK_EQUAL( "FIXED" , ParserKeywordSizeEnum2String(FIXED)); + BOOST_CHECK_EQUAL( "OTHER_KEYWORD_IN_DECK" , ParserKeywordSizeEnum2String(OTHER_KEYWORD_IN_DECK)); + BOOST_CHECK_EQUAL( "UNKNOWN" , ParserKeywordSizeEnum2String(UNKNOWN)); +} + + +BOOST_AUTO_TEST_CASE(TestKeywordSizeEnumFromString) { + BOOST_CHECK_THROW( ParserKeywordSizeEnumFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL( FIXED , ParserKeywordSizeEnumFromString("FIXED")); + BOOST_CHECK_EQUAL( SLASH_TERMINATED , ParserKeywordSizeEnumFromString("SLASH_TERMINATED")); + BOOST_CHECK_EQUAL( "OTHER_KEYWORD_IN_DECK" , ParserKeywordSizeEnum2String(OTHER_KEYWORD_IN_DECK)); + BOOST_CHECK_EQUAL( "UNKNOWN" , ParserKeywordSizeEnum2String(UNKNOWN)); +} + + + +BOOST_AUTO_TEST_CASE(TestKeywordSizeEnumLoop) { + BOOST_CHECK_EQUAL( FIXED , ParserKeywordSizeEnumFromString( ParserKeywordSizeEnum2String( FIXED ) )); + BOOST_CHECK_EQUAL( SLASH_TERMINATED , ParserKeywordSizeEnumFromString( ParserKeywordSizeEnum2String( SLASH_TERMINATED ) )); + BOOST_CHECK_EQUAL( OTHER_KEYWORD_IN_DECK , ParserKeywordSizeEnumFromString( ParserKeywordSizeEnum2String( OTHER_KEYWORD_IN_DECK ) )); + BOOST_CHECK_EQUAL( UNKNOWN , ParserKeywordSizeEnumFromString( ParserKeywordSizeEnum2String( UNKNOWN ) )); + + BOOST_CHECK_EQUAL( "FIXED" , ParserKeywordSizeEnum2String(ParserKeywordSizeEnumFromString( "FIXED" ) )); + BOOST_CHECK_EQUAL( "SLASH_TERMINATED" , ParserKeywordSizeEnum2String(ParserKeywordSizeEnumFromString( "SLASH_TERMINATED" ) )); + BOOST_CHECK_EQUAL( "OTHER_KEYWORD_IN_DECK" , ParserKeywordSizeEnum2String(ParserKeywordSizeEnumFromString( "OTHER_KEYWORD_IN_DECK" ) )); + BOOST_CHECK_EQUAL( "UNKNOWN" , ParserKeywordSizeEnum2String(ParserKeywordSizeEnumFromString( "UNKNOWN" ) )); +} + + +/*****************************************************************/ + + +BOOST_AUTO_TEST_CASE(TestValueTypeEnum2String) { + BOOST_CHECK_EQUAL( "INT" , ParserValueTypeEnum2String(INT)); + BOOST_CHECK_EQUAL( "FLOAT" , ParserValueTypeEnum2String(FLOAT)); + BOOST_CHECK_EQUAL( "STRING" , ParserValueTypeEnum2String(STRING)); +} + + +BOOST_AUTO_TEST_CASE(TestValueTypeEnumFromString) { + BOOST_CHECK_THROW( ParserValueTypeEnumFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL( INT , ParserValueTypeEnumFromString("INT")); + BOOST_CHECK_EQUAL( STRING , ParserValueTypeEnumFromString("STRING")); + BOOST_CHECK_EQUAL( FLOAT , ParserValueTypeEnumFromString("FLOAT")); +} + + + +BOOST_AUTO_TEST_CASE(TestValueTypeEnumLoop) { + BOOST_CHECK_EQUAL( INT , ParserValueTypeEnumFromString( ParserValueTypeEnum2String( INT ) )); + BOOST_CHECK_EQUAL( FLOAT , ParserValueTypeEnumFromString( ParserValueTypeEnum2String( FLOAT ) )); + BOOST_CHECK_EQUAL( STRING , ParserValueTypeEnumFromString( ParserValueTypeEnum2String( STRING ) )); + + BOOST_CHECK_EQUAL( "INT" , ParserValueTypeEnum2String(ParserValueTypeEnumFromString( "INT" ) )); + BOOST_CHECK_EQUAL( "FLOAT" , ParserValueTypeEnum2String(ParserValueTypeEnumFromString( "FLOAT" ) )); + BOOST_CHECK_EQUAL( "STRING" , ParserValueTypeEnum2String(ParserValueTypeEnumFromString( "STRING" ) )); +} + + +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(TestKeywordActionEnum2String) { + BOOST_CHECK_EQUAL( "INTERNALIZE" , ParserKeywordActionEnum2String(INTERNALIZE)); + BOOST_CHECK_EQUAL( "IGNORE" , ParserKeywordActionEnum2String(IGNORE)); + BOOST_CHECK_EQUAL( "IGNORE_WARNING" , ParserKeywordActionEnum2String(IGNORE_WARNING)); + BOOST_CHECK_EQUAL( "THROW_EXCEPTION" , ParserKeywordActionEnum2String(THROW_EXCEPTION)); +} + + +BOOST_AUTO_TEST_CASE(TestKeywordActionEnumFromString) { + BOOST_CHECK_THROW( ParserKeywordActionEnumFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL( INTERNALIZE , ParserKeywordActionEnumFromString("INTERNALIZE")); + BOOST_CHECK_EQUAL( IGNORE_WARNING , ParserKeywordActionEnumFromString("IGNORE_WARNING")); + BOOST_CHECK_EQUAL( IGNORE , ParserKeywordActionEnumFromString("IGNORE")); + BOOST_CHECK_EQUAL( THROW_EXCEPTION , ParserKeywordActionEnumFromString("THROW_EXCEPTION")); +} + + + +BOOST_AUTO_TEST_CASE(TestKeywordActionEnumLoop) { + BOOST_CHECK_EQUAL( INTERNALIZE , ParserKeywordActionEnumFromString( ParserKeywordActionEnum2String( INTERNALIZE ) )); + BOOST_CHECK_EQUAL( IGNORE , ParserKeywordActionEnumFromString( ParserKeywordActionEnum2String( IGNORE ) )); + BOOST_CHECK_EQUAL( IGNORE_WARNING , ParserKeywordActionEnumFromString( ParserKeywordActionEnum2String( IGNORE_WARNING ) )); + BOOST_CHECK_EQUAL( THROW_EXCEPTION , ParserKeywordActionEnumFromString( ParserKeywordActionEnum2String( THROW_EXCEPTION ) )); + + BOOST_CHECK_EQUAL( "INTERNALIZE" , ParserKeywordActionEnum2String(ParserKeywordActionEnumFromString( "INTERNALIZE" ) )); + BOOST_CHECK_EQUAL( "IGNORE" , ParserKeywordActionEnum2String(ParserKeywordActionEnumFromString( "IGNORE" ) )); + BOOST_CHECK_EQUAL( "IGNORE_WARNING" , ParserKeywordActionEnum2String(ParserKeywordActionEnumFromString( "IGNORE_WARNING" ) )); + BOOST_CHECK_EQUAL( "THROW_EXCEPTION" , ParserKeywordActionEnum2String(ParserKeywordActionEnumFromString( "THROW_EXCEPTION" ) )); +} diff --git a/tests/parser/RawKeywordTests.cpp b/tests/parser/RawKeywordTests.cpp index 5e9fc76c0..44dcffaea 100644 --- a/tests/parser/RawKeywordTests.cpp +++ b/tests/parser/RawKeywordTests.cpp @@ -191,3 +191,75 @@ BOOST_AUTO_TEST_CASE(isUnknownSize) { BOOST_CHECK_EQUAL( Raw::UNKNOWN , keyword.getSizeType( )); } +BOOST_AUTO_TEST_CASE(RawRecordGetRecordsCorrectElementsReturned) { + Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 "); + + BOOST_CHECK_EQUAL((unsigned) 4, record.size()); + + BOOST_CHECK_EQUAL("'NODIR '", record.getItem(0)); + BOOST_CHECK_EQUAL("'REVERS'", record.getItem(1)); + BOOST_CHECK_EQUAL("1", record.getItem(2)); + BOOST_CHECK_EQUAL("20", record.getItem(3)); +} + +BOOST_AUTO_TEST_CASE(RawRecordIsCompleteRecordCompleteRecordReturnsTrue) { + bool isComplete = Opm::RawRecord::isTerminatedRecordString("'NODIR ' 'REVERS' 1 20 /"); + BOOST_CHECK_EQUAL(true, isComplete); +} + +BOOST_AUTO_TEST_CASE(RawRecordIsCompleteRecordInCompleteRecordReturnsFalse) { + bool isComplete = Opm::RawRecord::isTerminatedRecordString("'NODIR ' 'REVERS' 1 20 "); + BOOST_CHECK_EQUAL(false, isComplete); +} + +BOOST_AUTO_TEST_CASE(Rawrecord_OperatorThis_OK) { + Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 "); + + BOOST_CHECK_EQUAL("'NODIR '", record.getItem(0)); + BOOST_CHECK_EQUAL("'REVERS'", record.getItem(1)); + BOOST_CHECK_EQUAL("1", record.getItem(2)); + BOOST_CHECK_EQUAL("20", record.getItem(3)); + BOOST_CHECK_THROW(record.getItem(4), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(Rawrecord_PushFront_OK) { + Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 "); + record.prepend( 1, "String2" ); + record.prepend( 1, "String1" ); + + BOOST_CHECK_EQUAL("String1", record.getItem(0)); + BOOST_CHECK_EQUAL("String2", record.getItem(1)); +} + +BOOST_AUTO_TEST_CASE(Rawrecord_size_OK) { + Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 "); + + BOOST_CHECK_EQUAL(4U, record.size()); + record.prepend( 1, "String2"); + record.prepend( 1, "String1"); + BOOST_CHECK_EQUAL(6U, record.size()); +} + +BOOST_AUTO_TEST_CASE(Rawrecord_sizeEmpty_OK) { + Opm::RawRecord record(""); + BOOST_CHECK_EQUAL(0U, record.size()); +} + +BOOST_AUTO_TEST_CASE(Rawrecord_spaceOnlyEmpty_OK) { + Opm::RawRecord record(" "); + BOOST_CHECK_EQUAL(0U, record.size()); +} + +BOOST_AUTO_TEST_CASE(Rawrecord_noFileAndKeywordGiven_EmptyStringUsed) { + Opm::RawRecord record("32 33 "); + BOOST_CHECK_EQUAL("", record.getKeywordName()); + BOOST_CHECK_EQUAL("", record.getFileName()); +} + +BOOST_AUTO_TEST_CASE(Rawrecord_FileAndKeywordGiven_CorrectStringsReturned) { + const std::string fileName = "/this/is/it"; + const std::string keywordName = "KEYWD"; + Opm::RawRecord record("32 33 ", fileName, keywordName); + BOOST_CHECK_EQUAL(keywordName, record.getKeywordName()); + BOOST_CHECK_EQUAL(fileName, record.getFileName()); +} diff --git a/tests/parser/RawRecordTests.cpp b/tests/parser/RawRecordTests.cpp deleted file mode 100644 index 732588bb4..000000000 --- a/tests/parser/RawRecordTests.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - Copyright 2013 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 . - */ - -#define BOOST_TEST_MODULE ParserTests -#include -#include -#include - - -BOOST_AUTO_TEST_CASE(RawRecordGetRecordsCorrectElementsReturned) { - Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 "); - - BOOST_CHECK_EQUAL((unsigned) 4, record.size()); - - BOOST_CHECK_EQUAL("'NODIR '", record.getItem(0)); - BOOST_CHECK_EQUAL("'REVERS'", record.getItem(1)); - BOOST_CHECK_EQUAL("1", record.getItem(2)); - BOOST_CHECK_EQUAL("20", record.getItem(3)); -} - -BOOST_AUTO_TEST_CASE(RawRecordIsCompleteRecordCompleteRecordReturnsTrue) { - bool isComplete = Opm::RawRecord::isTerminatedRecordString("'NODIR ' 'REVERS' 1 20 /"); - BOOST_CHECK_EQUAL(true, isComplete); -} - -BOOST_AUTO_TEST_CASE(RawRecordIsCompleteRecordInCompleteRecordReturnsFalse) { - bool isComplete = Opm::RawRecord::isTerminatedRecordString("'NODIR ' 'REVERS' 1 20 "); - BOOST_CHECK_EQUAL(false, isComplete); -} - -BOOST_AUTO_TEST_CASE(Rawrecord_OperatorThis_OK) { - Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 "); - - BOOST_CHECK_EQUAL("'NODIR '", record.getItem(0)); - BOOST_CHECK_EQUAL("'REVERS'", record.getItem(1)); - BOOST_CHECK_EQUAL("1", record.getItem(2)); - BOOST_CHECK_EQUAL("20", record.getItem(3)); - BOOST_CHECK_THROW(record.getItem(4), std::out_of_range); -} - -BOOST_AUTO_TEST_CASE(Rawrecord_PushFront_OK) { - Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 "); - record.prepend( 1, "String2" ); - record.prepend( 1, "String1" ); - - BOOST_CHECK_EQUAL("String1", record.getItem(0)); - BOOST_CHECK_EQUAL("String2", record.getItem(1)); -} - -BOOST_AUTO_TEST_CASE(Rawrecord_size_OK) { - Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 "); - - BOOST_CHECK_EQUAL(4U, record.size()); - record.prepend( 1, "String2"); - record.prepend( 1, "String1"); - BOOST_CHECK_EQUAL(6U, record.size()); -} - -BOOST_AUTO_TEST_CASE(Rawrecord_sizeEmpty_OK) { - Opm::RawRecord record(""); - BOOST_CHECK_EQUAL(0U, record.size()); -} - -BOOST_AUTO_TEST_CASE(Rawrecord_spaceOnlyEmpty_OK) { - Opm::RawRecord record(" "); - BOOST_CHECK_EQUAL(0U, record.size()); -} - -BOOST_AUTO_TEST_CASE(Rawrecord_noFileAndKeywordGiven_EmptyStringUsed) { - Opm::RawRecord record("32 33 "); - BOOST_CHECK_EQUAL("", record.getKeywordName()); - BOOST_CHECK_EQUAL("", record.getFileName()); -} - -BOOST_AUTO_TEST_CASE(Rawrecord_FileAndKeywordGiven_CorrectStringsReturned) { - const std::string fileName = "/this/is/it"; - const std::string keywordName = "KEYWD"; - Opm::RawRecord record("32 33 ", fileName, keywordName); - BOOST_CHECK_EQUAL(keywordName, record.getKeywordName()); - BOOST_CHECK_EQUAL(fileName, record.getFileName()); -} diff --git a/tests/parser/ScheduleEnumTests.cpp b/tests/parser/ScheduleEnumTests.cpp deleted file mode 100644 index a02598f47..000000000 --- a/tests/parser/ScheduleEnumTests.cpp +++ /dev/null @@ -1,433 +0,0 @@ -/* - Copyright 2013 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 . - */ - - -#define BOOST_TEST_MODULE ParserEnumTests -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(TestCompletionStateEnum2String) { - BOOST_CHECK_EQUAL( "AUTO" , WellCompletion::StateEnum2String(WellCompletion::AUTO)); - BOOST_CHECK_EQUAL( "OPEN" , WellCompletion::StateEnum2String(WellCompletion::OPEN)); - BOOST_CHECK_EQUAL( "SHUT" , WellCompletion::StateEnum2String(WellCompletion::SHUT)); -} - - -BOOST_AUTO_TEST_CASE(TestCompletionStateEnumFromString) { - BOOST_CHECK_THROW( WellCompletion::StateEnumFromString("XXX") , std::invalid_argument ); - BOOST_CHECK_EQUAL( WellCompletion::AUTO , WellCompletion::StateEnumFromString("AUTO")); - BOOST_CHECK_EQUAL( WellCompletion::SHUT , WellCompletion::StateEnumFromString("SHUT")); - BOOST_CHECK_EQUAL( WellCompletion::SHUT , WellCompletion::StateEnumFromString("STOP")); - BOOST_CHECK_EQUAL( WellCompletion::OPEN , WellCompletion::StateEnumFromString("OPEN")); -} - - - -BOOST_AUTO_TEST_CASE(TestCompletionStateEnumLoop) { - BOOST_CHECK_EQUAL( WellCompletion::AUTO , WellCompletion::StateEnumFromString( WellCompletion::StateEnum2String( WellCompletion::AUTO ) )); - BOOST_CHECK_EQUAL( WellCompletion::SHUT , WellCompletion::StateEnumFromString( WellCompletion::StateEnum2String( WellCompletion::SHUT ) )); - BOOST_CHECK_EQUAL( WellCompletion::OPEN , WellCompletion::StateEnumFromString( WellCompletion::StateEnum2String( WellCompletion::OPEN ) )); - - BOOST_CHECK_EQUAL( "AUTO" , WellCompletion::StateEnum2String(WellCompletion::StateEnumFromString( "AUTO" ) )); - BOOST_CHECK_EQUAL( "OPEN" , WellCompletion::StateEnum2String(WellCompletion::StateEnumFromString( "OPEN" ) )); - BOOST_CHECK_EQUAL( "SHUT" , WellCompletion::StateEnum2String(WellCompletion::StateEnumFromString( "SHUT" ) )); -} - - -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(TestCompletionDirectionEnum2String) -{ - using namespace WellCompletion; - - BOOST_CHECK_EQUAL("X", DirectionEnum2String(DirectionEnum::X)); - BOOST_CHECK_EQUAL("Y", DirectionEnum2String(DirectionEnum::Y)); - BOOST_CHECK_EQUAL("Z", DirectionEnum2String(DirectionEnum::Z)); -} - -BOOST_AUTO_TEST_CASE(TestCompletionDirectionEnumFromString) -{ - using namespace WellCompletion; - - BOOST_CHECK_THROW(DirectionEnumFromString("XXX"), std::invalid_argument); - - BOOST_CHECK_EQUAL(DirectionEnum::X, DirectionEnumFromString("X")); - BOOST_CHECK_EQUAL(DirectionEnum::Y, DirectionEnumFromString("Y")); - BOOST_CHECK_EQUAL(DirectionEnum::Z, DirectionEnumFromString("Z")); -} - -BOOST_AUTO_TEST_CASE(TestCompletionDirectionEnumLoop) -{ - using namespace WellCompletion; - - BOOST_CHECK_EQUAL(DirectionEnum::X, DirectionEnumFromString(DirectionEnum2String(DirectionEnum::X))); - BOOST_CHECK_EQUAL(DirectionEnum::Y, DirectionEnumFromString(DirectionEnum2String(DirectionEnum::Y))); - BOOST_CHECK_EQUAL(DirectionEnum::Z, DirectionEnumFromString(DirectionEnum2String(DirectionEnum::Z))); - - BOOST_CHECK_EQUAL("X", DirectionEnum2String(DirectionEnumFromString("X"))); - BOOST_CHECK_EQUAL("Y", DirectionEnum2String(DirectionEnumFromString("Y"))); - BOOST_CHECK_EQUAL("Z", DirectionEnum2String(DirectionEnumFromString("Z"))); -} - -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(TestGroupInjectionControlEnum2String) { - BOOST_CHECK_EQUAL( "NONE" , GroupInjection::ControlEnum2String(GroupInjection::NONE)); - BOOST_CHECK_EQUAL( "RATE" , GroupInjection::ControlEnum2String(GroupInjection::RATE)); - BOOST_CHECK_EQUAL( "RESV" , GroupInjection::ControlEnum2String(GroupInjection::RESV)); - BOOST_CHECK_EQUAL( "REIN" , GroupInjection::ControlEnum2String(GroupInjection::REIN)); - BOOST_CHECK_EQUAL( "VREP" , GroupInjection::ControlEnum2String(GroupInjection::VREP)); - BOOST_CHECK_EQUAL( "FLD" , GroupInjection::ControlEnum2String(GroupInjection::FLD)); -} - - -BOOST_AUTO_TEST_CASE(TestGroupInjectionControlEnumFromString) { - BOOST_CHECK_THROW( GroupInjection::ControlEnumFromString("XXX") , std::invalid_argument ); - BOOST_CHECK_EQUAL( GroupInjection::NONE , GroupInjection::ControlEnumFromString("NONE")); - BOOST_CHECK_EQUAL( GroupInjection::RATE , GroupInjection::ControlEnumFromString("RATE")); - BOOST_CHECK_EQUAL( GroupInjection::RESV , GroupInjection::ControlEnumFromString("RESV")); - BOOST_CHECK_EQUAL( GroupInjection::REIN , GroupInjection::ControlEnumFromString("REIN")); - BOOST_CHECK_EQUAL( GroupInjection::VREP , GroupInjection::ControlEnumFromString("VREP")); - BOOST_CHECK_EQUAL( GroupInjection::FLD , GroupInjection::ControlEnumFromString("FLD")); -} - - - -BOOST_AUTO_TEST_CASE(TestGroupInjectionControlEnumLoop) { - BOOST_CHECK_EQUAL( GroupInjection::NONE , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::NONE ) )); - BOOST_CHECK_EQUAL( GroupInjection::RATE , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::RATE ) )); - BOOST_CHECK_EQUAL( GroupInjection::RESV , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::RESV ) )); - BOOST_CHECK_EQUAL( GroupInjection::REIN , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::REIN ) )); - BOOST_CHECK_EQUAL( GroupInjection::VREP , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::VREP ) )); - BOOST_CHECK_EQUAL( GroupInjection::FLD , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::FLD ) )); - - BOOST_CHECK_EQUAL( "NONE" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "NONE" ) )); - BOOST_CHECK_EQUAL( "RATE" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "RATE" ) )); - BOOST_CHECK_EQUAL( "RESV" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "RESV" ) )); - BOOST_CHECK_EQUAL( "REIN" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "REIN" ) )); - BOOST_CHECK_EQUAL( "VREP" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "VREP" ) )); - BOOST_CHECK_EQUAL( "FLD" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "FLD" ) )); -} - -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(TestGroupProductionControlEnum2String) { - BOOST_CHECK_EQUAL( "NONE" , GroupProduction::ControlEnum2String(GroupProduction::NONE)); - BOOST_CHECK_EQUAL( "ORAT" , GroupProduction::ControlEnum2String(GroupProduction::ORAT)); - BOOST_CHECK_EQUAL( "WRAT" , GroupProduction::ControlEnum2String(GroupProduction::WRAT)); - BOOST_CHECK_EQUAL( "GRAT" , GroupProduction::ControlEnum2String(GroupProduction::GRAT)); - BOOST_CHECK_EQUAL( "LRAT" , GroupProduction::ControlEnum2String(GroupProduction::LRAT)); - BOOST_CHECK_EQUAL( "CRAT" , GroupProduction::ControlEnum2String(GroupProduction::CRAT)); - BOOST_CHECK_EQUAL( "RESV" , GroupProduction::ControlEnum2String(GroupProduction::RESV)); - BOOST_CHECK_EQUAL( "PRBL" , GroupProduction::ControlEnum2String(GroupProduction::PRBL)); -} - - -BOOST_AUTO_TEST_CASE(TestGroupProductionControlEnumFromString) { - BOOST_CHECK_THROW( GroupProduction::ControlEnumFromString("XXX") , std::invalid_argument ); - BOOST_CHECK_EQUAL(GroupProduction::NONE , GroupProduction::ControlEnumFromString("NONE")); - BOOST_CHECK_EQUAL(GroupProduction::ORAT , GroupProduction::ControlEnumFromString("ORAT")); - BOOST_CHECK_EQUAL(GroupProduction::WRAT , GroupProduction::ControlEnumFromString("WRAT")); - BOOST_CHECK_EQUAL(GroupProduction::GRAT , GroupProduction::ControlEnumFromString("GRAT")); - BOOST_CHECK_EQUAL(GroupProduction::LRAT , GroupProduction::ControlEnumFromString("LRAT")); - BOOST_CHECK_EQUAL(GroupProduction::CRAT , GroupProduction::ControlEnumFromString("CRAT")); - BOOST_CHECK_EQUAL(GroupProduction::RESV , GroupProduction::ControlEnumFromString("RESV")); - BOOST_CHECK_EQUAL(GroupProduction::PRBL , GroupProduction::ControlEnumFromString("PRBL")); -} - - - -BOOST_AUTO_TEST_CASE(TestGroupProductionControlEnumLoop) { - BOOST_CHECK_EQUAL( GroupProduction::NONE, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::NONE ) )); - BOOST_CHECK_EQUAL( GroupProduction::ORAT, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::ORAT ) )); - BOOST_CHECK_EQUAL( GroupProduction::WRAT, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::WRAT ) )); - BOOST_CHECK_EQUAL( GroupProduction::GRAT, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::GRAT ) )); - BOOST_CHECK_EQUAL( GroupProduction::LRAT, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::LRAT ) )); - BOOST_CHECK_EQUAL( GroupProduction::CRAT, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::CRAT ) )); - BOOST_CHECK_EQUAL( GroupProduction::RESV, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::RESV ) )); - BOOST_CHECK_EQUAL( GroupProduction::PRBL, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::PRBL ) )); - - BOOST_CHECK_EQUAL( "NONE" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "NONE" ) )); - BOOST_CHECK_EQUAL( "ORAT" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "ORAT" ) )); - BOOST_CHECK_EQUAL( "WRAT" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "WRAT" ) )); - BOOST_CHECK_EQUAL( "GRAT" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "GRAT" ) )); - BOOST_CHECK_EQUAL( "LRAT" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "LRAT" ) )); - BOOST_CHECK_EQUAL( "CRAT" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "CRAT" ) )); - BOOST_CHECK_EQUAL( "RESV" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "RESV" ) )); - BOOST_CHECK_EQUAL( "PRBL" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "PRBL" ) )); -} - -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(TestGroupProductionExceedLimitControlEnum2String) { - BOOST_CHECK_EQUAL( "NONE" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::NONE)); - BOOST_CHECK_EQUAL( "CON" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::CON)); - BOOST_CHECK_EQUAL( "+CON" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::CON_PLUS)); - BOOST_CHECK_EQUAL( "WELL" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::WELL)); - BOOST_CHECK_EQUAL( "PLUG" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::PLUG)); - BOOST_CHECK_EQUAL( "RATE" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::RATE)); -} - - -BOOST_AUTO_TEST_CASE(TestGroupProductionExceedLimitActionEnumFromString) { - BOOST_CHECK_THROW( GroupProductionExceedLimit::ActionEnumFromString("XXX") , std::invalid_argument ); - - BOOST_CHECK_EQUAL(GroupProductionExceedLimit::NONE , GroupProductionExceedLimit::ActionEnumFromString("NONE")); - BOOST_CHECK_EQUAL(GroupProductionExceedLimit::CON , GroupProductionExceedLimit::ActionEnumFromString("CON" )); - BOOST_CHECK_EQUAL(GroupProductionExceedLimit::CON_PLUS , GroupProductionExceedLimit::ActionEnumFromString("+CON")); - BOOST_CHECK_EQUAL(GroupProductionExceedLimit::WELL , GroupProductionExceedLimit::ActionEnumFromString("WELL")); - BOOST_CHECK_EQUAL(GroupProductionExceedLimit::PLUG , GroupProductionExceedLimit::ActionEnumFromString("PLUG")); - BOOST_CHECK_EQUAL(GroupProductionExceedLimit::RATE , GroupProductionExceedLimit::ActionEnumFromString("RATE")); -} - - - -BOOST_AUTO_TEST_CASE(TestGroupProductionExceedLimitActionEnumLoop) { - BOOST_CHECK_EQUAL( GroupProductionExceedLimit::NONE , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::NONE ) )); - BOOST_CHECK_EQUAL( GroupProductionExceedLimit::CON , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::CON ) )); - BOOST_CHECK_EQUAL( GroupProductionExceedLimit::CON_PLUS , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::CON_PLUS ) )); - BOOST_CHECK_EQUAL( GroupProductionExceedLimit::WELL , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::WELL ) )); - BOOST_CHECK_EQUAL( GroupProductionExceedLimit::PLUG , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::PLUG ) )); - BOOST_CHECK_EQUAL( GroupProductionExceedLimit::RATE , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::RATE ) )); - - BOOST_CHECK_EQUAL("NONE" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "NONE" ) )); - BOOST_CHECK_EQUAL("CON" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "CON" ) )); - BOOST_CHECK_EQUAL("+CON" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "+CON" ) )); - BOOST_CHECK_EQUAL("WELL" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "WELL" ) )); - BOOST_CHECK_EQUAL("PLUG" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "PLUG" ) )); - BOOST_CHECK_EQUAL("RATE" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "RATE" ) )); -} - -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(TestInjectorEnum2String) { - BOOST_CHECK_EQUAL( "OIL" , WellInjector::Type2String(WellInjector::OIL)); - BOOST_CHECK_EQUAL( "GAS" , WellInjector::Type2String(WellInjector::GAS)); - BOOST_CHECK_EQUAL( "WATER" , WellInjector::Type2String(WellInjector::WATER)); - BOOST_CHECK_EQUAL( "MULTI" , WellInjector::Type2String(WellInjector::MULTI)); -} - - -BOOST_AUTO_TEST_CASE(TestInjectorEnumFromString) { - BOOST_CHECK_THROW( WellInjector::TypeFromString("XXX") , std::invalid_argument ); - BOOST_CHECK_EQUAL( WellInjector::OIL , WellInjector::TypeFromString("OIL")); - BOOST_CHECK_EQUAL( WellInjector::WATER , WellInjector::TypeFromString("WATER")); - BOOST_CHECK_EQUAL( WellInjector::WATER , WellInjector::TypeFromString("WAT")); - BOOST_CHECK_EQUAL( WellInjector::GAS , WellInjector::TypeFromString("GAS")); - BOOST_CHECK_EQUAL( WellInjector::MULTI , WellInjector::TypeFromString("MULTI")); -} - - - -BOOST_AUTO_TEST_CASE(TestInjectorEnumLoop) { - BOOST_CHECK_EQUAL( WellInjector::OIL , WellInjector::TypeFromString( WellInjector::Type2String( WellInjector::OIL ) )); - BOOST_CHECK_EQUAL( WellInjector::WATER , WellInjector::TypeFromString( WellInjector::Type2String( WellInjector::WATER ) )); - BOOST_CHECK_EQUAL( WellInjector::GAS , WellInjector::TypeFromString( WellInjector::Type2String( WellInjector::GAS ) )); - BOOST_CHECK_EQUAL( WellInjector::MULTI , WellInjector::TypeFromString( WellInjector::Type2String( WellInjector::MULTI ) )); - - BOOST_CHECK_EQUAL( "MULTI" , WellInjector::Type2String(WellInjector::TypeFromString( "MULTI" ) )); - BOOST_CHECK_EQUAL( "OIL" , WellInjector::Type2String(WellInjector::TypeFromString( "OIL" ) )); - BOOST_CHECK_EQUAL( "GAS" , WellInjector::Type2String(WellInjector::TypeFromString( "GAS" ) )); - BOOST_CHECK_EQUAL( "WATER" , WellInjector::Type2String(WellInjector::TypeFromString( "WATER" ) )); -} - -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(InjectorCOntrolMopdeEnum2String) { - BOOST_CHECK_EQUAL( "RATE" , WellInjector::ControlMode2String(WellInjector::RATE)); - BOOST_CHECK_EQUAL( "RESV" , WellInjector::ControlMode2String(WellInjector::RESV)); - BOOST_CHECK_EQUAL( "BHP" , WellInjector::ControlMode2String(WellInjector::BHP)); - BOOST_CHECK_EQUAL( "THP" , WellInjector::ControlMode2String(WellInjector::THP)); - BOOST_CHECK_EQUAL( "GRUP" , WellInjector::ControlMode2String(WellInjector::GRUP)); -} - - -BOOST_AUTO_TEST_CASE(InjectorControlModeEnumFromString) { - BOOST_CHECK_THROW( WellInjector::ControlModeFromString("XXX") , std::invalid_argument ); - BOOST_CHECK_EQUAL( WellInjector::RATE , WellInjector::ControlModeFromString("RATE")); - BOOST_CHECK_EQUAL( WellInjector::BHP , WellInjector::ControlModeFromString("BHP")); - BOOST_CHECK_EQUAL( WellInjector::RESV , WellInjector::ControlModeFromString("RESV")); - BOOST_CHECK_EQUAL( WellInjector::THP , WellInjector::ControlModeFromString("THP")); - BOOST_CHECK_EQUAL( WellInjector::GRUP , WellInjector::ControlModeFromString("GRUP")); -} - - - -BOOST_AUTO_TEST_CASE(InjectorControlModeEnumLoop) { - BOOST_CHECK_EQUAL( WellInjector::RATE , WellInjector::ControlModeFromString( WellInjector::ControlMode2String( WellInjector::RATE ) )); - BOOST_CHECK_EQUAL( WellInjector::BHP , WellInjector::ControlModeFromString( WellInjector::ControlMode2String( WellInjector::BHP ) )); - BOOST_CHECK_EQUAL( WellInjector::RESV , WellInjector::ControlModeFromString( WellInjector::ControlMode2String( WellInjector::RESV ) )); - BOOST_CHECK_EQUAL( WellInjector::THP , WellInjector::ControlModeFromString( WellInjector::ControlMode2String( WellInjector::THP ) )); - BOOST_CHECK_EQUAL( WellInjector::GRUP , WellInjector::ControlModeFromString( WellInjector::ControlMode2String( WellInjector::GRUP ) )); - - BOOST_CHECK_EQUAL( "THP" , WellInjector::ControlMode2String(WellInjector::ControlModeFromString( "THP" ) )); - BOOST_CHECK_EQUAL( "RATE" , WellInjector::ControlMode2String(WellInjector::ControlModeFromString( "RATE" ) )); - BOOST_CHECK_EQUAL( "RESV" , WellInjector::ControlMode2String(WellInjector::ControlModeFromString( "RESV" ) )); - BOOST_CHECK_EQUAL( "BHP" , WellInjector::ControlMode2String(WellInjector::ControlModeFromString( "BHP" ) )); - BOOST_CHECK_EQUAL( "GRUP" , WellInjector::ControlMode2String(WellInjector::ControlModeFromString( "GRUP" ) )); -} - - - -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(InjectorStatusEnum2String) { - BOOST_CHECK_EQUAL( "OPEN" , WellCommon::Status2String(WellCommon::OPEN)); - BOOST_CHECK_EQUAL( "SHUT" , WellCommon::Status2String(WellCommon::SHUT)); - BOOST_CHECK_EQUAL( "AUTO" , WellCommon::Status2String(WellCommon::AUTO)); - BOOST_CHECK_EQUAL( "STOP" , WellCommon::Status2String(WellCommon::STOP)); -} - - -BOOST_AUTO_TEST_CASE(InjectorStatusEnumFromString) { - BOOST_CHECK_THROW( WellCommon::StatusFromString("XXX") , std::invalid_argument ); - BOOST_CHECK_EQUAL( WellCommon::OPEN , WellCommon::StatusFromString("OPEN")); - BOOST_CHECK_EQUAL( WellCommon::AUTO , WellCommon::StatusFromString("AUTO")); - BOOST_CHECK_EQUAL( WellCommon::SHUT , WellCommon::StatusFromString("SHUT")); - BOOST_CHECK_EQUAL( WellCommon::STOP , WellCommon::StatusFromString("STOP")); -} - - - -BOOST_AUTO_TEST_CASE(InjectorStatusEnumLoop) { - BOOST_CHECK_EQUAL( WellCommon::OPEN , WellCommon::StatusFromString( WellCommon::Status2String( WellCommon::OPEN ) )); - BOOST_CHECK_EQUAL( WellCommon::AUTO , WellCommon::StatusFromString( WellCommon::Status2String( WellCommon::AUTO ) )); - BOOST_CHECK_EQUAL( WellCommon::SHUT , WellCommon::StatusFromString( WellCommon::Status2String( WellCommon::SHUT ) )); - BOOST_CHECK_EQUAL( WellCommon::STOP , WellCommon::StatusFromString( WellCommon::Status2String( WellCommon::STOP ) )); - - BOOST_CHECK_EQUAL( "STOP" , WellCommon::Status2String(WellCommon::StatusFromString( "STOP" ) )); - BOOST_CHECK_EQUAL( "OPEN" , WellCommon::Status2String(WellCommon::StatusFromString( "OPEN" ) )); - BOOST_CHECK_EQUAL( "SHUT" , WellCommon::Status2String(WellCommon::StatusFromString( "SHUT" ) )); - BOOST_CHECK_EQUAL( "AUTO" , WellCommon::Status2String(WellCommon::StatusFromString( "AUTO" ) )); -} - - - -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(ProducerCOntrolMopdeEnum2String) { - BOOST_CHECK_EQUAL( "ORAT" , WellProducer::ControlMode2String(WellProducer::ORAT)); - BOOST_CHECK_EQUAL( "WRAT" , WellProducer::ControlMode2String(WellProducer::WRAT)); - BOOST_CHECK_EQUAL( "GRAT" , WellProducer::ControlMode2String(WellProducer::GRAT)); - BOOST_CHECK_EQUAL( "LRAT" , WellProducer::ControlMode2String(WellProducer::LRAT)); - BOOST_CHECK_EQUAL( "CRAT" , WellProducer::ControlMode2String(WellProducer::CRAT)); - BOOST_CHECK_EQUAL( "RESV" , WellProducer::ControlMode2String(WellProducer::RESV)); - BOOST_CHECK_EQUAL( "BHP" , WellProducer::ControlMode2String(WellProducer::BHP)); - BOOST_CHECK_EQUAL( "THP" , WellProducer::ControlMode2String(WellProducer::THP)); - BOOST_CHECK_EQUAL( "GRUP" , WellProducer::ControlMode2String(WellProducer::GRUP)); -} - - -BOOST_AUTO_TEST_CASE(ProducerControlModeEnumFromString) { - BOOST_CHECK_THROW( WellProducer::ControlModeFromString("XRAT") , std::invalid_argument ); - BOOST_CHECK_EQUAL( WellProducer::ORAT , WellProducer::ControlModeFromString("ORAT")); - BOOST_CHECK_EQUAL( WellProducer::WRAT , WellProducer::ControlModeFromString("WRAT")); - BOOST_CHECK_EQUAL( WellProducer::GRAT , WellProducer::ControlModeFromString("GRAT")); - BOOST_CHECK_EQUAL( WellProducer::LRAT , WellProducer::ControlModeFromString("LRAT")); - BOOST_CHECK_EQUAL( WellProducer::CRAT , WellProducer::ControlModeFromString("CRAT")); - BOOST_CHECK_EQUAL( WellProducer::RESV , WellProducer::ControlModeFromString("RESV")); - BOOST_CHECK_EQUAL( WellProducer::BHP , WellProducer::ControlModeFromString("BHP" )); - BOOST_CHECK_EQUAL( WellProducer::THP , WellProducer::ControlModeFromString("THP" )); - BOOST_CHECK_EQUAL( WellProducer::GRUP , WellProducer::ControlModeFromString("GRUP")); -} - - - -BOOST_AUTO_TEST_CASE(ProducerControlModeEnumLoop) { - BOOST_CHECK_EQUAL( WellProducer::ORAT , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::ORAT ) )); - BOOST_CHECK_EQUAL( WellProducer::WRAT , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::WRAT ) )); - BOOST_CHECK_EQUAL( WellProducer::GRAT , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::GRAT ) )); - BOOST_CHECK_EQUAL( WellProducer::LRAT , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::LRAT ) )); - BOOST_CHECK_EQUAL( WellProducer::CRAT , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::CRAT ) )); - BOOST_CHECK_EQUAL( WellProducer::RESV , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::RESV ) )); - BOOST_CHECK_EQUAL( WellProducer::BHP , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::BHP ) )); - BOOST_CHECK_EQUAL( WellProducer::THP , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::THP ) )); - BOOST_CHECK_EQUAL( WellProducer::GRUP , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::GRUP ) )); - - BOOST_CHECK_EQUAL( "ORAT" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "ORAT" ) )); - BOOST_CHECK_EQUAL( "WRAT" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "WRAT" ) )); - BOOST_CHECK_EQUAL( "GRAT" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "GRAT" ) )); - BOOST_CHECK_EQUAL( "LRAT" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "LRAT" ) )); - BOOST_CHECK_EQUAL( "CRAT" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "CRAT" ) )); - BOOST_CHECK_EQUAL( "RESV" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "RESV" ) )); - BOOST_CHECK_EQUAL( "BHP" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "BHP" ) )); - BOOST_CHECK_EQUAL( "THP" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "THP" ) )); - BOOST_CHECK_EQUAL( "GRUP" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "GRUP" ) )); -} - -/*******************************************************************/ -/*****************************************************************/ - -BOOST_AUTO_TEST_CASE(GuideRatePhaseEnum2String) { - BOOST_CHECK_EQUAL( "OIL" , GuideRate::GuideRatePhaseEnum2String(GuideRate::OIL)); - BOOST_CHECK_EQUAL( "WAT" , GuideRate::GuideRatePhaseEnum2String(GuideRate::WAT)); - BOOST_CHECK_EQUAL( "GAS" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GAS)); - BOOST_CHECK_EQUAL( "LIQ" , GuideRate::GuideRatePhaseEnum2String(GuideRate::LIQ)); - BOOST_CHECK_EQUAL( "COMB" , GuideRate::GuideRatePhaseEnum2String(GuideRate::COMB)); - BOOST_CHECK_EQUAL( "WGA" , GuideRate::GuideRatePhaseEnum2String(GuideRate::WGA)); - BOOST_CHECK_EQUAL( "CVAL" , GuideRate::GuideRatePhaseEnum2String(GuideRate::CVAL)); - BOOST_CHECK_EQUAL( "RAT" , GuideRate::GuideRatePhaseEnum2String(GuideRate::RAT)); - BOOST_CHECK_EQUAL( "RES" , GuideRate::GuideRatePhaseEnum2String(GuideRate::RES)); - BOOST_CHECK_EQUAL( "UNDEFINED" , GuideRate::GuideRatePhaseEnum2String(GuideRate::UNDEFINED)); -} - - -BOOST_AUTO_TEST_CASE(GuideRatePhaseEnumFromString) { - BOOST_CHECK_THROW( GuideRate::GuideRatePhaseEnumFromString("XRAT") , std::invalid_argument ); - BOOST_CHECK_EQUAL( GuideRate::OIL , GuideRate::GuideRatePhaseEnumFromString("OIL")); - BOOST_CHECK_EQUAL( GuideRate::WAT , GuideRate::GuideRatePhaseEnumFromString("WAT")); - BOOST_CHECK_EQUAL( GuideRate::GAS , GuideRate::GuideRatePhaseEnumFromString("GAS")); - BOOST_CHECK_EQUAL( GuideRate::LIQ , GuideRate::GuideRatePhaseEnumFromString("LIQ")); - BOOST_CHECK_EQUAL( GuideRate::COMB , GuideRate::GuideRatePhaseEnumFromString("COMB")); - BOOST_CHECK_EQUAL( GuideRate::WGA , GuideRate::GuideRatePhaseEnumFromString("WGA")); - BOOST_CHECK_EQUAL( GuideRate::CVAL , GuideRate::GuideRatePhaseEnumFromString("CVAL")); - BOOST_CHECK_EQUAL( GuideRate::RAT , GuideRate::GuideRatePhaseEnumFromString("RAT")); - BOOST_CHECK_EQUAL( GuideRate::RES , GuideRate::GuideRatePhaseEnumFromString("RES")); - BOOST_CHECK_EQUAL( GuideRate::UNDEFINED, GuideRate::GuideRatePhaseEnumFromString("UNDEFINED")); -} - - - -BOOST_AUTO_TEST_CASE(GuideRatePhaseEnum2Loop) { - BOOST_CHECK_EQUAL( GuideRate::OIL , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::OIL ) )); - BOOST_CHECK_EQUAL( GuideRate::WAT , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::WAT ) )); - BOOST_CHECK_EQUAL( GuideRate::GAS , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::GAS ) )); - BOOST_CHECK_EQUAL( GuideRate::LIQ , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::LIQ ) )); - BOOST_CHECK_EQUAL( GuideRate::COMB , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::COMB ) )); - BOOST_CHECK_EQUAL( GuideRate::WGA , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::WGA ) )); - BOOST_CHECK_EQUAL( GuideRate::CVAL , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::CVAL ) )); - BOOST_CHECK_EQUAL( GuideRate::RAT , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::RAT ) )); - BOOST_CHECK_EQUAL( GuideRate::RES , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::RES ) )); - BOOST_CHECK_EQUAL( GuideRate::UNDEFINED , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::UNDEFINED ) )); - - BOOST_CHECK_EQUAL( "OIL" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "OIL" ) )); - BOOST_CHECK_EQUAL( "WAT" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "WAT" ) )); - BOOST_CHECK_EQUAL( "GAS" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "GAS" ) )); - BOOST_CHECK_EQUAL( "LIQ" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "LIQ" ) )); - BOOST_CHECK_EQUAL( "COMB" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "COMB" ) )); - BOOST_CHECK_EQUAL( "WGA" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "WGA" ) )); - BOOST_CHECK_EQUAL( "CVAL" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "CVAL" ) )); - BOOST_CHECK_EQUAL( "RAT" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "RAT" ) )); - BOOST_CHECK_EQUAL( "RES" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "RES" ) )); - BOOST_CHECK_EQUAL( "UNDEFINED" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "UNDEFINED" ) )); - -} diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index dfa84d5cf..b61d13da1 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -1555,3 +1555,410 @@ BOOST_AUTO_TEST_CASE( COMPLUMP_specific_coordinates ) { BOOST_CHECK_EQUAL( open, cs2.getFromIJK( 1, 1, 4 ).getState() ); BOOST_CHECK_EQUAL( shut, cs2.getFromIJK( 1, 1, 5 ).getState() ); } + +BOOST_AUTO_TEST_CASE(TestCompletionStateEnum2String) { + BOOST_CHECK_EQUAL( "AUTO" , WellCompletion::StateEnum2String(WellCompletion::AUTO)); + BOOST_CHECK_EQUAL( "OPEN" , WellCompletion::StateEnum2String(WellCompletion::OPEN)); + BOOST_CHECK_EQUAL( "SHUT" , WellCompletion::StateEnum2String(WellCompletion::SHUT)); +} + + +BOOST_AUTO_TEST_CASE(TestCompletionStateEnumFromString) { + BOOST_CHECK_THROW( WellCompletion::StateEnumFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL( WellCompletion::AUTO , WellCompletion::StateEnumFromString("AUTO")); + BOOST_CHECK_EQUAL( WellCompletion::SHUT , WellCompletion::StateEnumFromString("SHUT")); + BOOST_CHECK_EQUAL( WellCompletion::SHUT , WellCompletion::StateEnumFromString("STOP")); + BOOST_CHECK_EQUAL( WellCompletion::OPEN , WellCompletion::StateEnumFromString("OPEN")); +} + + + +BOOST_AUTO_TEST_CASE(TestCompletionStateEnumLoop) { + BOOST_CHECK_EQUAL( WellCompletion::AUTO , WellCompletion::StateEnumFromString( WellCompletion::StateEnum2String( WellCompletion::AUTO ) )); + BOOST_CHECK_EQUAL( WellCompletion::SHUT , WellCompletion::StateEnumFromString( WellCompletion::StateEnum2String( WellCompletion::SHUT ) )); + BOOST_CHECK_EQUAL( WellCompletion::OPEN , WellCompletion::StateEnumFromString( WellCompletion::StateEnum2String( WellCompletion::OPEN ) )); + + BOOST_CHECK_EQUAL( "AUTO" , WellCompletion::StateEnum2String(WellCompletion::StateEnumFromString( "AUTO" ) )); + BOOST_CHECK_EQUAL( "OPEN" , WellCompletion::StateEnum2String(WellCompletion::StateEnumFromString( "OPEN" ) )); + BOOST_CHECK_EQUAL( "SHUT" , WellCompletion::StateEnum2String(WellCompletion::StateEnumFromString( "SHUT" ) )); +} + + +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(TestCompletionDirectionEnum2String) +{ + using namespace WellCompletion; + + BOOST_CHECK_EQUAL("X", DirectionEnum2String(DirectionEnum::X)); + BOOST_CHECK_EQUAL("Y", DirectionEnum2String(DirectionEnum::Y)); + BOOST_CHECK_EQUAL("Z", DirectionEnum2String(DirectionEnum::Z)); +} + +BOOST_AUTO_TEST_CASE(TestCompletionDirectionEnumFromString) +{ + using namespace WellCompletion; + + BOOST_CHECK_THROW(DirectionEnumFromString("XXX"), std::invalid_argument); + + BOOST_CHECK_EQUAL(DirectionEnum::X, DirectionEnumFromString("X")); + BOOST_CHECK_EQUAL(DirectionEnum::Y, DirectionEnumFromString("Y")); + BOOST_CHECK_EQUAL(DirectionEnum::Z, DirectionEnumFromString("Z")); +} + +BOOST_AUTO_TEST_CASE(TestCompletionDirectionEnumLoop) +{ + using namespace WellCompletion; + + BOOST_CHECK_EQUAL(DirectionEnum::X, DirectionEnumFromString(DirectionEnum2String(DirectionEnum::X))); + BOOST_CHECK_EQUAL(DirectionEnum::Y, DirectionEnumFromString(DirectionEnum2String(DirectionEnum::Y))); + BOOST_CHECK_EQUAL(DirectionEnum::Z, DirectionEnumFromString(DirectionEnum2String(DirectionEnum::Z))); + + BOOST_CHECK_EQUAL("X", DirectionEnum2String(DirectionEnumFromString("X"))); + BOOST_CHECK_EQUAL("Y", DirectionEnum2String(DirectionEnumFromString("Y"))); + BOOST_CHECK_EQUAL("Z", DirectionEnum2String(DirectionEnumFromString("Z"))); +} + +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(TestGroupInjectionControlEnum2String) { + BOOST_CHECK_EQUAL( "NONE" , GroupInjection::ControlEnum2String(GroupInjection::NONE)); + BOOST_CHECK_EQUAL( "RATE" , GroupInjection::ControlEnum2String(GroupInjection::RATE)); + BOOST_CHECK_EQUAL( "RESV" , GroupInjection::ControlEnum2String(GroupInjection::RESV)); + BOOST_CHECK_EQUAL( "REIN" , GroupInjection::ControlEnum2String(GroupInjection::REIN)); + BOOST_CHECK_EQUAL( "VREP" , GroupInjection::ControlEnum2String(GroupInjection::VREP)); + BOOST_CHECK_EQUAL( "FLD" , GroupInjection::ControlEnum2String(GroupInjection::FLD)); +} + + +BOOST_AUTO_TEST_CASE(TestGroupInjectionControlEnumFromString) { + BOOST_CHECK_THROW( GroupInjection::ControlEnumFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL( GroupInjection::NONE , GroupInjection::ControlEnumFromString("NONE")); + BOOST_CHECK_EQUAL( GroupInjection::RATE , GroupInjection::ControlEnumFromString("RATE")); + BOOST_CHECK_EQUAL( GroupInjection::RESV , GroupInjection::ControlEnumFromString("RESV")); + BOOST_CHECK_EQUAL( GroupInjection::REIN , GroupInjection::ControlEnumFromString("REIN")); + BOOST_CHECK_EQUAL( GroupInjection::VREP , GroupInjection::ControlEnumFromString("VREP")); + BOOST_CHECK_EQUAL( GroupInjection::FLD , GroupInjection::ControlEnumFromString("FLD")); +} + + + +BOOST_AUTO_TEST_CASE(TestGroupInjectionControlEnumLoop) { + BOOST_CHECK_EQUAL( GroupInjection::NONE , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::NONE ) )); + BOOST_CHECK_EQUAL( GroupInjection::RATE , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::RATE ) )); + BOOST_CHECK_EQUAL( GroupInjection::RESV , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::RESV ) )); + BOOST_CHECK_EQUAL( GroupInjection::REIN , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::REIN ) )); + BOOST_CHECK_EQUAL( GroupInjection::VREP , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::VREP ) )); + BOOST_CHECK_EQUAL( GroupInjection::FLD , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::FLD ) )); + + BOOST_CHECK_EQUAL( "NONE" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "NONE" ) )); + BOOST_CHECK_EQUAL( "RATE" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "RATE" ) )); + BOOST_CHECK_EQUAL( "RESV" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "RESV" ) )); + BOOST_CHECK_EQUAL( "REIN" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "REIN" ) )); + BOOST_CHECK_EQUAL( "VREP" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "VREP" ) )); + BOOST_CHECK_EQUAL( "FLD" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "FLD" ) )); +} + +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(TestGroupProductionControlEnum2String) { + BOOST_CHECK_EQUAL( "NONE" , GroupProduction::ControlEnum2String(GroupProduction::NONE)); + BOOST_CHECK_EQUAL( "ORAT" , GroupProduction::ControlEnum2String(GroupProduction::ORAT)); + BOOST_CHECK_EQUAL( "WRAT" , GroupProduction::ControlEnum2String(GroupProduction::WRAT)); + BOOST_CHECK_EQUAL( "GRAT" , GroupProduction::ControlEnum2String(GroupProduction::GRAT)); + BOOST_CHECK_EQUAL( "LRAT" , GroupProduction::ControlEnum2String(GroupProduction::LRAT)); + BOOST_CHECK_EQUAL( "CRAT" , GroupProduction::ControlEnum2String(GroupProduction::CRAT)); + BOOST_CHECK_EQUAL( "RESV" , GroupProduction::ControlEnum2String(GroupProduction::RESV)); + BOOST_CHECK_EQUAL( "PRBL" , GroupProduction::ControlEnum2String(GroupProduction::PRBL)); +} + + +BOOST_AUTO_TEST_CASE(TestGroupProductionControlEnumFromString) { + BOOST_CHECK_THROW( GroupProduction::ControlEnumFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL(GroupProduction::NONE , GroupProduction::ControlEnumFromString("NONE")); + BOOST_CHECK_EQUAL(GroupProduction::ORAT , GroupProduction::ControlEnumFromString("ORAT")); + BOOST_CHECK_EQUAL(GroupProduction::WRAT , GroupProduction::ControlEnumFromString("WRAT")); + BOOST_CHECK_EQUAL(GroupProduction::GRAT , GroupProduction::ControlEnumFromString("GRAT")); + BOOST_CHECK_EQUAL(GroupProduction::LRAT , GroupProduction::ControlEnumFromString("LRAT")); + BOOST_CHECK_EQUAL(GroupProduction::CRAT , GroupProduction::ControlEnumFromString("CRAT")); + BOOST_CHECK_EQUAL(GroupProduction::RESV , GroupProduction::ControlEnumFromString("RESV")); + BOOST_CHECK_EQUAL(GroupProduction::PRBL , GroupProduction::ControlEnumFromString("PRBL")); +} + + + +BOOST_AUTO_TEST_CASE(TestGroupProductionControlEnumLoop) { + BOOST_CHECK_EQUAL( GroupProduction::NONE, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::NONE ) )); + BOOST_CHECK_EQUAL( GroupProduction::ORAT, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::ORAT ) )); + BOOST_CHECK_EQUAL( GroupProduction::WRAT, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::WRAT ) )); + BOOST_CHECK_EQUAL( GroupProduction::GRAT, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::GRAT ) )); + BOOST_CHECK_EQUAL( GroupProduction::LRAT, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::LRAT ) )); + BOOST_CHECK_EQUAL( GroupProduction::CRAT, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::CRAT ) )); + BOOST_CHECK_EQUAL( GroupProduction::RESV, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::RESV ) )); + BOOST_CHECK_EQUAL( GroupProduction::PRBL, GroupProduction::ControlEnumFromString( GroupProduction::ControlEnum2String( GroupProduction::PRBL ) )); + + BOOST_CHECK_EQUAL( "NONE" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "NONE" ) )); + BOOST_CHECK_EQUAL( "ORAT" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "ORAT" ) )); + BOOST_CHECK_EQUAL( "WRAT" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "WRAT" ) )); + BOOST_CHECK_EQUAL( "GRAT" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "GRAT" ) )); + BOOST_CHECK_EQUAL( "LRAT" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "LRAT" ) )); + BOOST_CHECK_EQUAL( "CRAT" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "CRAT" ) )); + BOOST_CHECK_EQUAL( "RESV" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "RESV" ) )); + BOOST_CHECK_EQUAL( "PRBL" , GroupProduction::ControlEnum2String(GroupProduction::ControlEnumFromString( "PRBL" ) )); +} + +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(TestGroupProductionExceedLimitControlEnum2String) { + BOOST_CHECK_EQUAL( "NONE" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::NONE)); + BOOST_CHECK_EQUAL( "CON" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::CON)); + BOOST_CHECK_EQUAL( "+CON" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::CON_PLUS)); + BOOST_CHECK_EQUAL( "WELL" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::WELL)); + BOOST_CHECK_EQUAL( "PLUG" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::PLUG)); + BOOST_CHECK_EQUAL( "RATE" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::RATE)); +} + + +BOOST_AUTO_TEST_CASE(TestGroupProductionExceedLimitActionEnumFromString) { + BOOST_CHECK_THROW( GroupProductionExceedLimit::ActionEnumFromString("XXX") , std::invalid_argument ); + + BOOST_CHECK_EQUAL(GroupProductionExceedLimit::NONE , GroupProductionExceedLimit::ActionEnumFromString("NONE")); + BOOST_CHECK_EQUAL(GroupProductionExceedLimit::CON , GroupProductionExceedLimit::ActionEnumFromString("CON" )); + BOOST_CHECK_EQUAL(GroupProductionExceedLimit::CON_PLUS , GroupProductionExceedLimit::ActionEnumFromString("+CON")); + BOOST_CHECK_EQUAL(GroupProductionExceedLimit::WELL , GroupProductionExceedLimit::ActionEnumFromString("WELL")); + BOOST_CHECK_EQUAL(GroupProductionExceedLimit::PLUG , GroupProductionExceedLimit::ActionEnumFromString("PLUG")); + BOOST_CHECK_EQUAL(GroupProductionExceedLimit::RATE , GroupProductionExceedLimit::ActionEnumFromString("RATE")); +} + + + +BOOST_AUTO_TEST_CASE(TestGroupProductionExceedLimitActionEnumLoop) { + BOOST_CHECK_EQUAL( GroupProductionExceedLimit::NONE , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::NONE ) )); + BOOST_CHECK_EQUAL( GroupProductionExceedLimit::CON , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::CON ) )); + BOOST_CHECK_EQUAL( GroupProductionExceedLimit::CON_PLUS , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::CON_PLUS ) )); + BOOST_CHECK_EQUAL( GroupProductionExceedLimit::WELL , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::WELL ) )); + BOOST_CHECK_EQUAL( GroupProductionExceedLimit::PLUG , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::PLUG ) )); + BOOST_CHECK_EQUAL( GroupProductionExceedLimit::RATE , GroupProductionExceedLimit::ActionEnumFromString( GroupProductionExceedLimit::ActionEnum2String( GroupProductionExceedLimit::RATE ) )); + + BOOST_CHECK_EQUAL("NONE" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "NONE" ) )); + BOOST_CHECK_EQUAL("CON" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "CON" ) )); + BOOST_CHECK_EQUAL("+CON" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "+CON" ) )); + BOOST_CHECK_EQUAL("WELL" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "WELL" ) )); + BOOST_CHECK_EQUAL("PLUG" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "PLUG" ) )); + BOOST_CHECK_EQUAL("RATE" , GroupProductionExceedLimit::ActionEnum2String(GroupProductionExceedLimit::ActionEnumFromString( "RATE" ) )); +} + +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(TestInjectorEnum2String) { + BOOST_CHECK_EQUAL( "OIL" , WellInjector::Type2String(WellInjector::OIL)); + BOOST_CHECK_EQUAL( "GAS" , WellInjector::Type2String(WellInjector::GAS)); + BOOST_CHECK_EQUAL( "WATER" , WellInjector::Type2String(WellInjector::WATER)); + BOOST_CHECK_EQUAL( "MULTI" , WellInjector::Type2String(WellInjector::MULTI)); +} + + +BOOST_AUTO_TEST_CASE(TestInjectorEnumFromString) { + BOOST_CHECK_THROW( WellInjector::TypeFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL( WellInjector::OIL , WellInjector::TypeFromString("OIL")); + BOOST_CHECK_EQUAL( WellInjector::WATER , WellInjector::TypeFromString("WATER")); + BOOST_CHECK_EQUAL( WellInjector::WATER , WellInjector::TypeFromString("WAT")); + BOOST_CHECK_EQUAL( WellInjector::GAS , WellInjector::TypeFromString("GAS")); + BOOST_CHECK_EQUAL( WellInjector::MULTI , WellInjector::TypeFromString("MULTI")); +} + + + +BOOST_AUTO_TEST_CASE(TestInjectorEnumLoop) { + BOOST_CHECK_EQUAL( WellInjector::OIL , WellInjector::TypeFromString( WellInjector::Type2String( WellInjector::OIL ) )); + BOOST_CHECK_EQUAL( WellInjector::WATER , WellInjector::TypeFromString( WellInjector::Type2String( WellInjector::WATER ) )); + BOOST_CHECK_EQUAL( WellInjector::GAS , WellInjector::TypeFromString( WellInjector::Type2String( WellInjector::GAS ) )); + BOOST_CHECK_EQUAL( WellInjector::MULTI , WellInjector::TypeFromString( WellInjector::Type2String( WellInjector::MULTI ) )); + + BOOST_CHECK_EQUAL( "MULTI" , WellInjector::Type2String(WellInjector::TypeFromString( "MULTI" ) )); + BOOST_CHECK_EQUAL( "OIL" , WellInjector::Type2String(WellInjector::TypeFromString( "OIL" ) )); + BOOST_CHECK_EQUAL( "GAS" , WellInjector::Type2String(WellInjector::TypeFromString( "GAS" ) )); + BOOST_CHECK_EQUAL( "WATER" , WellInjector::Type2String(WellInjector::TypeFromString( "WATER" ) )); +} + +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(InjectorCOntrolMopdeEnum2String) { + BOOST_CHECK_EQUAL( "RATE" , WellInjector::ControlMode2String(WellInjector::RATE)); + BOOST_CHECK_EQUAL( "RESV" , WellInjector::ControlMode2String(WellInjector::RESV)); + BOOST_CHECK_EQUAL( "BHP" , WellInjector::ControlMode2String(WellInjector::BHP)); + BOOST_CHECK_EQUAL( "THP" , WellInjector::ControlMode2String(WellInjector::THP)); + BOOST_CHECK_EQUAL( "GRUP" , WellInjector::ControlMode2String(WellInjector::GRUP)); +} + + +BOOST_AUTO_TEST_CASE(InjectorControlModeEnumFromString) { + BOOST_CHECK_THROW( WellInjector::ControlModeFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL( WellInjector::RATE , WellInjector::ControlModeFromString("RATE")); + BOOST_CHECK_EQUAL( WellInjector::BHP , WellInjector::ControlModeFromString("BHP")); + BOOST_CHECK_EQUAL( WellInjector::RESV , WellInjector::ControlModeFromString("RESV")); + BOOST_CHECK_EQUAL( WellInjector::THP , WellInjector::ControlModeFromString("THP")); + BOOST_CHECK_EQUAL( WellInjector::GRUP , WellInjector::ControlModeFromString("GRUP")); +} + + + +BOOST_AUTO_TEST_CASE(InjectorControlModeEnumLoop) { + BOOST_CHECK_EQUAL( WellInjector::RATE , WellInjector::ControlModeFromString( WellInjector::ControlMode2String( WellInjector::RATE ) )); + BOOST_CHECK_EQUAL( WellInjector::BHP , WellInjector::ControlModeFromString( WellInjector::ControlMode2String( WellInjector::BHP ) )); + BOOST_CHECK_EQUAL( WellInjector::RESV , WellInjector::ControlModeFromString( WellInjector::ControlMode2String( WellInjector::RESV ) )); + BOOST_CHECK_EQUAL( WellInjector::THP , WellInjector::ControlModeFromString( WellInjector::ControlMode2String( WellInjector::THP ) )); + BOOST_CHECK_EQUAL( WellInjector::GRUP , WellInjector::ControlModeFromString( WellInjector::ControlMode2String( WellInjector::GRUP ) )); + + BOOST_CHECK_EQUAL( "THP" , WellInjector::ControlMode2String(WellInjector::ControlModeFromString( "THP" ) )); + BOOST_CHECK_EQUAL( "RATE" , WellInjector::ControlMode2String(WellInjector::ControlModeFromString( "RATE" ) )); + BOOST_CHECK_EQUAL( "RESV" , WellInjector::ControlMode2String(WellInjector::ControlModeFromString( "RESV" ) )); + BOOST_CHECK_EQUAL( "BHP" , WellInjector::ControlMode2String(WellInjector::ControlModeFromString( "BHP" ) )); + BOOST_CHECK_EQUAL( "GRUP" , WellInjector::ControlMode2String(WellInjector::ControlModeFromString( "GRUP" ) )); +} + + + +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(InjectorStatusEnum2String) { + BOOST_CHECK_EQUAL( "OPEN" , WellCommon::Status2String(WellCommon::OPEN)); + BOOST_CHECK_EQUAL( "SHUT" , WellCommon::Status2String(WellCommon::SHUT)); + BOOST_CHECK_EQUAL( "AUTO" , WellCommon::Status2String(WellCommon::AUTO)); + BOOST_CHECK_EQUAL( "STOP" , WellCommon::Status2String(WellCommon::STOP)); +} + + +BOOST_AUTO_TEST_CASE(InjectorStatusEnumFromString) { + BOOST_CHECK_THROW( WellCommon::StatusFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL( WellCommon::OPEN , WellCommon::StatusFromString("OPEN")); + BOOST_CHECK_EQUAL( WellCommon::AUTO , WellCommon::StatusFromString("AUTO")); + BOOST_CHECK_EQUAL( WellCommon::SHUT , WellCommon::StatusFromString("SHUT")); + BOOST_CHECK_EQUAL( WellCommon::STOP , WellCommon::StatusFromString("STOP")); +} + + + +BOOST_AUTO_TEST_CASE(InjectorStatusEnumLoop) { + BOOST_CHECK_EQUAL( WellCommon::OPEN , WellCommon::StatusFromString( WellCommon::Status2String( WellCommon::OPEN ) )); + BOOST_CHECK_EQUAL( WellCommon::AUTO , WellCommon::StatusFromString( WellCommon::Status2String( WellCommon::AUTO ) )); + BOOST_CHECK_EQUAL( WellCommon::SHUT , WellCommon::StatusFromString( WellCommon::Status2String( WellCommon::SHUT ) )); + BOOST_CHECK_EQUAL( WellCommon::STOP , WellCommon::StatusFromString( WellCommon::Status2String( WellCommon::STOP ) )); + + BOOST_CHECK_EQUAL( "STOP" , WellCommon::Status2String(WellCommon::StatusFromString( "STOP" ) )); + BOOST_CHECK_EQUAL( "OPEN" , WellCommon::Status2String(WellCommon::StatusFromString( "OPEN" ) )); + BOOST_CHECK_EQUAL( "SHUT" , WellCommon::Status2String(WellCommon::StatusFromString( "SHUT" ) )); + BOOST_CHECK_EQUAL( "AUTO" , WellCommon::Status2String(WellCommon::StatusFromString( "AUTO" ) )); +} + + + +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(ProducerCOntrolMopdeEnum2String) { + BOOST_CHECK_EQUAL( "ORAT" , WellProducer::ControlMode2String(WellProducer::ORAT)); + BOOST_CHECK_EQUAL( "WRAT" , WellProducer::ControlMode2String(WellProducer::WRAT)); + BOOST_CHECK_EQUAL( "GRAT" , WellProducer::ControlMode2String(WellProducer::GRAT)); + BOOST_CHECK_EQUAL( "LRAT" , WellProducer::ControlMode2String(WellProducer::LRAT)); + BOOST_CHECK_EQUAL( "CRAT" , WellProducer::ControlMode2String(WellProducer::CRAT)); + BOOST_CHECK_EQUAL( "RESV" , WellProducer::ControlMode2String(WellProducer::RESV)); + BOOST_CHECK_EQUAL( "BHP" , WellProducer::ControlMode2String(WellProducer::BHP)); + BOOST_CHECK_EQUAL( "THP" , WellProducer::ControlMode2String(WellProducer::THP)); + BOOST_CHECK_EQUAL( "GRUP" , WellProducer::ControlMode2String(WellProducer::GRUP)); +} + + +BOOST_AUTO_TEST_CASE(ProducerControlModeEnumFromString) { + BOOST_CHECK_THROW( WellProducer::ControlModeFromString("XRAT") , std::invalid_argument ); + BOOST_CHECK_EQUAL( WellProducer::ORAT , WellProducer::ControlModeFromString("ORAT")); + BOOST_CHECK_EQUAL( WellProducer::WRAT , WellProducer::ControlModeFromString("WRAT")); + BOOST_CHECK_EQUAL( WellProducer::GRAT , WellProducer::ControlModeFromString("GRAT")); + BOOST_CHECK_EQUAL( WellProducer::LRAT , WellProducer::ControlModeFromString("LRAT")); + BOOST_CHECK_EQUAL( WellProducer::CRAT , WellProducer::ControlModeFromString("CRAT")); + BOOST_CHECK_EQUAL( WellProducer::RESV , WellProducer::ControlModeFromString("RESV")); + BOOST_CHECK_EQUAL( WellProducer::BHP , WellProducer::ControlModeFromString("BHP" )); + BOOST_CHECK_EQUAL( WellProducer::THP , WellProducer::ControlModeFromString("THP" )); + BOOST_CHECK_EQUAL( WellProducer::GRUP , WellProducer::ControlModeFromString("GRUP")); +} + + + +BOOST_AUTO_TEST_CASE(ProducerControlModeEnumLoop) { + BOOST_CHECK_EQUAL( WellProducer::ORAT , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::ORAT ) )); + BOOST_CHECK_EQUAL( WellProducer::WRAT , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::WRAT ) )); + BOOST_CHECK_EQUAL( WellProducer::GRAT , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::GRAT ) )); + BOOST_CHECK_EQUAL( WellProducer::LRAT , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::LRAT ) )); + BOOST_CHECK_EQUAL( WellProducer::CRAT , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::CRAT ) )); + BOOST_CHECK_EQUAL( WellProducer::RESV , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::RESV ) )); + BOOST_CHECK_EQUAL( WellProducer::BHP , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::BHP ) )); + BOOST_CHECK_EQUAL( WellProducer::THP , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::THP ) )); + BOOST_CHECK_EQUAL( WellProducer::GRUP , WellProducer::ControlModeFromString( WellProducer::ControlMode2String( WellProducer::GRUP ) )); + + BOOST_CHECK_EQUAL( "ORAT" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "ORAT" ) )); + BOOST_CHECK_EQUAL( "WRAT" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "WRAT" ) )); + BOOST_CHECK_EQUAL( "GRAT" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "GRAT" ) )); + BOOST_CHECK_EQUAL( "LRAT" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "LRAT" ) )); + BOOST_CHECK_EQUAL( "CRAT" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "CRAT" ) )); + BOOST_CHECK_EQUAL( "RESV" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "RESV" ) )); + BOOST_CHECK_EQUAL( "BHP" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "BHP" ) )); + BOOST_CHECK_EQUAL( "THP" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "THP" ) )); + BOOST_CHECK_EQUAL( "GRUP" , WellProducer::ControlMode2String(WellProducer::ControlModeFromString( "GRUP" ) )); +} + +/*******************************************************************/ +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(GuideRatePhaseEnum2String) { + BOOST_CHECK_EQUAL( "OIL" , GuideRate::GuideRatePhaseEnum2String(GuideRate::OIL)); + BOOST_CHECK_EQUAL( "WAT" , GuideRate::GuideRatePhaseEnum2String(GuideRate::WAT)); + BOOST_CHECK_EQUAL( "GAS" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GAS)); + BOOST_CHECK_EQUAL( "LIQ" , GuideRate::GuideRatePhaseEnum2String(GuideRate::LIQ)); + BOOST_CHECK_EQUAL( "COMB" , GuideRate::GuideRatePhaseEnum2String(GuideRate::COMB)); + BOOST_CHECK_EQUAL( "WGA" , GuideRate::GuideRatePhaseEnum2String(GuideRate::WGA)); + BOOST_CHECK_EQUAL( "CVAL" , GuideRate::GuideRatePhaseEnum2String(GuideRate::CVAL)); + BOOST_CHECK_EQUAL( "RAT" , GuideRate::GuideRatePhaseEnum2String(GuideRate::RAT)); + BOOST_CHECK_EQUAL( "RES" , GuideRate::GuideRatePhaseEnum2String(GuideRate::RES)); + BOOST_CHECK_EQUAL( "UNDEFINED" , GuideRate::GuideRatePhaseEnum2String(GuideRate::UNDEFINED)); +} + + +BOOST_AUTO_TEST_CASE(GuideRatePhaseEnumFromString) { + BOOST_CHECK_THROW( GuideRate::GuideRatePhaseEnumFromString("XRAT") , std::invalid_argument ); + BOOST_CHECK_EQUAL( GuideRate::OIL , GuideRate::GuideRatePhaseEnumFromString("OIL")); + BOOST_CHECK_EQUAL( GuideRate::WAT , GuideRate::GuideRatePhaseEnumFromString("WAT")); + BOOST_CHECK_EQUAL( GuideRate::GAS , GuideRate::GuideRatePhaseEnumFromString("GAS")); + BOOST_CHECK_EQUAL( GuideRate::LIQ , GuideRate::GuideRatePhaseEnumFromString("LIQ")); + BOOST_CHECK_EQUAL( GuideRate::COMB , GuideRate::GuideRatePhaseEnumFromString("COMB")); + BOOST_CHECK_EQUAL( GuideRate::WGA , GuideRate::GuideRatePhaseEnumFromString("WGA")); + BOOST_CHECK_EQUAL( GuideRate::CVAL , GuideRate::GuideRatePhaseEnumFromString("CVAL")); + BOOST_CHECK_EQUAL( GuideRate::RAT , GuideRate::GuideRatePhaseEnumFromString("RAT")); + BOOST_CHECK_EQUAL( GuideRate::RES , GuideRate::GuideRatePhaseEnumFromString("RES")); + BOOST_CHECK_EQUAL( GuideRate::UNDEFINED, GuideRate::GuideRatePhaseEnumFromString("UNDEFINED")); +} + + + +BOOST_AUTO_TEST_CASE(GuideRatePhaseEnum2Loop) { + BOOST_CHECK_EQUAL( GuideRate::OIL , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::OIL ) )); + BOOST_CHECK_EQUAL( GuideRate::WAT , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::WAT ) )); + BOOST_CHECK_EQUAL( GuideRate::GAS , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::GAS ) )); + BOOST_CHECK_EQUAL( GuideRate::LIQ , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::LIQ ) )); + BOOST_CHECK_EQUAL( GuideRate::COMB , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::COMB ) )); + BOOST_CHECK_EQUAL( GuideRate::WGA , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::WGA ) )); + BOOST_CHECK_EQUAL( GuideRate::CVAL , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::CVAL ) )); + BOOST_CHECK_EQUAL( GuideRate::RAT , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::RAT ) )); + BOOST_CHECK_EQUAL( GuideRate::RES , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::RES ) )); + BOOST_CHECK_EQUAL( GuideRate::UNDEFINED , GuideRate::GuideRatePhaseEnumFromString( GuideRate::GuideRatePhaseEnum2String( GuideRate::UNDEFINED ) )); + + BOOST_CHECK_EQUAL( "OIL" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "OIL" ) )); + BOOST_CHECK_EQUAL( "WAT" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "WAT" ) )); + BOOST_CHECK_EQUAL( "GAS" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "GAS" ) )); + BOOST_CHECK_EQUAL( "LIQ" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "LIQ" ) )); + BOOST_CHECK_EQUAL( "COMB" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "COMB" ) )); + BOOST_CHECK_EQUAL( "WGA" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "WGA" ) )); + BOOST_CHECK_EQUAL( "CVAL" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "CVAL" ) )); + BOOST_CHECK_EQUAL( "RAT" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "RAT" ) )); + BOOST_CHECK_EQUAL( "RES" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "RES" ) )); + BOOST_CHECK_EQUAL( "UNDEFINED" , GuideRate::GuideRatePhaseEnum2String(GuideRate::GuideRatePhaseEnumFromString( "UNDEFINED" ) )); + +} diff --git a/tests/parser/StringTests.cpp b/tests/parser/StringTests.cpp index c2ea98738..da84fa155 100644 --- a/tests/parser/StringTests.cpp +++ b/tests/parser/StringTests.cpp @@ -60,3 +60,99 @@ BOOST_AUTO_TEST_CASE( write_parts_of_dst ) { BOOST_CHECK_EQUAL( dst, "STRINGmixed" ); BOOST_CHECK_EQUAL( view, "string" ); } + +BOOST_AUTO_TEST_CASE(fullStringView) { + std::string srcstr = "lorem ipsum"; + string_view view( srcstr ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + srcstr.begin(), srcstr.end(), + view.begin(), view.end() ); +} + +BOOST_AUTO_TEST_CASE(viewCorrectSize) { + std::string srcstr = "lorem ipsum"; + + string_view full( srcstr ); + BOOST_CHECK_EQUAL( srcstr.size(), full.size() ); + + string_view view( srcstr, 5 ); + BOOST_CHECK_EQUAL( 5, view.size() ); + BOOST_CHECK_EQUAL( 5, view.length() ); +} + +BOOST_AUTO_TEST_CASE(viewOperatorAt) { + std::string srcstr = "lorem ipsum"; + string_view view( srcstr ); + + for( size_t i = 0; i < view.size(); ++i ) + BOOST_CHECK_EQUAL( view[ i ], srcstr[ i ] ); +} + +BOOST_AUTO_TEST_CASE(viewFrontBack) { + std::string srcstr = "lorem ipsum"; + string_view view( srcstr ); + + BOOST_CHECK_EQUAL( view.front(), 'l' ); + BOOST_CHECK_EQUAL( view.back(), 'm' ); +} + + +BOOST_AUTO_TEST_CASE(viewSubstr) { + std::string srcstr = "lorem ipsum"; + string_view view( srcstr ); + + BOOST_CHECK_NO_THROW( view.string() ); + BOOST_CHECK_EQUAL( srcstr, view.string() ); + BOOST_CHECK_EQUAL( srcstr, view.substr() ); + BOOST_CHECK_EQUAL( "", view.substr( 0, 0 ) ); + + BOOST_CHECK_EQUAL( srcstr.substr( 1 ), view.substr( 1 ) ); + + BOOST_CHECK_THROW( view.substr( srcstr.size() + 1 ), std::out_of_range ); + BOOST_CHECK_THROW( view.substr( 0, srcstr.size() + 1 ), std::out_of_range ); + BOOST_CHECK_THROW( view.substr( 1, 0 ), std::invalid_argument ); + BOOST_CHECK_NO_THROW( view.substr( 0, 0 ) ); +} + +BOOST_AUTO_TEST_CASE(viewStream) { + std::string srcstr = "lorem ipsum"; + string_view view( srcstr ); + + std::stringstream str; + str << view; + + BOOST_CHECK_EQUAL( srcstr, str.str() ); +} + +BOOST_AUTO_TEST_CASE(equalityOperators) { + std::string srcstr = "lorem ipsum"; + std::string diffstr = "lorem"; + string_view view( srcstr ); + + BOOST_CHECK_EQUAL( srcstr, view ); + BOOST_CHECK_NE( diffstr, view ); + + BOOST_CHECK_EQUAL( view, srcstr ); + BOOST_CHECK_NE( view, diffstr ); + + BOOST_CHECK_EQUAL( "lorem ipsum", view ); + BOOST_CHECK_NE( "lorem", view ); + + BOOST_CHECK_EQUAL( view, "lorem ipsum" ); + BOOST_CHECK_NE( view, "lorem" ); +} + +BOOST_AUTO_TEST_CASE(plusOperator) { + std::string total = "lorem ipsum"; + std::string lhs = "lorem"; + std::string ws = " "; + std::string rhs = "ipsum"; + + string_view lhs_view( lhs ); + string_view rhs_view( rhs ); + + BOOST_CHECK_EQUAL( total, lhs_view + ws + rhs_view ); + BOOST_CHECK_EQUAL( lhs + ws, lhs_view + ws ); + BOOST_CHECK_EQUAL( ws + rhs, ws + rhs_view ); +} diff --git a/tests/parser/StringviewTests.cpp b/tests/parser/StringviewTests.cpp deleted file mode 100644 index 0a57384a0..000000000 --- a/tests/parser/StringviewTests.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#define BOOST_TEST_MODULE StringviewTests - -#include -#include - -#include - -#include - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(fullStringView) { - std::string srcstr = "lorem ipsum"; - string_view view( srcstr ); - - BOOST_CHECK_EQUAL_COLLECTIONS( - srcstr.begin(), srcstr.end(), - view.begin(), view.end() ); -} - -BOOST_AUTO_TEST_CASE(viewCorrectSize) { - std::string srcstr = "lorem ipsum"; - - string_view full( srcstr ); - BOOST_CHECK_EQUAL( srcstr.size(), full.size() ); - - string_view view( srcstr, 5 ); - BOOST_CHECK_EQUAL( 5, view.size() ); - BOOST_CHECK_EQUAL( 5, view.length() ); -} - -BOOST_AUTO_TEST_CASE(viewOperatorAt) { - std::string srcstr = "lorem ipsum"; - string_view view( srcstr ); - - for( size_t i = 0; i < view.size(); ++i ) - BOOST_CHECK_EQUAL( view[ i ], srcstr[ i ] ); -} - -BOOST_AUTO_TEST_CASE(viewFrontBack) { - std::string srcstr = "lorem ipsum"; - string_view view( srcstr ); - - BOOST_CHECK_EQUAL( view.front(), 'l' ); - BOOST_CHECK_EQUAL( view.back(), 'm' ); -} - - -BOOST_AUTO_TEST_CASE(viewSubstr) { - std::string srcstr = "lorem ipsum"; - string_view view( srcstr ); - - BOOST_CHECK_NO_THROW( view.string() ); - BOOST_CHECK_EQUAL( srcstr, view.string() ); - BOOST_CHECK_EQUAL( srcstr, view.substr() ); - BOOST_CHECK_EQUAL( "", view.substr( 0, 0 ) ); - - BOOST_CHECK_EQUAL( srcstr.substr( 1 ), view.substr( 1 ) ); - - BOOST_CHECK_THROW( view.substr( srcstr.size() + 1 ), std::out_of_range ); - BOOST_CHECK_THROW( view.substr( 0, srcstr.size() + 1 ), std::out_of_range ); - BOOST_CHECK_THROW( view.substr( 1, 0 ), std::invalid_argument ); - BOOST_CHECK_NO_THROW( view.substr( 0, 0 ) ); -} - -BOOST_AUTO_TEST_CASE(viewStream) { - std::string srcstr = "lorem ipsum"; - string_view view( srcstr ); - - std::stringstream str; - str << view; - - BOOST_CHECK_EQUAL( srcstr, str.str() ); -} - -BOOST_AUTO_TEST_CASE(equalityOperators) { - std::string srcstr = "lorem ipsum"; - std::string diffstr = "lorem"; - string_view view( srcstr ); - - BOOST_CHECK_EQUAL( srcstr, view ); - BOOST_CHECK_NE( diffstr, view ); - - BOOST_CHECK_EQUAL( view, srcstr ); - BOOST_CHECK_NE( view, diffstr ); - - BOOST_CHECK_EQUAL( "lorem ipsum", view ); - BOOST_CHECK_NE( "lorem", view ); - - BOOST_CHECK_EQUAL( view, "lorem ipsum" ); - BOOST_CHECK_NE( view, "lorem" ); -} - -BOOST_AUTO_TEST_CASE(plusOperator) { - std::string total = "lorem ipsum"; - std::string lhs = "lorem"; - std::string ws = " "; - std::string rhs = "ipsum"; - - string_view lhs_view( lhs ); - string_view rhs_view( rhs ); - - BOOST_CHECK_EQUAL( total, lhs_view + ws + rhs_view ); - BOOST_CHECK_EQUAL( lhs + ws, lhs_view + ws ); - BOOST_CHECK_EQUAL( ws + rhs, ws + rhs_view ); -} diff --git a/tests/parser/WellPropertiesTests.cpp b/tests/parser/WellPropertiesTests.cpp deleted file mode 100644 index d5b50b12e..000000000 --- a/tests/parser/WellPropertiesTests.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - Copyright 2014 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 . - */ - -#define BOOST_TEST_MODULE WellPropertiesTest -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace { - namespace WCONHIST { - std::string all_specified_CMODE_BHP() { - const std::string input = - "WCONHIST\n" - "'P' 'OPEN' 'BHP' 1 2 3/\n/\n"; - - return input; - } - - - - std::string all_specified() { - const std::string input = - "WCONHIST\n" - "'P' 'OPEN' 'ORAT' 1 2 3/\n/\n"; - - return input; - } - - std::string orat_defaulted() { - const std::string input = - "WCONHIST\n" - "'P' 'OPEN' 'WRAT' 1* 2 3/\n/\n"; - - return input; - } - - std::string owrat_defaulted() { - const std::string input = - "WCONHIST\n" - "'P' 'OPEN' 'GRAT' 1* 1* 3/\n/\n"; - - return input; - } - - std::string all_defaulted() { - const std::string input = - "WCONHIST\n" - "'P' 'OPEN' 'LRAT'/\n/\n"; - - return input; - } - - std::string all_defaulted_with_bhp() { - const std::string input = - "WCONHIST\n" - "-- 1 2 3 4-9 10\n" - " 'P' 'OPEN' 'RESV' 6* 500/\n/\n"; - - return input; - } - - Opm::WellProductionProperties properties(const std::string& input) { - Opm::Parser parser; - - auto deck = parser.parseString(input, Opm::ParseContext()); - const auto& record = deck.getKeyword("WCONHIST").getRecord(0); - Opm::WellProductionProperties hist = Opm::WellProductionProperties::history( 100 , record);; - - return hist; - } - } // namespace WCONHIST - - namespace WCONPROD { - std::string - all_specified_CMODE_BHP() - { - const std::string input = - "WCONPROD\n" - "'P' 'OPEN' 'BHP' 1 2 3/\n/\n"; - - return input; - } - - - Opm::WellProductionProperties - properties(const std::string& input) - { - Opm::Parser parser; - - auto deck = parser.parseString(input, Opm::ParseContext()); - const auto& kwd = deck.getKeyword("WCONHIST"); - const auto& record = kwd.getRecord(0); - Opm::WellProductionProperties pred = Opm::WellProductionProperties::prediction( record, false ); - - return pred; - } - } - -} // namespace anonymous - -BOOST_AUTO_TEST_CASE(WCH_All_Specified_BHP_Defaulted) -{ - const Opm::WellProductionProperties& p = - WCONHIST::properties(WCONHIST::all_specified()); - - // WCONHIST always supports {O,W,G}RAT, LRAT, and - // RESV--irrespective of actual specification. - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::ORAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::WRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::GRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::LRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::RESV)); - - BOOST_CHECK_EQUAL(p.controlMode , Opm::WellProducer::ORAT); - - // BHP must be explicitly provided/specified - BOOST_CHECK(! p.hasProductionControl(Opm::WellProducer::BHP)); -} - -BOOST_AUTO_TEST_CASE(WCH_ORAT_Defaulted_BHP_Defaulted) -{ - const Opm::WellProductionProperties& p = - WCONHIST::properties(WCONHIST::orat_defaulted()); - - // WCONHIST always supports {O,W,G}RAT, LRAT, and - // RESV--irrespective of actual specification. - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::ORAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::WRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::GRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::LRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::RESV)); - BOOST_CHECK_EQUAL(p.controlMode , Opm::WellProducer::WRAT); - - // BHP must be explicitly provided/specified - BOOST_CHECK(! p.hasProductionControl(Opm::WellProducer::BHP)); -} - -BOOST_AUTO_TEST_CASE(WCH_OWRAT_Defaulted_BHP_Defaulted) -{ - const Opm::WellProductionProperties& p = - WCONHIST::properties(WCONHIST::owrat_defaulted()); - - // WCONHIST always supports {O,W,G}RAT, LRAT, and - // RESV--irrespective of actual specification. - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::ORAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::WRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::GRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::LRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::RESV)); - BOOST_CHECK_EQUAL(p.controlMode , Opm::WellProducer::GRAT); - - // BHP must be explicitly provided/specified - BOOST_CHECK(! p.hasProductionControl(Opm::WellProducer::BHP)); -} - -BOOST_AUTO_TEST_CASE(WCH_Rates_Defaulted_BHP_Defaulted) -{ - const Opm::WellProductionProperties& p = - WCONHIST::properties(WCONHIST::all_defaulted()); - - // WCONHIST always supports {O,W,G}RAT, LRAT, and - // RESV--irrespective of actual specification. - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::ORAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::WRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::GRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::LRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::RESV)); - BOOST_CHECK_EQUAL(p.controlMode , Opm::WellProducer::LRAT); - - // BHP must be explicitly provided/specified - BOOST_CHECK(! p.hasProductionControl(Opm::WellProducer::BHP)); -} - -BOOST_AUTO_TEST_CASE(WCH_Rates_Defaulted_BHP_Specified) -{ - const Opm::WellProductionProperties& p = - WCONHIST::properties(WCONHIST::all_defaulted_with_bhp()); - - // WCONHIST always supports {O,W,G}RAT, LRAT, and - // RESV--irrespective of actual specification. - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::ORAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::WRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::GRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::LRAT)); - BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::RESV)); - - BOOST_CHECK_EQUAL(p.controlMode , Opm::WellProducer::RESV); - - /* - BHP in WCONHIST is not an available control; just information - about the historical BHP. - */ - BOOST_CHECK_EQUAL(false , p.hasProductionControl(Opm::WellProducer::BHP)); -} - - -BOOST_AUTO_TEST_CASE(BHP_CMODE) -{ - BOOST_CHECK_THROW( WCONHIST::properties(WCONHIST::all_specified_CMODE_BHP()) , std::invalid_argument); - BOOST_CHECK_THROW( WCONPROD::properties(WCONPROD::all_specified_CMODE_BHP()) , std::invalid_argument); -} - - - - -BOOST_AUTO_TEST_CASE(CMODE_DEFAULT) { - const Opm::WellProductionProperties Pproperties; - const Opm::WellInjectionProperties Iproperties; - - BOOST_CHECK_EQUAL( Pproperties.controlMode , Opm::WellProducer::CMODE_UNDEFINED ); - BOOST_CHECK_EQUAL( Iproperties.controlMode , Opm::WellInjector::CMODE_UNDEFINED ); -} diff --git a/tests/parser/WellTests.cpp b/tests/parser/WellTests.cpp index 92ff88a8e..ab7c24015 100644 --- a/tests/parser/WellTests.cpp +++ b/tests/parser/WellTests.cpp @@ -797,3 +797,208 @@ BOOST_AUTO_TEST_CASE(testWellNameInWellNamePattern) { const std::string& wellnamePattern2 = "NONE"; BOOST_CHECK_EQUAL(Opm::Well::wellNameInWellNamePattern(wellname1, wellnamePattern2), false); } + +namespace { + namespace WCONHIST { + std::string all_specified_CMODE_BHP() { + const std::string input = + "WCONHIST\n" + "'P' 'OPEN' 'BHP' 1 2 3/\n/\n"; + + return input; + } + + + + std::string all_specified() { + const std::string input = + "WCONHIST\n" + "'P' 'OPEN' 'ORAT' 1 2 3/\n/\n"; + + return input; + } + + std::string orat_defaulted() { + const std::string input = + "WCONHIST\n" + "'P' 'OPEN' 'WRAT' 1* 2 3/\n/\n"; + + return input; + } + + std::string owrat_defaulted() { + const std::string input = + "WCONHIST\n" + "'P' 'OPEN' 'GRAT' 1* 1* 3/\n/\n"; + + return input; + } + + std::string all_defaulted() { + const std::string input = + "WCONHIST\n" + "'P' 'OPEN' 'LRAT'/\n/\n"; + + return input; + } + + std::string all_defaulted_with_bhp() { + const std::string input = + "WCONHIST\n" + "-- 1 2 3 4-9 10\n" + " 'P' 'OPEN' 'RESV' 6* 500/\n/\n"; + + return input; + } + + Opm::WellProductionProperties properties(const std::string& input) { + Opm::Parser parser; + + auto deck = parser.parseString(input, Opm::ParseContext()); + const auto& record = deck.getKeyword("WCONHIST").getRecord(0); + Opm::WellProductionProperties hist = Opm::WellProductionProperties::history( 100 , record);; + + return hist; + } + } // namespace WCONHIST + + namespace WCONPROD { + std::string + all_specified_CMODE_BHP() + { + const std::string input = + "WCONPROD\n" + "'P' 'OPEN' 'BHP' 1 2 3/\n/\n"; + + return input; + } + + + Opm::WellProductionProperties + properties(const std::string& input) + { + Opm::Parser parser; + + auto deck = parser.parseString(input, Opm::ParseContext()); + const auto& kwd = deck.getKeyword("WCONHIST"); + const auto& record = kwd.getRecord(0); + Opm::WellProductionProperties pred = Opm::WellProductionProperties::prediction( record, false ); + + return pred; + } + } + +} // namespace anonymous + +BOOST_AUTO_TEST_CASE(WCH_All_Specified_BHP_Defaulted) +{ + const Opm::WellProductionProperties& p = + WCONHIST::properties(WCONHIST::all_specified()); + + // WCONHIST always supports {O,W,G}RAT, LRAT, and + // RESV--irrespective of actual specification. + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::ORAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::WRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::GRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::LRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::RESV)); + + BOOST_CHECK_EQUAL(p.controlMode , Opm::WellProducer::ORAT); + + // BHP must be explicitly provided/specified + BOOST_CHECK(! p.hasProductionControl(Opm::WellProducer::BHP)); +} + +BOOST_AUTO_TEST_CASE(WCH_ORAT_Defaulted_BHP_Defaulted) +{ + const Opm::WellProductionProperties& p = + WCONHIST::properties(WCONHIST::orat_defaulted()); + + // WCONHIST always supports {O,W,G}RAT, LRAT, and + // RESV--irrespective of actual specification. + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::ORAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::WRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::GRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::LRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::RESV)); + BOOST_CHECK_EQUAL(p.controlMode , Opm::WellProducer::WRAT); + + // BHP must be explicitly provided/specified + BOOST_CHECK(! p.hasProductionControl(Opm::WellProducer::BHP)); +} + +BOOST_AUTO_TEST_CASE(WCH_OWRAT_Defaulted_BHP_Defaulted) +{ + const Opm::WellProductionProperties& p = + WCONHIST::properties(WCONHIST::owrat_defaulted()); + + // WCONHIST always supports {O,W,G}RAT, LRAT, and + // RESV--irrespective of actual specification. + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::ORAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::WRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::GRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::LRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::RESV)); + BOOST_CHECK_EQUAL(p.controlMode , Opm::WellProducer::GRAT); + + // BHP must be explicitly provided/specified + BOOST_CHECK(! p.hasProductionControl(Opm::WellProducer::BHP)); +} + +BOOST_AUTO_TEST_CASE(WCH_Rates_Defaulted_BHP_Defaulted) +{ + const Opm::WellProductionProperties& p = + WCONHIST::properties(WCONHIST::all_defaulted()); + + // WCONHIST always supports {O,W,G}RAT, LRAT, and + // RESV--irrespective of actual specification. + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::ORAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::WRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::GRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::LRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::RESV)); + BOOST_CHECK_EQUAL(p.controlMode , Opm::WellProducer::LRAT); + + // BHP must be explicitly provided/specified + BOOST_CHECK(! p.hasProductionControl(Opm::WellProducer::BHP)); +} + +BOOST_AUTO_TEST_CASE(WCH_Rates_Defaulted_BHP_Specified) +{ + const Opm::WellProductionProperties& p = + WCONHIST::properties(WCONHIST::all_defaulted_with_bhp()); + + // WCONHIST always supports {O,W,G}RAT, LRAT, and + // RESV--irrespective of actual specification. + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::ORAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::WRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::GRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::LRAT)); + BOOST_CHECK(p.hasProductionControl(Opm::WellProducer::RESV)); + + BOOST_CHECK_EQUAL(p.controlMode , Opm::WellProducer::RESV); + + /* + BHP in WCONHIST is not an available control; just information + about the historical BHP. + */ + BOOST_CHECK_EQUAL(false , p.hasProductionControl(Opm::WellProducer::BHP)); +} + + +BOOST_AUTO_TEST_CASE(BHP_CMODE) +{ + BOOST_CHECK_THROW( WCONHIST::properties(WCONHIST::all_specified_CMODE_BHP()) , std::invalid_argument); + BOOST_CHECK_THROW( WCONPROD::properties(WCONPROD::all_specified_CMODE_BHP()) , std::invalid_argument); +} + + + + +BOOST_AUTO_TEST_CASE(CMODE_DEFAULT) { + const Opm::WellProductionProperties Pproperties; + const Opm::WellInjectionProperties Iproperties; + + BOOST_CHECK_EQUAL( Pproperties.controlMode , Opm::WellProducer::CMODE_UNDEFINED ); + BOOST_CHECK_EQUAL( Iproperties.controlMode , Opm::WellInjector::CMODE_UNDEFINED ); +}