Skip to content

Commit

Permalink
[#53] Fix operator++/-- in NumericTypeWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Mi-La committed Dec 13, 2024
1 parent 19822bb commit fe9c611
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions runtime/src/zserio/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class NumericTypeWrapper

constexpr NumericTypeWrapper operator++(int) noexcept
{
NumericTypeWrapper old;
NumericTypeWrapper old = *this;
operator++();
return old;
}
Expand All @@ -96,7 +96,7 @@ class NumericTypeWrapper

constexpr NumericTypeWrapper operator--(int) noexcept
{
NumericTypeWrapper old;
NumericTypeWrapper old = *this;
operator--();
return old;
}
Expand Down
33 changes: 21 additions & 12 deletions runtime/test/zserio/TypesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ void testIntOperators(typename T::ValueType minValue = NumericLimits<T>::min())
}

// increment / decrement
++value;
--value;
value++;
value--;
Int64 origValue = value;
ASSERT_EQ(origValue + 1, ++value);
ASSERT_EQ(origValue, --value);
ASSERT_EQ(origValue, value++);
ASSERT_EQ(origValue + 1, value);
ASSERT_EQ(origValue + 1, value--);
ASSERT_EQ(origValue, value);

// logical
ASSERT_FALSE(!valueMin);
Expand Down Expand Up @@ -133,10 +136,13 @@ void testUIntOperators(typename T::ValueType minValue = NumericLimits<T>::min())
}

// increment / decrement
++value;
--value;
value++;
value--;
UInt64 origValue = value;
ASSERT_EQ(origValue + 1, ++value);
ASSERT_EQ(origValue, --value);
ASSERT_EQ(origValue, value++);
ASSERT_EQ(origValue + 1, value);
ASSERT_EQ(origValue + 1, value--);
ASSERT_EQ(origValue, value);

// logical
ASSERT_FALSE(!valueMax);
Expand Down Expand Up @@ -210,10 +216,13 @@ void testFloatOperators()
value = valueMax / valueMin;

// increment / decrement
++value;
--value;
value++;
value--;
FloatWrapper origValue = value;
ASSERT_DOUBLE_EQ(origValue + 1, ++value);
ASSERT_DOUBLE_EQ(origValue, --value);
ASSERT_DOUBLE_EQ(origValue, value++);
ASSERT_DOUBLE_EQ(origValue + 1, value);
ASSERT_DOUBLE_EQ(origValue + 1, value--);
ASSERT_DOUBLE_EQ(origValue, value);

// comparison
ASSERT_TRUE(valueMin < valueMax);
Expand Down

0 comments on commit fe9c611

Please sign in to comment.