Skip to content

Commit

Permalink
Fix decrement operators for DiscreteVector
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau committed May 18, 2024
1 parent c009a9b commit 389553d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/ddc/discrete_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,15 @@ class DiscreteVector : public detail::DiscreteVectorConversionOperators<Discrete
template <std::size_t N = sizeof...(Tags), class = std::enable_if_t<N == 1>>
KOKKOS_FUNCTION constexpr DiscreteVector& operator--()
{
++m_values[0];
--m_values[0];
return *this;
}

template <std::size_t N = sizeof...(Tags), class = std::enable_if_t<N == 1>>
KOKKOS_FUNCTION constexpr DiscreteVector operator--(int)
{
DiscreteVector const tmp = *this;
++m_values[0];
--m_values[0];
return tmp;
}

Expand Down
36 changes: 36 additions & 0 deletions tests/discrete_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,42 @@ TEST(DiscreteVectorXYZTest, ConstructorFromDiscreteVectors)
EXPECT_EQ(ixyz.get<DDimZ>(), dv_z);
}

TEST(DiscreteVectorXTest, PreIncrement)
{
DVectX const ix0(3);
DVectX ix1(ix0);
DVectX const ix2 = ++ix1;
EXPECT_EQ(ix1, ix0 + 1);
EXPECT_EQ(ix2, ix0 + 1);
}

TEST(DiscreteVectorXTest, PostIncrement)
{
DVectX const ix0(3);
DVectX ix1(ix0);
DVectX const ix2 = ix1++;
EXPECT_EQ(ix1, ix0 + 1);
EXPECT_EQ(ix2, ix0);
}

TEST(DiscreteVectorXTest, PreDecrement)
{
DVectX const ix0(3);
DVectX ix1(ix0);
DVectX const ix2 = --ix1;
EXPECT_EQ(ix1, ix0 - 1);
EXPECT_EQ(ix2, ix0 - 1);
}

TEST(DiscreteVectorXTest, PostDecrement)
{
DVectX const ix0(3);
DVectX ix1(ix0);
DVectX const ix2 = ix1--;
EXPECT_EQ(ix1, ix0 - 1);
EXPECT_EQ(ix2, ix0);
}

TEST(DiscreteVectorTest, ExternalBinaryOperatorPlus)
{
std::size_t const dv_x = 7;
Expand Down

0 comments on commit 389553d

Please sign in to comment.