MQTTSuite
Loading...
Searching...
No Matches
issue-293.cpp
Go to the documentation of this file.
1#include "nlohmann/json-schema.hpp"
2
3using nlohmann::json_schema::json_validator;
4
5template <typename T>
6int should_throw(const nlohmann::json &schema, T value)
7{
8 try {
9 json_validator(schema).validate(value);
10 } catch (const std::exception &ex) {
11 return 0;
12 }
13 return 1;
14}
15
16int main(void)
17{
18
19 json_validator({{"type", "number"}, {"multipleOf", 0.001}}).validate(0.3 - 0.2);
20 json_validator({{"type", "number"}, {"multipleOf", 3.3}}).validate(8.0 - 1.4);
21 json_validator({{"type", "number"}, {"multipleOf", 1000.01}}).validate((1000.03 - 0.02) * 15.0);
22 json_validator({{"type", "number"}, {"multipleOf", 0.001}}).validate(0.030999999999999993);
23 json_validator({{"type", "number"}, {"multipleOf", 0.100000}}).validate(1.9);
24 json_validator({{"type", "number"}, {"multipleOf", 100000.1}}).validate(9000009);
25
26 int exc_count = 0;
27 exc_count += should_throw({{"type", "number"}, {"multipleOf", 0.001}}, 0.3 - 0.2005);
28 exc_count += should_throw({{"type", "number"}, {"multipleOf", 1000.02}}, (1000.03 - 0.02) * 15.0);
29 exc_count += should_throw({{"type", "number"}, {"multipleOf", 100000.11}}, 9000009);
30
31 return exc_count;
32}
json_validator(json &&, schema_loader=nullptr, format_checker=nullptr, content_checker=nullptr)
json_validator(const json &, schema_loader=nullptr, format_checker=nullptr, content_checker=nullptr)
int main()
Definition format.cpp:34
int should_throw(const nlohmann::json &schema, T value)
Definition issue-293.cpp:6