2016-03-03 19:53:58 +01:00
|
|
|
|
2015-09-24 18:35:17 +02:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
|
|
|
#include <mapnik/value_types.hpp>
|
|
|
|
#include <mapnik/value.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
|
|
|
|
|
2015-11-03 16:17:43 +01:00
|
|
|
CHECK(v0.is<mapnik::value_integer>());
|
|
|
|
CHECK(v1.is<mapnik::value_double>());
|
|
|
|
CHECK(v2.is<mapnik::value_bool>());
|
|
|
|
|
2015-09-24 18:35:17 +02:00
|
|
|
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(); //
|
|
|
|
|
2015-11-03 16:17:43 +01:00
|
|
|
CHECK(v0.is<mapnik::value_integer>());
|
|
|
|
CHECK(v1.is<mapnik::value_double>());
|
|
|
|
CHECK(v2.is<mapnik::value_bool>());
|
|
|
|
CHECK(v3.is<mapnik::value_null>());
|
|
|
|
|
2015-09-24 18:35:17 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
2015-11-03 11:10:24 +01:00
|
|
|
SECTION("operator<,<=,>,>=")
|
|
|
|
{
|
|
|
|
mapnik::value v0 = 1;
|
|
|
|
mapnik::value v1 = 1.01;
|
|
|
|
mapnik::value v2 = true;
|
|
|
|
mapnik::value v3 = 2;
|
2015-11-03 16:17:43 +01:00
|
|
|
|
|
|
|
CHECK(v0.is<mapnik::value_integer>());
|
|
|
|
CHECK(v1.is<mapnik::value_double>());
|
|
|
|
CHECK(v2.is<mapnik::value_bool>());
|
|
|
|
CHECK(v3.is<mapnik::value_integer>());
|
2015-11-03 11:10:24 +01:00
|
|
|
// 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);
|
|
|
|
}
|
2015-09-24 18:35:17 +02:00
|
|
|
}
|