Added iget() and iset() methods to DynamicVector.

This commit is contained in:
Joakim Hove
2015-11-09 12:05:09 +01:00
parent b20f46649d
commit 2cd69fcbda
2 changed files with 36 additions and 0 deletions
@@ -68,6 +68,12 @@ namespace Opm {
}
const T& iget(size_t index) const {
return (*this)[index];
}
T& operator[](size_t index) {
if (index >= m_timeMap->size())
throw std::range_error("Index value is out range.");
@@ -78,6 +84,9 @@ namespace Opm {
return m_data[index];
}
void iset(size_t index, T value) {
(*this)[index] = value;
}
private:
@@ -68,3 +68,30 @@ BOOST_AUTO_TEST_CASE(DynamicVectorSet) {
BOOST_CHECK_THROW( state[5] = 99 , std::range_error);
}
BOOST_AUTO_TEST_CASE(DynamicVectorPtr) {
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
Opm::TimeMapPtr timeMap(new Opm::TimeMap(boost::posix_time::ptime(startDate)));
Opm::DynamicVector<int> * state = new Opm::DynamicVector<int>( timeMap , 137 );
for (size_t i = 0; i < 4; i++)
timeMap->addTStep( boost::posix_time::hours( (i+1) * 24 ));
BOOST_CHECK_EQUAL( 137 , state->iget(0) );
BOOST_CHECK_EQUAL( 137 , state->iget(1) );
BOOST_CHECK_EQUAL( 137 , state->iget(2) );
BOOST_CHECK_EQUAL( 137 , state->iget(3) );
BOOST_CHECK_EQUAL( 137 , state->iget(4) );
state->iset(2 , 99);
BOOST_CHECK_EQUAL( 137 , state->iget(1) );
BOOST_CHECK_EQUAL( 99 , state->iget(2) );
BOOST_CHECK_EQUAL( 137 , state->iget(3) );
state->iset(0,88);
BOOST_CHECK_EQUAL( 88 , state->iget(0));
BOOST_CHECK_THROW( state->iset(5 , 99) , std::range_error);
delete state;
}