mapnik::value - always upcast to the higher definition numeric value (rhs or lhs) in operator== and operator!=
add unit test for comparing numeric mapnik::values
This commit is contained in:
parent
499a2bdd74
commit
8c2f15c94a
2 changed files with 60 additions and 12 deletions
|
@ -72,42 +72,41 @@ using value_base = util::variant<value_null, value_bool, value_integer,value_dou
|
|||
namespace impl {
|
||||
|
||||
struct equals
|
||||
|
||||
{
|
||||
bool operator() (value_integer lhs, value_double rhs) const
|
||||
{
|
||||
return lhs == static_cast<value_integer>(rhs);
|
||||
return static_cast<value_double>(lhs) == rhs;
|
||||
}
|
||||
|
||||
bool operator() (value_bool lhs, value_double rhs) const
|
||||
{
|
||||
return lhs == static_cast<value_bool>(rhs);
|
||||
return static_cast<value_double>(lhs) == rhs;
|
||||
}
|
||||
|
||||
bool operator() (value_double lhs, value_integer rhs) const
|
||||
{
|
||||
return lhs == static_cast<value_double>(rhs);
|
||||
return lhs == static_cast<value_double>(rhs);
|
||||
}
|
||||
|
||||
bool operator() (value_bool lhs, value_integer rhs) const
|
||||
{
|
||||
return lhs == static_cast<value_bool>(rhs);
|
||||
return static_cast<value_integer>(lhs) == rhs;
|
||||
}
|
||||
|
||||
bool operator() (value_integer lhs, value_bool rhs) const
|
||||
{
|
||||
return lhs == static_cast<value_integer>(rhs);
|
||||
return lhs == static_cast<value_integer>(rhs);
|
||||
}
|
||||
|
||||
bool operator() (value_double lhs, value_bool rhs) const
|
||||
{
|
||||
return lhs == static_cast<value_double>(rhs);
|
||||
return static_cast<value_double>(lhs) == rhs;
|
||||
}
|
||||
|
||||
bool operator() (value_unicode_string const& lhs,
|
||||
value_unicode_string const& rhs) const
|
||||
{
|
||||
return (lhs == rhs) ? true: false;
|
||||
return (lhs == rhs) ? true: false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -140,12 +139,12 @@ struct not_equals
|
|||
|
||||
bool operator() (value_integer lhs, value_double rhs) const
|
||||
{
|
||||
return lhs != rhs;
|
||||
return static_cast<value_double>(lhs) != rhs;
|
||||
}
|
||||
|
||||
bool operator() (value_bool lhs, value_double rhs) const
|
||||
{
|
||||
return lhs != static_cast<value_bool>(rhs);
|
||||
return static_cast<value_double>(lhs) != rhs;
|
||||
}
|
||||
|
||||
bool operator() (value_double lhs, value_integer rhs) const
|
||||
|
@ -155,12 +154,12 @@ struct not_equals
|
|||
|
||||
bool operator() (value_bool lhs, value_integer rhs) const
|
||||
{
|
||||
return lhs != static_cast<value_bool>(rhs);
|
||||
return static_cast<value_integer>(lhs) != rhs;
|
||||
}
|
||||
|
||||
bool operator() (value_integer lhs, value_bool rhs) const
|
||||
{
|
||||
return lhs != static_cast<value_integer>(rhs);
|
||||
return lhs != static_cast<value_integer>(rhs);
|
||||
}
|
||||
|
||||
bool operator() (value_double lhs, value_bool rhs) const
|
||||
|
|
49
test/unit/core/comparison_test.cpp
Normal file
49
test/unit/core/comparison_test.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include "catch.hpp"
|
||||
|
||||
#include <mapnik/value_types.hpp>
|
||||
#include <mapnik/value.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
|
||||
TEST_CASE("comparison")
|
||||
{
|
||||
SECTION("operator==()")
|
||||
{
|
||||
mapnik::value v0 = 1; // mapnik::value_integer
|
||||
mapnik::value v1 = 1.001; // mapnik::value_double
|
||||
mapnik::value v2 = true; // mapnik::value_boolean
|
||||
|
||||
REQUIRE(!(v0 == v1));
|
||||
REQUIRE(!(v1 == v0));
|
||||
|
||||
REQUIRE(!(v1 == v2));
|
||||
REQUIRE(!(v2 == v1));
|
||||
|
||||
REQUIRE(v2 == v0);
|
||||
REQUIRE(v0 == v2);
|
||||
}
|
||||
|
||||
SECTION("operator!=()")
|
||||
{
|
||||
mapnik::value v0 = 1; // mapnik::value_integer
|
||||
mapnik::value v1 = 1.001; // mapnik::value_double
|
||||
mapnik::value v2 = true; // mapnik::value_boolean
|
||||
mapnik::value v3 = mapnik::value_null(); //
|
||||
|
||||
REQUIRE(v0 != v1);
|
||||
REQUIRE(v1 != v0);
|
||||
|
||||
REQUIRE(v1 != v2);
|
||||
REQUIRE(v2 != v1);
|
||||
|
||||
REQUIRE(!(v2 != v0));
|
||||
REQUIRE(!(v0 != v2));
|
||||
|
||||
REQUIRE(v3 != v0);
|
||||
REQUIRE(v3 != v1);
|
||||
REQUIRE(v3 != v2);
|
||||
REQUIRE(v0 != v3);
|
||||
REQUIRE(v1 != v3);
|
||||
REQUIRE(v2 != v3);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue