]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/numbertest_doubleconversion.cpp
ICU-64252.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / numbertest_doubleconversion.cpp
1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #include "unicode/utypes.h"
5
6 #if !UCONFIG_NO_FORMATTING
7
8 #include "numbertest.h"
9 #include "double-conversion.h"
10
11 using namespace double_conversion;
12
13 void DoubleConversionTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
14 if (exec) {
15 logln("TestSuite DoubleConversionTest: ");
16 }
17 TESTCASE_AUTO_BEGIN;
18 TESTCASE_AUTO(testDoubleConversionApi);
19 TESTCASE_AUTO_END;
20 }
21
22 void DoubleConversionTest::testDoubleConversionApi() {
23 double v = 87.65;
24 char buffer[DoubleToStringConverter::kBase10MaximalLength + 1];
25 bool sign;
26 int32_t length;
27 int32_t point;
28
29 DoubleToStringConverter::DoubleToAscii(
30 v,
31 DoubleToStringConverter::DtoaMode::SHORTEST,
32 0,
33 buffer,
34 sizeof(buffer),
35 &sign,
36 &length,
37 &point
38 );
39
40 UnicodeString result(buffer, length);
41 assertEquals("Digits", u"8765", result);
42 assertEquals("Scale", 2, point);
43 }
44
45 #endif /* #if !UCONFIG_NO_FORMATTING */