Changed Deck & Section implementation
- Removed the KeywordContainer class; and implemented the behaviour directly in the Deck. - Added begin() and end() iterators to the Deck. - Section class inherits from Deck.
This commit is contained in:
parent
150a6f8ebd
commit
7bd566d6a6
@ -41,7 +41,6 @@ Deck/DeckIntItem.cpp
|
||||
Deck/DeckDoubleItem.cpp
|
||||
Deck/DeckFloatItem.cpp
|
||||
Deck/DeckStringItem.cpp
|
||||
Deck/KeywordContainer.cpp
|
||||
Deck/Section.cpp
|
||||
)
|
||||
|
||||
@ -130,7 +129,6 @@ Deck/DeckIntItem.hpp
|
||||
Deck/DeckDoubleItem.hpp
|
||||
Deck/DeckFloatItem.hpp
|
||||
Deck/DeckStringItem.hpp
|
||||
Deck/KeywordContainer.hpp
|
||||
Deck/Section.hpp
|
||||
#
|
||||
Parser/ParserEnums.hpp
|
||||
|
@ -25,39 +25,73 @@
|
||||
namespace Opm {
|
||||
|
||||
Deck::Deck() {
|
||||
m_keywords = KeywordContainerPtr(new KeywordContainer());
|
||||
}
|
||||
|
||||
bool Deck::hasKeyword(const std::string& keyword) const {
|
||||
return m_keywords->hasKeyword(keyword);
|
||||
return (m_keywordMap.find(keyword) != m_keywordMap.end());
|
||||
}
|
||||
|
||||
void Deck::addKeyword( DeckKeywordConstPtr keyword) {
|
||||
m_keywords->addKeyword(keyword);
|
||||
m_keywordList.push_back(keyword);
|
||||
|
||||
if (!hasKeyword(keyword->name())) {
|
||||
m_keywordMap[keyword->name()] = std::vector<DeckKeywordConstPtr>();
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap[keyword->name()];
|
||||
keywordList.push_back(keyword);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword, size_t index) const {
|
||||
return m_keywords->getKeyword(keyword , index);
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
||||
if (index < keywordList.size())
|
||||
return keywordList[index];
|
||||
else
|
||||
throw std::out_of_range("Keyword index is out of range.");
|
||||
}
|
||||
|
||||
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword) const {
|
||||
return m_keywords->getKeyword(keyword);
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
||||
return keywordList.back();
|
||||
}
|
||||
|
||||
DeckKeywordConstPtr Deck::getKeyword(size_t index) const {
|
||||
return m_keywords->getKeyword(index);
|
||||
if (index < m_keywordList.size())
|
||||
return m_keywordList[index];
|
||||
else
|
||||
throw std::out_of_range("Keyword index is out of range.");
|
||||
}
|
||||
|
||||
size_t Deck::numKeywords(const std::string& keyword) const {
|
||||
return m_keywords->numKeywords( keyword );
|
||||
if (hasKeyword(keyword)) {
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
||||
return keywordList.size();
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
const std::vector<DeckKeywordConstPtr>& Deck::getKeywordList(const std::string& keyword) const {
|
||||
return m_keywords->getKeywordList( keyword );
|
||||
if (hasKeyword(keyword)) {
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap.find(keyword)->second;
|
||||
return keywordList;
|
||||
} else
|
||||
throw std::invalid_argument("Keyword: " + keyword + " is not found in the container");
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordConstPtr>::const_iterator Deck::begin() const {
|
||||
return m_keywordList.begin();
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordConstPtr>::const_iterator Deck::end() const {
|
||||
return m_keywordList.end();
|
||||
}
|
||||
|
||||
|
||||
size_t Deck::size() const {
|
||||
return m_keywords->size();
|
||||
return m_keywordList.size();
|
||||
}
|
||||
|
||||
void Deck::initUnitSystem() {
|
||||
|
@ -23,7 +23,8 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/KeywordContainer.hpp>
|
||||
//#include <opm/parser/eclipse/Deck/KeywordContainer.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
|
||||
|
||||
namespace Opm {
|
||||
@ -43,11 +44,15 @@ namespace Opm {
|
||||
void initUnitSystem();
|
||||
std::shared_ptr<UnitSystem> getDefaultUnitSystem() const;
|
||||
std::shared_ptr<UnitSystem> getActiveUnitSystem() const;
|
||||
std::vector<DeckKeywordConstPtr>::const_iterator begin() const;
|
||||
std::vector<DeckKeywordConstPtr>::const_iterator end() const;
|
||||
|
||||
private:
|
||||
KeywordContainerPtr m_keywords;
|
||||
std::shared_ptr<UnitSystem> m_defaultUnits;
|
||||
std::shared_ptr<UnitSystem> m_activeUnits;
|
||||
|
||||
std::vector<DeckKeywordConstPtr> m_keywordList;
|
||||
std::map<std::string, std::vector<DeckKeywordConstPtr> > m_keywordMap;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Deck> DeckPtr;
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/KeywordContainer.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
KeywordContainer::KeywordContainer() {
|
||||
}
|
||||
|
||||
bool KeywordContainer::hasKeyword(const std::string& keyword) const {
|
||||
return (m_keywordMap.find(keyword) != m_keywordMap.end());
|
||||
}
|
||||
|
||||
size_t KeywordContainer::size() const {
|
||||
return m_keywordList.size();
|
||||
}
|
||||
|
||||
void KeywordContainer::addKeyword(DeckKeywordConstPtr keyword) {
|
||||
m_keywordList.push_back(keyword);
|
||||
|
||||
if (!hasKeyword(keyword->name())) {
|
||||
m_keywordMap[keyword->name()] = std::vector<DeckKeywordConstPtr>();
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap[keyword->name()];
|
||||
keywordList.push_back(keyword);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<DeckKeywordConstPtr>& KeywordContainer::getKeywordList(const std::string& keyword) const {
|
||||
if (hasKeyword(keyword)) {
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap.find(keyword)->second;
|
||||
return keywordList;
|
||||
} else
|
||||
throw std::invalid_argument("Keyword: " + keyword + " is not found in the container");
|
||||
}
|
||||
|
||||
|
||||
DeckKeywordConstPtr KeywordContainer::getKeyword(const std::string& keyword, size_t index) const {
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
||||
if (index < keywordList.size())
|
||||
return keywordList[index];
|
||||
else
|
||||
throw std::out_of_range("Keyword index is out of range.");
|
||||
}
|
||||
|
||||
|
||||
DeckKeywordConstPtr KeywordContainer::getKeyword(const std::string& keyword) const {
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
||||
return keywordList.back();
|
||||
}
|
||||
|
||||
DeckKeywordConstPtr KeywordContainer::getKeyword(size_t index) const {
|
||||
if (index < m_keywordList.size())
|
||||
return m_keywordList[index];
|
||||
else
|
||||
throw std::out_of_range("Keyword index is out of range.");
|
||||
}
|
||||
|
||||
size_t KeywordContainer::numKeywords(const std::string& keyword) const{
|
||||
if (hasKeyword(keyword)) {
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
||||
return keywordList.size();
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordConstPtr>::iterator KeywordContainer::begin() {
|
||||
return m_keywordList.begin();
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordConstPtr>::iterator KeywordContainer::end() {
|
||||
return m_keywordList.end();
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* File: KeywordContainer.hpp
|
||||
* Author: kflik
|
||||
*
|
||||
* Created on June 3, 2013, 10:49 AM
|
||||
*/
|
||||
|
||||
#ifndef KEYWORDCONTAINER_HPP
|
||||
#define KEYWORDCONTAINER_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <memory>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class KeywordContainer {
|
||||
public:
|
||||
KeywordContainer();
|
||||
bool hasKeyword(const std::string& keyword) const;
|
||||
size_t size() const;
|
||||
void addKeyword(DeckKeywordConstPtr keyword);
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword, size_t index) const;
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword) const;
|
||||
DeckKeywordConstPtr getKeyword(size_t index) const;
|
||||
|
||||
const std::vector<DeckKeywordConstPtr>& getKeywordList(const std::string& keyword) const;
|
||||
size_t numKeywords(const std::string& keyword) const;
|
||||
|
||||
std::vector<DeckKeywordConstPtr>::iterator begin();
|
||||
std::vector<DeckKeywordConstPtr>::iterator end();
|
||||
|
||||
private:
|
||||
std::vector<DeckKeywordConstPtr> m_keywordList;
|
||||
std::map<std::string, std::vector<DeckKeywordConstPtr> > m_keywordMap;
|
||||
};
|
||||
typedef std::shared_ptr<KeywordContainer> KeywordContainerPtr;
|
||||
typedef std::shared_ptr<const KeywordContainer> KeywordContainerConstPtr;
|
||||
}
|
||||
|
||||
#endif /* KEYWORDCONTAINER_HPP */
|
||||
|
@ -40,65 +40,37 @@ namespace Opm {
|
||||
|
||||
void Section::populateSection(DeckConstPtr deck, const std::string& startKeywordName)
|
||||
{
|
||||
// find the first occurence of the section's start keyword
|
||||
size_t startKeywordIdx = 0;
|
||||
for (; startKeywordIdx<deck->size(); startKeywordIdx++) {
|
||||
if (deck->getKeyword(startKeywordIdx)->name() == startKeywordName)
|
||||
break;
|
||||
}
|
||||
bool inSection = false;
|
||||
for (auto iter = deck->begin(); iter != deck->end(); ++iter) {
|
||||
auto keyword = *iter;
|
||||
if (!inSection) {
|
||||
if (keyword->name() == startKeywordName) {
|
||||
inSection = true;
|
||||
addKeyword(keyword);
|
||||
}
|
||||
} else {
|
||||
if (keyword->name() == startKeywordName)
|
||||
throw std::invalid_argument(std::string("Deck contains the '")+startKeywordName+"' section multiple times");
|
||||
|
||||
if (startKeywordIdx >= deck->size())
|
||||
if (isSectionDelimiter(keyword->name()))
|
||||
break;
|
||||
|
||||
addKeyword(keyword);
|
||||
}
|
||||
}
|
||||
if (!inSection)
|
||||
throw std::invalid_argument(std::string("Deck requires a '")+startKeywordName+"' section");
|
||||
|
||||
// make sure that the section identifier is unique
|
||||
for (size_t j = startKeywordIdx + 1; j < deck->size(); j++)
|
||||
if (deck->getKeyword(j)->name() == startKeywordName)
|
||||
throw std::invalid_argument(std::string("Deck contains the '")+startKeywordName+"' section multiple times");
|
||||
|
||||
// populate the section with keywords
|
||||
for (size_t curKeywordIdx = startKeywordIdx;
|
||||
curKeywordIdx < deck->size();
|
||||
curKeywordIdx++)
|
||||
{
|
||||
const std::string &keywordName = deck->getKeyword(curKeywordIdx)->name();
|
||||
if (curKeywordIdx > startKeywordIdx && isSectionDelimiter(keywordName))
|
||||
break;
|
||||
|
||||
m_keywords.addKeyword(deck->getKeyword(curKeywordIdx));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t Section::count(const std::string& keyword) const {
|
||||
return m_keywords.numKeywords( keyword );
|
||||
return numKeywords( keyword );
|
||||
}
|
||||
|
||||
const std::string& Section::name() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
bool Section::hasKeyword( const std::string& keyword ) const {
|
||||
return m_keywords.hasKeyword(keyword);
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordConstPtr>::iterator Section::begin() {
|
||||
return m_keywords.begin();
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordConstPtr>::iterator Section::end() {
|
||||
return m_keywords.end();
|
||||
}
|
||||
|
||||
DeckKeywordConstPtr Section::getKeyword(const std::string& keyword, size_t index) const {
|
||||
return m_keywords.getKeyword(keyword , index);
|
||||
}
|
||||
|
||||
DeckKeywordConstPtr Section::getKeyword(const std::string& keyword) const {
|
||||
return m_keywords.getKeyword(keyword);
|
||||
}
|
||||
|
||||
DeckKeywordConstPtr Section::getKeyword(size_t index) const {
|
||||
return m_keywords.getKeyword(index);
|
||||
}
|
||||
|
||||
bool Section::checkSectionTopology(DeckConstPtr deck,
|
||||
bool ensureKeywordSectionAffiliation)
|
||||
|
@ -20,26 +20,22 @@
|
||||
#ifndef SECTION_HPP
|
||||
#define SECTION_HPP
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class Section : public boost::iterator_facade<Section, DeckKeywordPtr, boost::forward_traversal_tag>
|
||||
class Section : public Deck
|
||||
{
|
||||
public:
|
||||
Section(DeckConstPtr deck, const std::string& startKeyword);
|
||||
bool hasKeyword( const std::string& keyword ) const;
|
||||
std::vector<DeckKeywordConstPtr>::iterator begin();
|
||||
std::vector<DeckKeywordConstPtr>::iterator end();
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword, size_t index) const;
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword) const;
|
||||
DeckKeywordConstPtr getKeyword(size_t index) const;
|
||||
const std::string& name() const;
|
||||
size_t count(const std::string& keyword) const;
|
||||
|
||||
@ -57,7 +53,6 @@ namespace Opm {
|
||||
bool ensureKeywordSectionAffiliation = false);
|
||||
|
||||
private:
|
||||
KeywordContainer m_keywords;
|
||||
std::string m_name;
|
||||
static bool isSectionDelimiter(const std::string& keywordName);
|
||||
static bool hasSection(DeckConstPtr deck, const std::string& startKeyword);
|
||||
|
@ -22,10 +22,6 @@ add_executable(runDeckTests DeckTests.cpp)
|
||||
target_link_libraries(runDeckTests Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runDeckTests COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runDeckTests )
|
||||
|
||||
add_executable(runKeywordContainerTests KeywordContainerTests.cpp)
|
||||
target_link_libraries(runKeywordContainerTests Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runKeywordContainerTests COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runKeywordContainerTests )
|
||||
|
||||
add_executable(runDeckKeywordTests DeckKeywordTests.cpp)
|
||||
target_link_libraries(runDeckKeywordTests Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runDeckKeywordTests COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runDeckKeywordTests )
|
||||
|
@ -122,6 +122,97 @@ BOOST_AUTO_TEST_CASE(size_twokeyword_return2) {
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_multipleKeyword_keywordReturned) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
deck.addKeyword(keyword1);
|
||||
deck.addKeyword(keyword2);
|
||||
deck.addKeyword(keyword3);
|
||||
|
||||
BOOST_CHECK_EQUAL(keyword1, deck.getKeyword("TRULS", 0));
|
||||
BOOST_CHECK_EQUAL(keyword3, deck.getKeyword("TRULS", 2));
|
||||
BOOST_CHECK_EQUAL(keyword3, deck.getKeyword("TRULS"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_outOfRange_throws) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
deck.addKeyword(keyword);
|
||||
BOOST_CHECK_THROW( deck.getKeyword("TRULS" , 3) , std::out_of_range)
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeywordList_notFound_throws) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
deck.addKeyword(keyword);
|
||||
BOOST_CHECK_THROW( deck.getKeywordList("TRULSX") , std::invalid_argument)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeywordList_OK) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
deck.addKeyword(keyword1);
|
||||
deck.addKeyword(keyword2);
|
||||
deck.addKeyword(keyword3);
|
||||
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = deck.getKeywordList("TRULS");
|
||||
BOOST_CHECK_EQUAL( 3U , keywordList.size() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keywordList_getnum_OK) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX"));
|
||||
deck.addKeyword(keyword1);
|
||||
deck.addKeyword(keyword2);
|
||||
deck.addKeyword(keyword3);
|
||||
|
||||
BOOST_CHECK_EQUAL( 0U , deck.numKeywords( "TRULSY" ));
|
||||
BOOST_CHECK_EQUAL( 2U , deck.numKeywords( "TRULS" ));
|
||||
BOOST_CHECK_EQUAL( 1U , deck.numKeywords( "TRULSX" ));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keywordList_getbyindexoutofbounds_exceptionthrown) {
|
||||
Deck deck;
|
||||
BOOST_CHECK_THROW(deck.getKeyword(0), std::out_of_range);
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX"));
|
||||
deck.addKeyword(keyword1);
|
||||
deck.addKeyword(keyword2);
|
||||
deck.addKeyword(keyword3);
|
||||
BOOST_CHECK_NO_THROW(deck.getKeyword(2));
|
||||
BOOST_CHECK_THROW(deck.getKeyword(3), std::out_of_range);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keywordList_getbyindex_correctkeywordreturned) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX"));
|
||||
deck.addKeyword(keyword1);
|
||||
deck.addKeyword(keyword2);
|
||||
deck.addKeyword(keyword3);
|
||||
BOOST_CHECK_EQUAL("TRULS", deck.getKeyword(0)->name());
|
||||
BOOST_CHECK_EQUAL("TRULS", deck.getKeyword(1)->name());
|
||||
BOOST_CHECK_EQUAL("TRULSX", deck.getKeyword(2)->name());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,174 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE KeywordContainerTests
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/Deck/KeywordContainer.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
KeywordContainer container;
|
||||
KeywordContainerPtr ptrContainer(new KeywordContainer());
|
||||
KeywordContainerConstPtr constPtrContainer(new KeywordContainer());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(hasKeyword_empty_returnsfalse) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
BOOST_CHECK_EQUAL(false, container->hasKeyword("Truls"));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addKeyword_keywordAdded_keywordAdded) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("Truls"));
|
||||
container->addKeyword(keyword);
|
||||
|
||||
BOOST_CHECK_EQUAL(true, container->hasKeyword("Truls"));
|
||||
BOOST_CHECK_EQUAL(1U, container->size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_nosuchkeyword_throws) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
BOOST_CHECK_THROW(container->getKeyword("TRULS" , 0), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_singleKeyword_keywordReturned) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
container->addKeyword(keyword);
|
||||
BOOST_CHECK_EQUAL(keyword, container->getKeyword("TRULS", 0));
|
||||
BOOST_CHECK_EQUAL(keyword, container->getKeyword("TRULS"));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_multipleKeyword_keywordReturned) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
container->addKeyword(keyword1);
|
||||
container->addKeyword(keyword2);
|
||||
container->addKeyword(keyword3);
|
||||
|
||||
BOOST_CHECK_EQUAL(keyword1, container->getKeyword("TRULS", 0));
|
||||
BOOST_CHECK_EQUAL(keyword3, container->getKeyword("TRULS", 2));
|
||||
BOOST_CHECK_EQUAL(keyword3, container->getKeyword("TRULS"));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_outOfRange_throws) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
container->addKeyword(keyword);
|
||||
BOOST_CHECK_THROW( container->getKeyword("TRULS" , 3) , std::out_of_range)
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeywordList_notFound_throws) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
container->addKeyword(keyword);
|
||||
BOOST_CHECK_THROW( container->getKeywordList("TRULSX") , std::invalid_argument)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeywordList_OK) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
container->addKeyword(keyword1);
|
||||
container->addKeyword(keyword2);
|
||||
container->addKeyword(keyword3);
|
||||
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = container->getKeywordList("TRULS");
|
||||
BOOST_CHECK_EQUAL( 3U , keywordList.size() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keywordList_getnum_OK) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX"));
|
||||
container->addKeyword(keyword1);
|
||||
container->addKeyword(keyword2);
|
||||
container->addKeyword(keyword3);
|
||||
|
||||
BOOST_CHECK_EQUAL( 0U , container->numKeywords( "TRULSY" ));
|
||||
BOOST_CHECK_EQUAL( 2U , container->numKeywords( "TRULS" ));
|
||||
BOOST_CHECK_EQUAL( 1U , container->numKeywords( "TRULSX" ));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keywordList_getbyindexoutofbounds_exceptionthrown) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
BOOST_CHECK_THROW(container->getKeyword(0), std::out_of_range);
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX"));
|
||||
container->addKeyword(keyword1);
|
||||
container->addKeyword(keyword2);
|
||||
container->addKeyword(keyword3);
|
||||
BOOST_CHECK_NO_THROW(container->getKeyword(2));
|
||||
BOOST_CHECK_THROW(container->getKeyword(3), std::out_of_range);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keywordList_getbyindex_correctkeywordreturned) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX"));
|
||||
container->addKeyword(keyword1);
|
||||
container->addKeyword(keyword2);
|
||||
container->addKeyword(keyword3);
|
||||
BOOST_CHECK_EQUAL("TRULS", container->getKeyword(0)->name());
|
||||
BOOST_CHECK_EQUAL("TRULS", container->getKeyword(1)->name());
|
||||
BOOST_CHECK_EQUAL("TRULSX", container->getKeyword(2)->name());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keywordList_canIterate) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX"));
|
||||
container->addKeyword(keyword1);
|
||||
container->addKeyword(keyword2);
|
||||
container->addKeyword(keyword3);
|
||||
int numberOfItems = 0;
|
||||
for (auto iter=container->begin(); iter != container->end(); ++iter) {
|
||||
std::cout << (*iter)->name() << std::endl;
|
||||
numberOfItems++;
|
||||
}
|
||||
BOOST_CHECK_EQUAL(3, numberOfItems);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user