Added size() property to DynamicState

This commit is contained in:
Joakim Hove
2013-11-15 15:58:06 +01:00
parent 468a2330f0
commit 3efe37dc37
2 changed files with 26 additions and 0 deletions

View File

@@ -50,6 +50,11 @@ namespace Opm {
}
size_t size() const {
return m_data.size();
}
void add(size_t index , T value) {
if (index >= (m_timeMap->size()))
throw std::range_error("Index value is out range.");

View File

@@ -109,3 +109,24 @@ BOOST_AUTO_TEST_CASE(DynamicStateAddIndexAlreadySetThrows) {
BOOST_AUTO_TEST_CASE(DynamicStateCheckSize) {
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
Opm::TimeMapPtr timeMap(new Opm::TimeMap(startDate));
Opm::DynamicState<int> state(timeMap , 137);
for (size_t i = 0; i < 10; i++)
timeMap->addTStep( boost::posix_time::hours( (i+1) * 24 ));
BOOST_CHECK_EQUAL( 0U , state.size() );
state.add( 0 , 10 );
BOOST_CHECK_EQUAL( 1U , state.size() );
state.add( 2 , 10 );
BOOST_CHECK_EQUAL( 3U , state.size() );
state.add( 2 , 10 );
BOOST_CHECK_EQUAL( 3U , state.size() );
state.add( 6 , 10 );
BOOST_CHECK_EQUAL( 7U , state.size() );
}