fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / rapidjson-1.1.0 / test / unittest / dtoatest.cpp
1 // Tencent is pleased to support the open source community by making RapidJSON available.
2 // 
3 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 //
5 // Licensed under the MIT License (the "License"); you may not use this file except
6 // in compliance with the License. You may obtain a copy of the License at
7 //
8 // http://opensource.org/licenses/MIT
9 //
10 // Unless required by applicable law or agreed to in writing, software distributed 
11 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
12 // CONDITIONS OF ANY KIND, either express or implied. See the License for the 
13 // specific language governing permissions and limitations under the License.
14
15 #include "unittest.h"
16 #include "rapidjson/internal/dtoa.h"
17
18 #ifdef __GNUC__
19 RAPIDJSON_DIAG_PUSH
20 RAPIDJSON_DIAG_OFF(type-limits)
21 #endif
22
23 using namespace rapidjson::internal;
24
25 TEST(dtoa, normal) {
26     char buffer[30];
27
28 #define TEST_DTOA(d, a)\
29     *dtoa(d, buffer) = '\0';\
30     EXPECT_STREQ(a, buffer)
31
32     TEST_DTOA(0.0, "0.0");
33     TEST_DTOA(-0.0, "-0.0");
34     TEST_DTOA(1.0, "1.0");
35     TEST_DTOA(-1.0, "-1.0");
36     TEST_DTOA(1.2345, "1.2345");
37     TEST_DTOA(1.2345678, "1.2345678");
38     TEST_DTOA(0.123456789012, "0.123456789012");
39     TEST_DTOA(1234567.8, "1234567.8");
40     TEST_DTOA(-79.39773355813419, "-79.39773355813419");
41     TEST_DTOA(0.000001, "0.000001");
42     TEST_DTOA(0.0000001, "1e-7");
43     TEST_DTOA(1e30, "1e30");
44     TEST_DTOA(1.234567890123456e30, "1.234567890123456e30");
45     TEST_DTOA(5e-324, "5e-324"); // Min subnormal positive double
46     TEST_DTOA(2.225073858507201e-308, "2.225073858507201e-308"); // Max subnormal positive double
47     TEST_DTOA(2.2250738585072014e-308, "2.2250738585072014e-308"); // Min normal positive double
48     TEST_DTOA(1.7976931348623157e308, "1.7976931348623157e308"); // Max double
49
50 #undef TEST_DTOA
51 }
52
53 TEST(dtoa, maxDecimalPlaces) {
54     char buffer[30];
55
56 #define TEST_DTOA(m, d, a)\
57     *dtoa(d, buffer, m) = '\0';\
58     EXPECT_STREQ(a, buffer)
59
60     TEST_DTOA(3, 0.0, "0.0");
61     TEST_DTOA(1, 0.0, "0.0");
62     TEST_DTOA(3, -0.0, "-0.0");
63     TEST_DTOA(3, 1.0, "1.0");
64     TEST_DTOA(3, -1.0, "-1.0");
65     TEST_DTOA(3, 1.2345, "1.234");
66     TEST_DTOA(2, 1.2345, "1.23");
67     TEST_DTOA(1, 1.2345, "1.2");
68     TEST_DTOA(3, 1.2345678, "1.234");
69     TEST_DTOA(3, 1.0001, "1.0");
70     TEST_DTOA(2, 1.0001, "1.0");
71     TEST_DTOA(1, 1.0001, "1.0");
72     TEST_DTOA(3, 0.123456789012, "0.123");
73     TEST_DTOA(2, 0.123456789012, "0.12");
74     TEST_DTOA(1, 0.123456789012, "0.1");
75     TEST_DTOA(4, 0.0001, "0.0001");
76     TEST_DTOA(3, 0.0001, "0.0");
77     TEST_DTOA(2, 0.0001, "0.0");
78     TEST_DTOA(1, 0.0001, "0.0");
79     TEST_DTOA(3, 1234567.8, "1234567.8");
80     TEST_DTOA(3, 1e30, "1e30");
81     TEST_DTOA(3, 5e-324, "0.0"); // Min subnormal positive double
82     TEST_DTOA(3, 2.225073858507201e-308, "0.0"); // Max subnormal positive double
83     TEST_DTOA(3, 2.2250738585072014e-308, "0.0"); // Min normal positive double
84     TEST_DTOA(3, 1.7976931348623157e308, "1.7976931348623157e308"); // Max double
85     TEST_DTOA(5, -0.14000000000000001, "-0.14");
86     TEST_DTOA(4, -0.14000000000000001, "-0.14");
87     TEST_DTOA(3, -0.14000000000000001, "-0.14");
88     TEST_DTOA(3, -0.10000000000000001, "-0.1");
89     TEST_DTOA(2, -0.10000000000000001, "-0.1");
90     TEST_DTOA(1, -0.10000000000000001, "-0.1");
91
92 #undef TEST_DTOA
93 }
94
95
96 #ifdef __GNUC__
97 RAPIDJSON_DIAG_POP
98 #endif