mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-28 20:15:24 +08:00
Add test code for precision
This commit is contained in:
parent
38022157b2
commit
9fd1ca8d68
@ -1675,6 +1675,43 @@ JSONTEST_FIXTURE(ValueTest, specialFloats) {
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE(ValueTest, precision) {
|
||||
Json::StreamWriterBuilder b;
|
||||
b.settings_["precision"] = 5;
|
||||
|
||||
Json::Value v = 100.0/3;
|
||||
std::string expected = "33.333";
|
||||
std::string result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
|
||||
v = 0.25000000;
|
||||
expected = "0.25";
|
||||
result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
|
||||
v = 0.2563456;
|
||||
expected = "0.25635";
|
||||
result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
|
||||
b.settings_["precision"] = 1;
|
||||
expected = "0.3";
|
||||
result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
|
||||
b.settings_["precision"] = 17;
|
||||
v = 1234857476305.256345694873740545068;
|
||||
expected = "1234857476305.2563";
|
||||
result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
|
||||
b.settings_["precision"] = 24;
|
||||
v = 0.256345694873740545068;
|
||||
expected = "0.25634569487374054";
|
||||
result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
}
|
||||
|
||||
struct WriterTest : JsonTest::TestCase {};
|
||||
|
||||
JSONTEST_FIXTURE(WriterTest, dropNullPlaceholders) {
|
||||
@ -2489,6 +2526,7 @@ int main(int argc, const char* argv[]) {
|
||||
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroes);
|
||||
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroesInKeys);
|
||||
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, specialFloats);
|
||||
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, precision);
|
||||
|
||||
JSONTEST_REGISTER_FIXTURE(runner, WriterTest, dropNullPlaceholders);
|
||||
JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, dropNullPlaceholders);
|
||||
|
Loading…
x
Reference in New Issue
Block a user