From fb7dc690d1c993ddc659592292b03a8f5ae9cc6a Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 10 Oct 2013 13:32:05 +0200 Subject: [PATCH] Added defaultApplied() method to DeckItem - and FAILING test --- opm/parser/eclipse/Deck/DeckIntItem.cpp | 2 +- opm/parser/eclipse/Deck/DeckItem.cpp | 6 +++ opm/parser/eclipse/Deck/DeckItem.hpp | 4 +- .../eclipse/Deck/tests/DeckIntItemTests.cpp | 10 +++++ .../eclipse/Parser/tests/ParserItemTests.cpp | 44 +++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/opm/parser/eclipse/Deck/DeckIntItem.cpp b/opm/parser/eclipse/Deck/DeckIntItem.cpp index 12c5f36a2..87c69f5c6 100644 --- a/opm/parser/eclipse/Deck/DeckIntItem.cpp +++ b/opm/parser/eclipse/Deck/DeckIntItem.cpp @@ -45,7 +45,7 @@ namespace Opm { push_back(data, data.size()); } - void DeckIntItem::push_back(int data) { + void DeckIntItem::push_back(int data) { m_data.push_back(data); } diff --git a/opm/parser/eclipse/Deck/DeckItem.cpp b/opm/parser/eclipse/Deck/DeckItem.cpp index 846af7d37..c1c146d03 100644 --- a/opm/parser/eclipse/Deck/DeckItem.cpp +++ b/opm/parser/eclipse/Deck/DeckItem.cpp @@ -23,9 +23,15 @@ namespace Opm { DeckItem::DeckItem(const std::string& name) { m_name = name; + m_defaultApplied = false; } const std::string& DeckItem::name() const { return m_name; } + + bool DeckItem::defaultApplied() const { + return m_defaultApplied; + } + } diff --git a/opm/parser/eclipse/Deck/DeckItem.hpp b/opm/parser/eclipse/Deck/DeckItem.hpp index 7960dbd46..1dfc2bbff 100644 --- a/opm/parser/eclipse/Deck/DeckItem.hpp +++ b/opm/parser/eclipse/Deck/DeckItem.hpp @@ -33,6 +33,8 @@ namespace Opm { DeckItem(const std::string& name); const std::string& name() const; + bool defaultApplied() const; + virtual size_t size() const = 0; virtual int getInt(size_t index) const { @@ -70,7 +72,7 @@ namespace Opm { } private: std::string m_name; - + bool m_defaultApplied; }; typedef boost::shared_ptr DeckItemPtr; typedef boost::shared_ptr DeckItemConstPtr; diff --git a/opm/parser/eclipse/Deck/tests/DeckIntItemTests.cpp b/opm/parser/eclipse/Deck/tests/DeckIntItemTests.cpp index 96ab1cc27..f0834a9c4 100644 --- a/opm/parser/eclipse/Deck/tests/DeckIntItemTests.cpp +++ b/opm/parser/eclipse/Deck/tests/DeckIntItemTests.cpp @@ -69,3 +69,13 @@ BOOST_AUTO_TEST_CASE(size_correct) { deckIntItem.push_back( 100 ); BOOST_CHECK_EQUAL( 3U , deckIntItem.size()); } + + + +BOOST_AUTO_TEST_CASE(DefaultApplied) { + DeckIntItem deckIntItem("TEST"); + BOOST_CHECK_EQUAL( false , deckIntItem.defaultApplied() ); +} + + + diff --git a/opm/parser/eclipse/Parser/tests/ParserItemTests.cpp b/opm/parser/eclipse/Parser/tests/ParserItemTests.cpp index 810aea404..150759f7d 100644 --- a/opm/parser/eclipse/Parser/tests/ParserItemTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserItemTests.cpp @@ -494,3 +494,47 @@ BOOST_AUTO_TEST_CASE(scan_intsAndStrings_dataCorrect) { BOOST_CHECK_EQUAL(3, deckItemInts->getInt(2)); BOOST_CHECK_EQUAL(3, deckItemInts->getInt(3)); } + + +BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) { + ParserIntItem itemInt("ITEM", SINGLE); + ParserIntItem itemString("ITEM", SINGLE); + ParserIntItem itemDouble("ITEM", SINGLE); + + { + RawRecordPtr rawRecord(new RawRecord("* /")); + DeckItemConstPtr deckStringItem = itemString.scan(rawRecord); + DeckItemConstPtr deckIntItem = itemInt.scan(rawRecord); + DeckItemConstPtr deckDoubleItem = itemDouble.scan(rawRecord); + + BOOST_CHECK( deckStringItem->defaultApplied() ); + BOOST_CHECK( deckIntItem->defaultApplied() ); + BOOST_CHECK( deckDoubleItem->defaultApplied() ); + } + + + { + RawRecordPtr rawRecord(new RawRecord("/")); + DeckItemConstPtr deckStringItem = itemString.scan(rawRecord); + DeckItemConstPtr deckIntItem = itemInt.scan(rawRecord); + DeckItemConstPtr deckDoubleItem = itemDouble.scan(rawRecord); + + BOOST_CHECK( deckStringItem->defaultApplied() ); + BOOST_CHECK( deckIntItem->defaultApplied() ); + BOOST_CHECK( deckDoubleItem->defaultApplied() ); + } + + + { + RawRecordPtr rawRecord(new RawRecord("10 /")); + DeckItemConstPtr deckStringItem = itemString.scan(rawRecord); + DeckItemConstPtr deckIntItem = itemInt.scan(rawRecord); + DeckItemConstPtr deckDoubleItem = itemDouble.scan(rawRecord); + + BOOST_CHECK_EQUAL( false , deckStringItem->defaultApplied() ); + BOOST_CHECK_EQUAL( false , deckIntItem->defaultApplied() ); + BOOST_CHECK_EQUAL( false , deckDoubleItem->defaultApplied() ); + } + +} +