json/schema: add multipleOf test cases

This commit is contained in:
Danny Robson 2018-07-12 16:21:56 +10:00
parent 0629ba07cd
commit a2e2d59c98
10 changed files with 37 additions and 0 deletions

View File

@ -35,6 +35,7 @@ base::instantiate (std::string const &name, ::json::tree::node const &def)
if (name == "minimum") return std::make_unique<minimum> (def); if (name == "minimum") return std::make_unique<minimum> (def);
if (name == "exclusiveMaximum") return std::make_unique<exclusive_maximum> (def); if (name == "exclusiveMaximum") return std::make_unique<exclusive_maximum> (def);
if (name == "exclusiveMinimum") return std::make_unique<exclusive_minimum> (def); if (name == "exclusiveMinimum") return std::make_unique<exclusive_minimum> (def);
if (name == "multipleOf") return std::make_unique<multiple_of > (def);
if (name == "maximum") return std::make_unique<maximum> (def); if (name == "maximum") return std::make_unique<maximum> (def);
if (name == "properties") return std::make_unique<properties> (def); if (name == "properties") return std::make_unique<properties> (def);
if (name == "patternProperties") return std::make_unique<pattern_properties> (def); if (name == "patternProperties") return std::make_unique<pattern_properties> (def);

View File

@ -75,3 +75,16 @@ template class util::json::schema::constraint::inequality<std::less_equal>;
template class util::json::schema::constraint::inequality<std::greater_equal>; template class util::json::schema::constraint::inequality<std::greater_equal>;
template class util::json::schema::constraint::inequality<std::less>; template class util::json::schema::constraint::inequality<std::less>;
template class util::json::schema::constraint::inequality<std::greater>; template class util::json::schema::constraint::inequality<std::greater>;
///////////////////////////////////////////////////////////////////////////////
template <>
bool
util::json::schema::constraint::is_multiple<double>::operator() (double a, double b) const noexcept
{
return std::fmod (a, b) <= 1e-8;
}
//-----------------------------------------------------------------------------
template class util::json::schema::constraint::inequality<util::json::schema::constraint::is_multiple>;

View File

@ -48,4 +48,14 @@ namespace util::json::schema::constraint {
using maximum = inequality<std::less_equal>; using maximum = inequality<std::less_equal>;
using exclusive_minimum = inequality<std::greater>; using exclusive_minimum = inequality<std::greater>;
using exclusive_maximum = inequality<std::less>; using exclusive_maximum = inequality<std::less>;
// this is not technically an inequality, but the implementation fits in
// nicely here.
template <typename T>
struct is_multiple {
bool operator() (T, T) const noexcept;
};
using multiple_of = inequality<is_multiple>;
} }

View File

@ -0,0 +1,4 @@
{
"description": "multipleOf must be strictly greater than zero",
"multipleOf": 0
}

View File

@ -0,0 +1,4 @@
{
"description": "multipleOf must be strictly greater than zero",
"multipleOf": -1
}

View File

@ -0,0 +1 @@
{ "type": "number", "multipleOf": 1.5 }