|
|
@@ -103,4 +103,58 @@ public:
|
|
|
TS_ASSERT_THROWS(parse(bind(out, binder), data, allow_all),
|
|
|
json::json_numeric_width_exception);
|
|
|
}
|
|
|
-};
|
|
|
+
|
|
|
+ void test_double_number_written_is_equal_exact_binary() {
|
|
|
+ std::stringstream ss;
|
|
|
+ double in = 500., out = 0;
|
|
|
+ value_binder<double> binder{};
|
|
|
+ write(bind(in, binder), ss);
|
|
|
+ parse(bind(out, binder), ss.str().c_str(), allow_all);
|
|
|
+ TS_ASSERT_EQUALS(out, in);
|
|
|
+ }
|
|
|
+
|
|
|
+ void test_double_number_written_is_equal_inexact_binary() {
|
|
|
+ std::stringstream ss;
|
|
|
+ double in = 0.3, out = 0;
|
|
|
+ value_binder<double> binder{};
|
|
|
+ write(bind(in, binder), ss);
|
|
|
+ parse(bind(out, binder), ss.str().c_str(), allow_all);
|
|
|
+ TS_ASSERT_EQUALS(out, in);
|
|
|
+ }
|
|
|
+
|
|
|
+ void test_double_number_written_is_equal_at_high_absolute_value() {
|
|
|
+ std::stringstream ss;
|
|
|
+ double in = 1.34e300, out = 0.0;
|
|
|
+ value_binder<double> binder{};
|
|
|
+ write(bind(in, binder), ss);
|
|
|
+ parse(bind(out, binder), ss.str().c_str(), allow_all);
|
|
|
+ TS_ASSERT_EQUALS(out, in);
|
|
|
+ }
|
|
|
+
|
|
|
+ void test_double_number_written_is_equal_at_low_absolute_value() {
|
|
|
+ std::stringstream ss;
|
|
|
+ double in = 1.34e-300, out = 0.0;
|
|
|
+ value_binder<double> binder{};
|
|
|
+ write(bind(in, binder), ss);
|
|
|
+ parse(bind(out, binder), ss.str().c_str(), allow_all);
|
|
|
+ TS_ASSERT_DELTA(out, in, 1e-299);
|
|
|
+ }
|
|
|
+
|
|
|
+ void test_double_number_written_is_equal_at_high_absolute_value_nonscientific() {
|
|
|
+ std::stringstream ss;
|
|
|
+ double in = 52450012.25, out = 0.0;
|
|
|
+ value_binder<double> binder{};
|
|
|
+ write(bind(in, binder), ss);
|
|
|
+ parse(bind(out, binder), ss.str().c_str(), allow_all);
|
|
|
+ TS_ASSERT_EQUALS(out, in);
|
|
|
+ }
|
|
|
+
|
|
|
+ void test_double_number_written_is_equal_at_low_absolute_value_nonscientific() {
|
|
|
+ std::stringstream ss;
|
|
|
+ double in = 0.0002517867, out = 0.0;
|
|
|
+ value_binder<double> binder{};
|
|
|
+ write(bind(in, binder), ss);
|
|
|
+ parse(bind(out, binder), ss.str().c_str(), allow_all);
|
|
|
+ TS_ASSERT_DELTA(out, in, 0.000001);
|
|
|
+ }
|
|
|
+};
|