mapnik::value - add missing specialisations for mapnik::value_bool in comparison operators + update unit tests

This commit is contained in:
artemp 2015-11-03 10:10:24 +00:00
parent dad4f64813
commit 2893ee4551
2 changed files with 149 additions and 17 deletions

View file

@ -137,12 +137,17 @@ struct not_equals
return lhs != rhs;
}
bool operator() (value_integer lhs, value_double rhs) const
bool operator() (value_bool lhs, value_double rhs) const
{
return static_cast<value_double>(lhs) != rhs;
}
bool operator() (value_bool lhs, value_double rhs) const
bool operator() (value_bool lhs, value_integer rhs) const
{
return static_cast<value_integer>(lhs) != rhs;
}
bool operator() (value_integer lhs, value_double rhs) const
{
return static_cast<value_double>(lhs) != rhs;
}
@ -152,11 +157,6 @@ struct not_equals
return lhs != static_cast<value_double>(rhs);
}
bool operator() (value_bool lhs, value_integer rhs) const
{
return static_cast<value_integer>(lhs) != rhs;
}
bool operator() (value_integer lhs, value_bool rhs) const
{
return lhs != static_cast<value_integer>(rhs);
@ -185,7 +185,6 @@ struct not_equals
};
struct greater_than
{
template <typename T, typename U>
bool operator()(const T &, const U &) const
@ -199,14 +198,34 @@ struct greater_than
return lhs > rhs;
}
bool operator() (value_bool lhs, value_double rhs) const
{
return static_cast<value_double>(lhs) > rhs;
}
bool operator() (value_double lhs, value_bool rhs) const
{
return lhs > static_cast<value_double>(rhs);
}
bool operator() (value_bool lhs, value_integer rhs) const
{
return static_cast<value_integer>(lhs) > rhs;
}
bool operator() (value_integer lhs, value_bool rhs) const
{
return lhs > static_cast<value_integer>(rhs);
}
bool operator() (value_integer lhs, value_double rhs) const
{
return lhs > rhs;
return static_cast<value_double>(lhs) > rhs;
}
bool operator() (value_double lhs, value_integer rhs) const
{
return lhs > rhs;
return static_cast<value_double>(lhs) > rhs;
}
bool operator() (value_unicode_string const& lhs, value_unicode_string const& rhs) const
@ -221,7 +240,6 @@ struct greater_than
};
struct greater_or_equal
{
template <typename T, typename U>
bool operator()(const T &, const U &) const
@ -235,14 +253,34 @@ struct greater_or_equal
return lhs >= rhs;
}
bool operator() (value_bool lhs, value_double rhs) const
{
return static_cast<value_double>(lhs) >= rhs;
}
bool operator() (value_double lhs, value_bool rhs) const
{
return lhs >= static_cast<value_double>(rhs);
}
bool operator() (value_bool lhs, value_integer rhs) const
{
return static_cast<value_integer>(lhs) >= rhs;
}
bool operator() (value_integer lhs, value_bool rhs) const
{
return lhs >= static_cast<value_integer>(rhs);
}
bool operator() (value_integer lhs, value_double rhs) const
{
return lhs >= rhs;
return static_cast<value_double>(lhs) >= rhs;
}
bool operator() (value_double lhs, value_integer rhs) const
{
return lhs >= rhs;
return lhs >= static_cast<value_double>(rhs);
}
bool operator() (value_unicode_string const& lhs, value_unicode_string const& rhs) const
@ -271,14 +309,34 @@ struct less_than
return lhs < rhs;
}
bool operator() (value_bool lhs, value_double rhs) const
{
return static_cast<value_double>(lhs) < rhs;
}
bool operator() (value_double lhs, value_bool rhs) const
{
return lhs < static_cast<value_double>(rhs);
}
bool operator() (value_bool lhs, value_integer rhs) const
{
return static_cast<value_integer>(lhs) < rhs;
}
bool operator() (value_integer lhs, value_bool rhs) const
{
return lhs < static_cast<value_integer>(rhs);
}
bool operator() (value_integer lhs, value_double rhs) const
{
return lhs < rhs;
return static_cast<value_double>(lhs) < rhs;
}
bool operator() (value_double lhs, value_integer rhs) const
{
return lhs < rhs;
return lhs < static_cast<value_double>(rhs);
}
bool operator()(value_unicode_string const& lhs,
@ -308,14 +366,34 @@ struct less_or_equal
return lhs <= rhs;
}
bool operator() (value_bool lhs, value_double rhs) const
{
return static_cast<value_double>(lhs) <= rhs;
}
bool operator() (value_double lhs, value_bool rhs) const
{
return lhs <= static_cast<value_double>(rhs);
}
bool operator() (value_bool lhs, value_integer rhs) const
{
return static_cast<value_integer>(lhs) <= rhs;
}
bool operator() (value_integer lhs, value_bool rhs) const
{
return lhs <= static_cast<value_integer>(rhs);
}
bool operator() (value_integer lhs, value_double rhs) const
{
return lhs <= rhs;
return static_cast<value_double>(lhs) <= rhs;
}
bool operator() (value_double lhs, value_integer rhs) const
{
return lhs <= rhs;
return lhs <= static_cast<value_double>(rhs);
}
bool operator()(value_unicode_string const& lhs,

View file

@ -45,4 +45,58 @@ TEST_CASE("comparison")
REQUIRE(v2 != v3);
}
SECTION("operator<,<=,>,>=")
{
mapnik::value v0 = 1;
mapnik::value v1 = 1.01;
mapnik::value v2 = true;
mapnik::value v3 = 2;
// value_integer | value_double
// 1 < 1.01 => true
// 1.01 > 1 => true
REQUIRE(v0 < v1);
REQUIRE(v1 > v0);
// 1 <= 1.01 => true
// 1.01 >= 1 => true
REQUIRE(v0 <= v1);
REQUIRE(v1 >= v0);
// value_bool | value_integer
// true < 1 => false
// true > 1 => false
REQUIRE(!(v2 < v0));
REQUIRE(!(v2 > v0));
// true <= 1 => true
// true >= 1 => true
REQUIRE(v2 <= v0);
REQUIRE(v2 >= v0);
// 1 > true => false
// 1 < true => false
REQUIRE(!(v0 > v2));
REQUIRE(!(v0 < v2));
// 1 >= true => true
// 1 <= true => true
REQUIRE(v0 >= v2);
REQUIRE(v0 <= v2);
// value_bool | value_doble
// true < 1.01 => true
// 1.01 > true => true
REQUIRE(v2 < v1);
REQUIRE(v1 > v2);
// true <= 1.01 => true
// 1.01 >= true => true
REQUIRE(v2 <= v1);
REQUIRE(v1 >= v2);
// value_integer | value_integer
// 1 < 2 => true
// 2 > 1 => true
REQUIRE(v0 < v3);
REQUIRE(v3 > v0);
// 1 <= 2 => true
// 2 >= 1 => true
REQUIRE(v0 <= v3);
REQUIRE(v3 >= v0);
}
}