Skip to content

Commit

Permalink
Merge pull request #35 from mapbox/property-comparison-operator
Browse files Browse the repository at this point in the history
add equality operator to vtzero::property
  • Loading branch information
joto authored Feb 21, 2018
2 parents 29c5718 + 0b10b28 commit 798b738
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/vtzero/property.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ namespace vtzero {

}; // class property

/// properties are equal if they contain the same key & value data.
inline constexpr bool operator==(const property& lhs, const property& rhs) noexcept {
return lhs.key() == rhs.key() && lhs.value() == rhs.value();
}

/// properties are unequal if they do not contain them same key and value data.
inline constexpr bool operator!=(const property& lhs, const property& rhs) noexcept {
return lhs.key() != rhs.key() || lhs.value() != rhs.value();
}

} // namespace vtzero

#endif // VTZERO_PROPERTY_HPP
32 changes: 32 additions & 0 deletions test/t/test_property_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,35 @@ TEST_CASE("create encoded property values from different bool types") {
REQUIRE(b1.hash() == b2.hash());
}

TEST_CASE("property equality comparison operator") {
std::string k = "key";

vtzero::encoded_property_value epv1{"value"};
vtzero::encoded_property_value epv2{"another value"};
vtzero::property_value pv1{epv1.data()};
vtzero::property_value pv2{epv2.data()};

vtzero::property p1{k, pv1};
vtzero::property p2{k, pv1};
vtzero::property p3{k, pv2};
REQUIRE(p1 == p2);
REQUIRE_FALSE(p1 == p3);
}

TEST_CASE("property inequality comparison operator") {
std::string k1 = "key";
std::string k2 = "another_key";

vtzero::encoded_property_value epv1{"value"};
vtzero::encoded_property_value epv2{"another value"};
vtzero::property_value pv1{epv1.data()};
vtzero::property_value pv2{epv2.data()};

vtzero::property p1{k1, pv1};
vtzero::property p2{k1, pv1};
vtzero::property p3{k1, pv2};
vtzero::property p4{k2, pv2};
REQUIRE_FALSE(p1 != p2);
REQUIRE(p1 != p3);
REQUIRE(p3 != p4);
}

0 comments on commit 798b738

Please sign in to comment.