Merge pull request #912 from joakim-hove/windowed-array-zero-size

Add invalid size zero in WindowArray and WindowMatrix
This commit is contained in:
Bård Skaflestad
2019-07-29 07:56:38 -05:00
committed by GitHub
2 changed files with 21 additions and 2 deletions

View File

@@ -72,7 +72,10 @@ namespace Opm { namespace RestartIO { namespace Helpers {
explicit WindowedArray(const NumWindows n, const WindowSize sz)
: x_ (n.value * sz.value)
, windowSize_(sz.value)
{}
{
if (sz.value == 0)
throw std::invalid_argument("Window array with windowsize==0 is not permitted");
}
/// Retrieve number of windows allocated for this array.
Idx numWindows() const
@@ -179,7 +182,10 @@ namespace Opm { namespace RestartIO { namespace Helpers {
const WindowSize& sz)
: data_ (NumWindows{ nRows.value * nCols.value }, sz)
, numCols_(nCols.value)
{}
{
if (nCols.value == 0)
throw std::invalid_argument("Window matrix with columns==0 is not permitted");
}
/// Retrieve number of columns allocated for this matrix.
Idx numCols() const

View File

@@ -30,6 +30,19 @@
BOOST_AUTO_TEST_SUITE(WriteOperations)
BOOST_AUTO_TEST_CASE(EmptyArray)
{
using Wa = Opm::RestartIO::Helpers::WindowedArray<int>;
using Wm = Opm::RestartIO::Helpers::WindowedMatrix<int>;
BOOST_CHECK_NO_THROW( Wa( Wa::NumWindows{ 0 }, Wa::WindowSize{ 1 }) );
BOOST_CHECK_NO_THROW( Wm( Wm::NumRows{ 0 }, Wm::NumCols{ 2 }, Wm::WindowSize{ 3 } ));
BOOST_CHECK_THROW( Wa(Wa::NumWindows{ 5 }, Wa::WindowSize{ 0 }), std::invalid_argument);
BOOST_CHECK_THROW( Wm(Wm::NumRows{ 3 }, Wm::NumCols{ 0 }, Wm::WindowSize{ 4 } ), std::invalid_argument);
BOOST_CHECK_THROW( Wm(Wm::NumRows{ 3 }, Wm::NumCols{ 2 }, Wm::WindowSize{ 0 } ), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(Array)
{
using Wa = Opm::RestartIO::Helpers::WindowedArray<int>;