Skip to content

Commit

Permalink
implement set_all for empty vector
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Voigt authored and Alexander Voigt committed Aug 26, 2016
1 parent 39bc8bb commit 1da8ee7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/gsl_vector.cpp
Expand Up @@ -163,7 +163,8 @@ gsl_vector* GSL_vector::raw() noexcept

void GSL_vector::set_all(double value) noexcept
{
gsl_vector_set_all(vec, value);
if (vec)
gsl_vector_set_all(vec, value);
}

std::ostream& operator<<(std::ostream& ostr, const GSL_vector& vec)
Expand Down
8 changes: 8 additions & 0 deletions test/test_gsl_vector.cpp
Expand Up @@ -204,6 +204,14 @@ BOOST_AUTO_TEST_CASE( test_set_all )
BOOST_CHECK_EQUAL(v[2], 1.);
}

BOOST_AUTO_TEST_CASE( test_set_all_empty )
{
GSL_vector v;
v.set_all(1.);

BOOST_CHECK_EQUAL(v.size(), 0);
}

BOOST_AUTO_TEST_CASE( test_move )
{
GSL_vector v(3);
Expand Down

0 comments on commit 1da8ee7

Please sign in to comment.