Add operator!= for duration (#1236) (#1278)

Signed-off-by: Jannik Abbenseth <jannik.abbenseth@ipa.fraunhofer.de>

Co-authored-by: Jannik Abbenseth <ipa-jba@users.noreply.github.com>
This commit is contained in:
Ivan Santiago Paunovic 2020-08-18 09:58:50 -03:00 committed by GitHub
parent 27e59d930a
commit 75f3d54d57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View file

@ -77,6 +77,9 @@ public:
bool bool
operator==(const rclcpp::Duration & rhs) const; operator==(const rclcpp::Duration & rhs) const;
bool
operator!=(const rclcpp::Duration & rhs) const;
bool bool
operator<(const rclcpp::Duration & rhs) const; operator<(const rclcpp::Duration & rhs) const;

View file

@ -96,6 +96,12 @@ Duration::operator==(const rclcpp::Duration & rhs) const
return rcl_duration_.nanoseconds == rhs.rcl_duration_.nanoseconds; return rcl_duration_.nanoseconds == rhs.rcl_duration_.nanoseconds;
} }
bool
Duration::operator!=(const rclcpp::Duration & rhs) const
{
return rcl_duration_.nanoseconds != rhs.rcl_duration_.nanoseconds;
}
bool bool
Duration::operator<(const rclcpp::Duration & rhs) const Duration::operator<(const rclcpp::Duration & rhs) const
{ {

View file

@ -45,6 +45,7 @@ TEST(TestDuration, operators) {
EXPECT_TRUE(old <= young); EXPECT_TRUE(old <= young);
EXPECT_TRUE(young >= old); EXPECT_TRUE(young >= old);
EXPECT_FALSE(young == old); EXPECT_FALSE(young == old);
EXPECT_TRUE(young != old);
rclcpp::Duration add = old + young; rclcpp::Duration add = old + young;
EXPECT_EQ(add.nanoseconds(), old.nanoseconds() + young.nanoseconds()); EXPECT_EQ(add.nanoseconds(), old.nanoseconds() + young.nanoseconds());