14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#include "ecmascript/base/number_helper.h"
174514f5e3Sopenharmony_ci#include "ecmascript/tests/test_helper.h"
184514f5e3Sopenharmony_ci
194514f5e3Sopenharmony_ciusing namespace panda::ecmascript;
204514f5e3Sopenharmony_ciusing namespace panda::ecmascript::base;
214514f5e3Sopenharmony_ci
224514f5e3Sopenharmony_cinamespace panda::test {
234514f5e3Sopenharmony_ciclass NumberHelperTest : public BaseTestWithScope<false> {
244514f5e3Sopenharmony_ci};
254514f5e3Sopenharmony_ci
264514f5e3Sopenharmony_ci/**
274514f5e3Sopenharmony_ci * @tc.name: IsNaN
284514f5e3Sopenharmony_ci * @tc.desc: Check whether number is Nan type data through "IsNaN" function.
294514f5e3Sopenharmony_ci * @tc.type: FUNC
304514f5e3Sopenharmony_ci * @tc.require:
314514f5e3Sopenharmony_ci */
324514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, IsNaN)
334514f5e3Sopenharmony_ci{
344514f5e3Sopenharmony_ci    JSTaggedValue number1(1.23);
354514f5e3Sopenharmony_ci    EXPECT_FALSE(NumberHelper::IsNaN(number1));
364514f5e3Sopenharmony_ci
374514f5e3Sopenharmony_ci    JSTaggedValue number2(-1.23);
384514f5e3Sopenharmony_ci    EXPECT_FALSE(NumberHelper::IsNaN(number2));
394514f5e3Sopenharmony_ci
404514f5e3Sopenharmony_ci    JSTaggedValue number3(0.0f);
414514f5e3Sopenharmony_ci    EXPECT_FALSE(NumberHelper::IsNaN(number3));
424514f5e3Sopenharmony_ci
434514f5e3Sopenharmony_ci    JSTaggedValue number4(0.0f / 0.0f);
444514f5e3Sopenharmony_ci    EXPECT_TRUE(NumberHelper::IsNaN(number4));
454514f5e3Sopenharmony_ci
464514f5e3Sopenharmony_ci    JSTaggedValue number5(NAN_VALUE);
474514f5e3Sopenharmony_ci    EXPECT_TRUE(NumberHelper::IsNaN(number5));
484514f5e3Sopenharmony_ci}
494514f5e3Sopenharmony_ci
504514f5e3Sopenharmony_ci/**
514514f5e3Sopenharmony_ci * @tc.name: DoubleToString
524514f5e3Sopenharmony_ci * @tc.desc: This function Convert the double type data into a string.first convert it into the corresponding
534514f5e3Sopenharmony_ci *           hexadecimal number according to the transmitted radix, and convert the hexadecimal number into a
544514f5e3Sopenharmony_ci *           string.
554514f5e3Sopenharmony_ci * @tc.type: FUNC
564514f5e3Sopenharmony_ci * @tc.require:
574514f5e3Sopenharmony_ci */
584514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToString_001)
594514f5e3Sopenharmony_ci{
604514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
614514f5e3Sopenharmony_ci    int radix;
624514f5e3Sopenharmony_ci    radix = 2;
634514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr = factory->NewFromASCII("100101");
644514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr1(thread, NumberHelper::DoubleToString(thread, 37, radix));
654514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr1, resultStr), 0);
664514f5e3Sopenharmony_ci
674514f5e3Sopenharmony_ci    radix = 3;
684514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("-1101");
694514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr2(thread, NumberHelper::DoubleToString(thread, -37, radix));
704514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr2, resultStr), 0);
714514f5e3Sopenharmony_ci
724514f5e3Sopenharmony_ci    radix = 4;
734514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("211");
744514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr3(thread, NumberHelper::DoubleToString(thread, 37, radix));
754514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr3, resultStr), 0);
764514f5e3Sopenharmony_ci
774514f5e3Sopenharmony_ci    radix = 5;
784514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("122");
794514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr4(thread, NumberHelper::DoubleToString(thread, 37, radix));
804514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr4, resultStr), 0);
814514f5e3Sopenharmony_ci
824514f5e3Sopenharmony_ci    radix = 5;
834514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("-1104332401304422434310320000");
844514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr5(thread,
854514f5e3Sopenharmony_ci        NumberHelper::DoubleToString(thread, static_cast<double>(-9223372036854775807), radix));
864514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr5, resultStr), 0);
874514f5e3Sopenharmony_ci
884514f5e3Sopenharmony_ci    radix = 6;
894514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("101");
904514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr6(thread, NumberHelper::DoubleToString(thread, 37, radix));
914514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr6, resultStr), 0);
924514f5e3Sopenharmony_ci
934514f5e3Sopenharmony_ci    radix = 7;
944514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("52");
954514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr7(thread, NumberHelper::DoubleToString(thread, 37, radix));
964514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr7, resultStr), 0);
974514f5e3Sopenharmony_ci
984514f5e3Sopenharmony_ci    radix = 36;
994514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("11");
1004514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr8(thread, NumberHelper::DoubleToString(thread, 37, radix));
1014514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr8, resultStr), 0);
1024514f5e3Sopenharmony_ci}
1034514f5e3Sopenharmony_ci
1044514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToString_002)
1054514f5e3Sopenharmony_ci{
1064514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1074514f5e3Sopenharmony_ci    int radix = 2;
1084514f5e3Sopenharmony_ci
1094514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr =
1104514f5e3Sopenharmony_ci        factory->NewFromASCII("10.111111011011000110000101010010001010100110111101");
1114514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr1(thread, NumberHelper::DoubleToString(thread, 2.99099, radix));
1124514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr1, resultStr), 0);
1134514f5e3Sopenharmony_ci
1144514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("10.000000101001000000000011111011101010001000001001101");
1154514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr2(thread, NumberHelper::DoubleToString(thread, 2.01001, radix));
1164514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr2, resultStr), 0);
1174514f5e3Sopenharmony_ci
1184514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("10.100000000000011010001101101110001011101011000111001");
1194514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr3(thread, NumberHelper::DoubleToString(thread, 2.5001, radix));
1204514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr3, resultStr), 0);
1214514f5e3Sopenharmony_ci
1224514f5e3Sopenharmony_ci    radix = 36;
1234514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0.i04nym8equ");
1244514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr4(thread, NumberHelper::DoubleToString(thread, 0.5001, radix));
1254514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr4, resultStr), 0);
1264514f5e3Sopenharmony_ci
1274514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0.wej2d0mt58f");
1284514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr5(thread, NumberHelper::DoubleToString(thread, 0.9001, radix));
1294514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr5, resultStr), 0);
1304514f5e3Sopenharmony_ci
1314514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0.0d384dldb02");
1324514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr6(thread, NumberHelper::DoubleToString(thread, 0.0101, radix));
1334514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr6, resultStr), 0);
1344514f5e3Sopenharmony_ci}
1354514f5e3Sopenharmony_ci
1364514f5e3Sopenharmony_ci/**
1374514f5e3Sopenharmony_ci * @tc.name: DoubleToEcmaString
1384514f5e3Sopenharmony_ci * @tc.desc: This function Convert the double type data into a EcmaString.
1394514f5e3Sopenharmony_ci * @tc.type: FUNC
1404514f5e3Sopenharmony_ci * @tc.require:
1414514f5e3Sopenharmony_ci */
1424514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToEcmaString)
1434514f5e3Sopenharmony_ci{
1444514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1454514f5e3Sopenharmony_ci
1464514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr1 =
1474514f5e3Sopenharmony_ci        factory->NewFromASCII("5562684646268003");
1484514f5e3Sopenharmony_ci    double d1 = 5562684646268003;
1494514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle1 = NumberHelper::DoubleToEcmaString(thread, d1);
1504514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle1, resultStr1), 0);
1514514f5e3Sopenharmony_ci
1524514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr2 =
1534514f5e3Sopenharmony_ci        factory->NewFromASCII("0.005431");
1544514f5e3Sopenharmony_ci    double d2 = 0.005431;
1554514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle2 = NumberHelper::DoubleToEcmaString(thread, d2);
1564514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle2, resultStr2), 0);
1574514f5e3Sopenharmony_ci
1584514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr3 =
1594514f5e3Sopenharmony_ci        factory->NewFromASCII("1.9045e-7");
1604514f5e3Sopenharmony_ci    double d3 = 0.00000019045;
1614514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle3 = NumberHelper::DoubleToEcmaString(thread, d3);
1624514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle3, resultStr3), 0);
1634514f5e3Sopenharmony_ci
1644514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr4 =
1654514f5e3Sopenharmony_ci        factory->NewFromASCII("-79.39773355813419");
1664514f5e3Sopenharmony_ci    double d4 = -79.39773355813419;
1674514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle4 = NumberHelper::DoubleToEcmaString(thread, d4);
1684514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle4, resultStr4), 0);
1694514f5e3Sopenharmony_ci
1704514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr5 =
1714514f5e3Sopenharmony_ci        factory->NewFromASCII("1e+21");
1724514f5e3Sopenharmony_ci    double d5 = 1e21;
1734514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle5 = NumberHelper::DoubleToEcmaString(thread, d5);
1744514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle5, resultStr5), 0);
1754514f5e3Sopenharmony_ci
1764514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr6 =
1774514f5e3Sopenharmony_ci        factory->NewFromASCII("340000000000000000");
1784514f5e3Sopenharmony_ci    double d6 = 340000000000000000;
1794514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle6 = NumberHelper::DoubleToEcmaString(thread, d6);
1804514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle6, resultStr6), 0);
1814514f5e3Sopenharmony_ci
1824514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr7 =
1834514f5e3Sopenharmony_ci        factory->NewFromASCII("12.012345678901234");
1844514f5e3Sopenharmony_ci    double d7 = 12.01234567890123456789;
1854514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle7 = NumberHelper::DoubleToEcmaString(thread, d7);
1864514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle7, resultStr7), 0);
1874514f5e3Sopenharmony_ci
1884514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr8 =
1894514f5e3Sopenharmony_ci        factory->NewFromASCII("0.0000012345678901234567");
1904514f5e3Sopenharmony_ci    double digit8 = 0.000001234567890123456789;
1914514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle8 = NumberHelper::DoubleToEcmaString(thread, digit8);
1924514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle8, resultStr8), 0);
1934514f5e3Sopenharmony_ci
1944514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr9 =
1954514f5e3Sopenharmony_ci        factory->NewFromASCII("Infinity");
1964514f5e3Sopenharmony_ci    double d9 = std::numeric_limits<double>::infinity();
1974514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle9 = NumberHelper::DoubleToEcmaString(thread, d9);
1984514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle9, resultStr9), 0);
1994514f5e3Sopenharmony_ci
2004514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr10 =
2014514f5e3Sopenharmony_ci        factory->NewFromASCII("-Infinity");
2024514f5e3Sopenharmony_ci    double d10 = -std::numeric_limits<double>::infinity();
2034514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle10 = NumberHelper::DoubleToEcmaString(thread, d10);
2044514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle10, resultStr10), 0);
2054514f5e3Sopenharmony_ci
2064514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr11 =
2074514f5e3Sopenharmony_ci        factory->NewFromASCII("1.7976931348623157e+308");
2084514f5e3Sopenharmony_ci    double d11 = 1.797693134862315807937e+308;
2094514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle11 = NumberHelper::DoubleToEcmaString(thread, d11);
2104514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle11, resultStr11), 0);
2114514f5e3Sopenharmony_ci
2124514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr12 =
2134514f5e3Sopenharmony_ci        factory->NewFromASCII("-1.7976931348623157e+308");
2144514f5e3Sopenharmony_ci    double d12 = -1.797693134862315807937e+308;
2154514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle12 = NumberHelper::DoubleToEcmaString(thread, d12);
2164514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle12, resultStr12), 0);
2174514f5e3Sopenharmony_ci
2184514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr13 =
2194514f5e3Sopenharmony_ci        factory->NewFromASCII("2.22507e-308");
2204514f5e3Sopenharmony_ci    double d13 = 2.22507e-308;
2214514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle13 = NumberHelper::DoubleToEcmaString(thread, d13);
2224514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle13, resultStr13), 0);
2234514f5e3Sopenharmony_ci
2244514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr14 =
2254514f5e3Sopenharmony_ci        factory->NewFromASCII("1.2345678901234568e-7");
2264514f5e3Sopenharmony_ci    double digit14 = 0.0000001234567890123456789;
2274514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle14 = NumberHelper::DoubleToEcmaString(thread, digit14);
2284514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle14, resultStr14), 0);
2294514f5e3Sopenharmony_ci
2304514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr15 =
2314514f5e3Sopenharmony_ci        factory->NewFromASCII("3.4e+21");
2324514f5e3Sopenharmony_ci    double digit15 = 3.4e21;
2334514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle15 = NumberHelper::DoubleToEcmaString(thread, digit15);
2344514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle15, resultStr15), 0);
2354514f5e3Sopenharmony_ci
2364514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr16 =
2374514f5e3Sopenharmony_ci        factory->NewFromASCII("120000000000000000000");
2384514f5e3Sopenharmony_ci    double digit16 = 1.2e20;
2394514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle16 = NumberHelper::DoubleToEcmaString(thread, digit16);
2404514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle16, resultStr16), 0);
2414514f5e3Sopenharmony_ci
2424514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr17 =
2434514f5e3Sopenharmony_ci        factory->NewFromASCII("1.2");
2444514f5e3Sopenharmony_ci    double digit17 = 1.2e0;
2454514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle17 = NumberHelper::DoubleToEcmaString(thread, digit17);
2464514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle17, resultStr17), 0);
2474514f5e3Sopenharmony_ci
2484514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr18 =
2494514f5e3Sopenharmony_ci        factory->NewFromASCII("0.0000012");
2504514f5e3Sopenharmony_ci    double digit18 = 1.2e-6;
2514514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle18 = NumberHelper::DoubleToEcmaString(thread, digit18);
2524514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle18, resultStr18), 0);
2534514f5e3Sopenharmony_ci
2544514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr19 =
2554514f5e3Sopenharmony_ci        factory->NewFromASCII("1.2e-7");
2564514f5e3Sopenharmony_ci    double digit19 = 1.2e-7;
2574514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle19 = NumberHelper::DoubleToEcmaString(thread, digit19);
2584514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle19, resultStr19), 0);
2594514f5e3Sopenharmony_ci
2604514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr20 =
2614514f5e3Sopenharmony_ci        factory->NewFromASCII("NaN");
2624514f5e3Sopenharmony_ci    double digit20 = std::numeric_limits<double>::quiet_NaN();
2634514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle20 = NumberHelper::DoubleToEcmaString(thread, digit20);
2644514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle20, resultStr20), 0);
2654514f5e3Sopenharmony_ci
2664514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr21 =
2674514f5e3Sopenharmony_ci        factory->NewFromASCII("-12.012345678901234");
2684514f5e3Sopenharmony_ci    double d21 = -12.01234567890123456789;
2694514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle21 = NumberHelper::DoubleToEcmaString(thread, d21);
2704514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle21, resultStr21), 0);
2714514f5e3Sopenharmony_ci
2724514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr22 =
2734514f5e3Sopenharmony_ci        factory->NewFromASCII("-0.0000012345678901234567");
2744514f5e3Sopenharmony_ci    double digit22 = -0.000001234567890123456789;
2754514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle22 = NumberHelper::DoubleToEcmaString(thread, digit22);
2764514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle22, resultStr22), 0);
2774514f5e3Sopenharmony_ci
2784514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr23 =
2794514f5e3Sopenharmony_ci        factory->NewFromASCII("-1.2345678901234568e-7");
2804514f5e3Sopenharmony_ci    double digit23 = -0.0000001234567890123456789;
2814514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle23 = NumberHelper::DoubleToEcmaString(thread, digit23);
2824514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle23, resultStr23), 0);
2834514f5e3Sopenharmony_ci
2844514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr24 =
2854514f5e3Sopenharmony_ci        factory->NewFromASCII("-3.4e+21");
2864514f5e3Sopenharmony_ci    double digit24 = -3.4e21;
2874514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle24 = NumberHelper::DoubleToEcmaString(thread, digit24);
2884514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle24, resultStr24), 0);
2894514f5e3Sopenharmony_ci
2904514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr25 =
2914514f5e3Sopenharmony_ci        factory->NewFromASCII("-120000000000000000000");
2924514f5e3Sopenharmony_ci    double digit25 = -1.2e20;
2934514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle25 = NumberHelper::DoubleToEcmaString(thread, digit25);
2944514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle25, resultStr25), 0);
2954514f5e3Sopenharmony_ci
2964514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr26 =
2974514f5e3Sopenharmony_ci        factory->NewFromASCII("-1.2");
2984514f5e3Sopenharmony_ci    double digit26 = -1.2e0;
2994514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle26 = NumberHelper::DoubleToEcmaString(thread, digit26);
3004514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle26, resultStr26), 0);
3014514f5e3Sopenharmony_ci
3024514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr27 =
3034514f5e3Sopenharmony_ci        factory->NewFromASCII("-0.0000012");
3044514f5e3Sopenharmony_ci    double digit27 = -1.2e-6;
3054514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle27 = NumberHelper::DoubleToEcmaString(thread, digit27);
3064514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle27, resultStr27), 0);
3074514f5e3Sopenharmony_ci
3084514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr28 =
3094514f5e3Sopenharmony_ci        factory->NewFromASCII("-1.2e-7");
3104514f5e3Sopenharmony_ci    double digit28 = -1.2e-7;
3114514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultJSHandle28 = NumberHelper::DoubleToEcmaString(thread, digit28);
3124514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, resultJSHandle28, resultStr28), 0);
3134514f5e3Sopenharmony_ci}
3144514f5e3Sopenharmony_ci
3154514f5e3Sopenharmony_ci/**
3164514f5e3Sopenharmony_ci * @tc.name: IsEmptyString
3174514f5e3Sopenharmony_ci * @tc.desc: Check whether the character is empty string through "IsEmptyString" function.
3184514f5e3Sopenharmony_ci * @tc.type: FUNC
3194514f5e3Sopenharmony_ci * @tc.require:
3204514f5e3Sopenharmony_ci */
3214514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, IsEmptyString_001)
3224514f5e3Sopenharmony_ci{
3234514f5e3Sopenharmony_ci    // 9 ~ 13 and 32 belong to empty string
3244514f5e3Sopenharmony_ci    uint8_t a[] = {0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x20};
3254514f5e3Sopenharmony_ci    for (int i = 0; i < static_cast<int>(sizeof(a)); i++) {
3264514f5e3Sopenharmony_ci        EXPECT_TRUE(NumberHelper::IsEmptyString(&a[i], &a[i] + 1));
3274514f5e3Sopenharmony_ci    }
3284514f5e3Sopenharmony_ci}
3294514f5e3Sopenharmony_ci
3304514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, IsEmptyString_002)
3314514f5e3Sopenharmony_ci{
3324514f5e3Sopenharmony_ci    // 14 ~ 31 not belong to empty string
3334514f5e3Sopenharmony_ci    uint8_t a[] = {0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3344514f5e3Sopenharmony_ci                                      0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
3354514f5e3Sopenharmony_ci    for (int i = 0; i < static_cast<int>(sizeof(a)); i++) {
3364514f5e3Sopenharmony_ci        EXPECT_FALSE(NumberHelper::IsEmptyString(&a[i], &a[i] + 1));
3374514f5e3Sopenharmony_ci    }
3384514f5e3Sopenharmony_ci}
3394514f5e3Sopenharmony_ci
3404514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, IsEmptyString_003)
3414514f5e3Sopenharmony_ci{
3424514f5e3Sopenharmony_ci    // 0 ~ 8 not belong to empty string
3434514f5e3Sopenharmony_ci    uint8_t a[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
3444514f5e3Sopenharmony_ci    for (int i = 0; i < static_cast<int>(sizeof(a)); i++) {
3454514f5e3Sopenharmony_ci        EXPECT_FALSE(NumberHelper::IsEmptyString(&a[i], &a[i] + 1));
3464514f5e3Sopenharmony_ci    }
3474514f5e3Sopenharmony_ci}
3484514f5e3Sopenharmony_ci
3494514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, IsEmptyString_004)
3504514f5e3Sopenharmony_ci{
3514514f5e3Sopenharmony_ci    // 160 belong to empty string
3524514f5e3Sopenharmony_ci    uint16_t c = 160;
3534514f5e3Sopenharmony_ci    utf_helper::Utf8Char d = utf_helper::ConvertUtf16ToUtf8(c, 0, true);
3544514f5e3Sopenharmony_ci    EXPECT_EQ(d.ch.at(1), 160);
3554514f5e3Sopenharmony_ci    uint8_t b = d.ch.at(1);
3564514f5e3Sopenharmony_ci    EXPECT_TRUE(NumberHelper::IsEmptyString(&b, &b + 1));
3574514f5e3Sopenharmony_ci}
3584514f5e3Sopenharmony_ci
3594514f5e3Sopenharmony_ci/**
3604514f5e3Sopenharmony_ci * @tc.name: TruncateDouble
3614514f5e3Sopenharmony_ci * @tc.desc:This function takes the integer part of double type.When it is positive,it is rounded down
3624514f5e3Sopenharmony_ci *          When it is negative,it is rounded up.
3634514f5e3Sopenharmony_ci * @tc.type: FUNC
3644514f5e3Sopenharmony_ci * @tc.require:
3654514f5e3Sopenharmony_ci */
3664514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, TruncateDouble)
3674514f5e3Sopenharmony_ci{
3684514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::TruncateDouble(NAN_VALUE), 0);
3694514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::TruncateDouble(POSITIVE_INFINITY), POSITIVE_INFINITY);
3704514f5e3Sopenharmony_ci    // round down
3714514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::TruncateDouble(4.1), 4);
3724514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::TruncateDouble(4.9), 4);
3734514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::TruncateDouble(101.111), 101);
3744514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::TruncateDouble(101.999), 101);
3754514f5e3Sopenharmony_ci    // round up
3764514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::TruncateDouble(-4.1), -4);
3774514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::TruncateDouble(-4.9), -4);
3784514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::TruncateDouble(-101.111), -101);
3794514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::TruncateDouble(-101.999), -101);
3804514f5e3Sopenharmony_ci}
3814514f5e3Sopenharmony_ci
3824514f5e3Sopenharmony_ci/**
3834514f5e3Sopenharmony_ci * @tc.name: DoubleToInt
3844514f5e3Sopenharmony_ci * @tc.desc: This function takes the double of integer type.When the decimal part is eight and the number of digits
3854514f5e3Sopenharmony_ci *           is 15 ~ 16, add one to convert to integer.According to the binary digits of the integer part,it is divided
3864514f5e3Sopenharmony_ci *           into 8, 16 and 64 hexadecimal conversion,for example, 8-hexadecimal conversion.The maximum value of the
3874514f5e3Sopenharmony_ci *           integer part is 255. If it exceeds 255,the conversion fails.
3884514f5e3Sopenharmony_ci * @tc.type: FUNC
3894514f5e3Sopenharmony_ci * @tc.require:
3904514f5e3Sopenharmony_ci */
3914514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToInt_001)
3924514f5e3Sopenharmony_ci{
3934514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(9.0, INT8_BITS), 9);
3944514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(9.5555555555555559, INT8_BITS), 9);
3954514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(9.9999999999999999, INT8_BITS), 10);
3964514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(128.123456, INT8_BITS), 128);
3974514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(-128.987654321, INT8_BITS), -128);
3984514f5e3Sopenharmony_ci
3994514f5e3Sopenharmony_ci    // the exponential bit digits exceeds 7
4004514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(256.0, INT8_BITS), 0);
4014514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(-256.0, INT8_BITS), 0);
4024514f5e3Sopenharmony_ci
4034514f5e3Sopenharmony_ci    double nanDouble = 0.0f / 0.0f;
4044514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(nanDouble, INT8_BITS), 0);
4054514f5e3Sopenharmony_ci    double infDouble = POSITIVE_INFINITY;
4064514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(infDouble, INT8_BITS), 0);
4074514f5e3Sopenharmony_ci}
4084514f5e3Sopenharmony_ci
4094514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToInt_002)
4104514f5e3Sopenharmony_ci{
4114514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(256.0, INT16_BITS), 256);
4124514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(256.555555555555556, INT16_BITS), 256);
4134514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(256.999999999999999, INT16_BITS), 257);
4144514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(1024.56789, INT16_BITS), 1024);
4154514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(-1024.987654, INT16_BITS), -1024);
4164514f5e3Sopenharmony_ci
4174514f5e3Sopenharmony_ci    // the exponential bit digits exceeds 15
4184514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(65536.0, INT16_BITS), 0);
4194514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(-65536.0, INT16_BITS), 0);
4204514f5e3Sopenharmony_ci
4214514f5e3Sopenharmony_ci    double nanDouble = 0.0f / 0.0f;
4224514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(nanDouble, INT16_BITS), 0);
4234514f5e3Sopenharmony_ci    double infDouble = POSITIVE_INFINITY;
4244514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(infDouble, INT16_BITS), 0);
4254514f5e3Sopenharmony_ci}
4264514f5e3Sopenharmony_ci
4274514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToInt_003)
4284514f5e3Sopenharmony_ci{
4294514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(256.0, INT64_BITS), 256);
4304514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(256.555555555555556, INT64_BITS), 256);
4314514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(256.999999999999999, INT64_BITS), 257);
4324514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(65536.55555, INT64_BITS), 65536);
4334514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(-65536.99999, INT64_BITS), -65536);
4344514f5e3Sopenharmony_ci
4354514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(2147483647.0, INT64_BITS), 2147483647);
4364514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(-2147483647.0, INT64_BITS), -2147483647);
4374514f5e3Sopenharmony_ci
4384514f5e3Sopenharmony_ci    double nanDouble = 0.0f / 0.0f;
4394514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(nanDouble, INT64_BITS), 0);
4404514f5e3Sopenharmony_ci    double infDouble = POSITIVE_INFINITY;
4414514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleToInt(infDouble, INT64_BITS), 0);
4424514f5e3Sopenharmony_ci}
4434514f5e3Sopenharmony_ci
4444514f5e3Sopenharmony_ci/**
4454514f5e3Sopenharmony_ci * @tc.name: DoubleInRangeInt32
4464514f5e3Sopenharmony_ci * @tc.desc: The function is to convert double type to int type,The maximum value of integer part of double type
4474514f5e3Sopenharmony_ci *           cannot exceed the maximum value of int, and the minimum value of integer part cannot exceed the
4484514f5e3Sopenharmony_ci *           minimum value of int.
4494514f5e3Sopenharmony_ci * @tc.type: FUNC
4504514f5e3Sopenharmony_ci * @tc.require:
4514514f5e3Sopenharmony_ci */
4524514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleInRangeInt32)
4534514f5e3Sopenharmony_ci{
4544514f5e3Sopenharmony_ci    // more than INT_MAX
4554514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleInRangeInt32(2147483649.0), 2147483647);
4564514f5e3Sopenharmony_ci    // less than INT_MIN
4574514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleInRangeInt32(-2147483649.0), -2147483648);
4584514f5e3Sopenharmony_ci
4594514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleInRangeInt32(128.0), 128);
4604514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleInRangeInt32(-128.999999999999999), -129);
4614514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleInRangeInt32(256.0), 256);
4624514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleInRangeInt32(-256.0), -256);
4634514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleInRangeInt32(12345.6789), 12345);
4644514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleInRangeInt32(-12345.6789), -12345);
4654514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleInRangeInt32(65535.999999999999999), 65536);
4664514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::DoubleInRangeInt32(-65535), -65535);
4674514f5e3Sopenharmony_ci}
4684514f5e3Sopenharmony_ci
4694514f5e3Sopenharmony_ci/**
4704514f5e3Sopenharmony_ci * @tc.name: DoubleToExponential
4714514f5e3Sopenharmony_ci * @tc.desc: Convert integer type to string type through "DoubleToExponential" function.
4724514f5e3Sopenharmony_ci * @tc.type: FUNC
4734514f5e3Sopenharmony_ci * @tc.require:
4744514f5e3Sopenharmony_ci */
4754514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToExponential01)
4764514f5e3Sopenharmony_ci{
4774514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
4784514f5e3Sopenharmony_ci    int radix;
4794514f5e3Sopenharmony_ci
4804514f5e3Sopenharmony_ci    radix = 0;
4814514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr = factory->NewFromASCII("1.12356e-4");
4824514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr1(thread, NumberHelper::DoubleToExponential(thread,
4834514f5e3Sopenharmony_ci                                        0.00011235600000000001, radix));
4844514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr1, resultStr), 0);
4854514f5e3Sopenharmony_ci
4864514f5e3Sopenharmony_ci    radix = 1;
4874514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1e-4");
4884514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr2(thread, NumberHelper::DoubleToExponential(thread,
4894514f5e3Sopenharmony_ci                                        0.00011235600000000001, radix));
4904514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr2, resultStr), 0);
4914514f5e3Sopenharmony_ci
4924514f5e3Sopenharmony_ci    radix = 2;
4934514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.1e-4");
4944514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr3(thread, NumberHelper::DoubleToExponential(thread,
4954514f5e3Sopenharmony_ci                                        0.00011235600000000001, radix));
4964514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr3, resultStr), 0);
4974514f5e3Sopenharmony_ci
4984514f5e3Sopenharmony_ci    radix = 16;
4994514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.123560000000000e-4");
5004514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr4(thread, NumberHelper::DoubleToExponential(thread,
5014514f5e3Sopenharmony_ci                                        0.00011235600000000001, radix));
5024514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr4, resultStr), 0);
5034514f5e3Sopenharmony_ci
5044514f5e3Sopenharmony_ci    radix = 0;
5054514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.23456e+2");
5064514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr5(thread, NumberHelper::DoubleToExponential(thread, 123.456, radix));
5074514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr5, resultStr), 0);
5084514f5e3Sopenharmony_ci
5094514f5e3Sopenharmony_ci    radix = 1;
5104514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1e+2");
5114514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr6(thread, NumberHelper::DoubleToExponential(thread, 123.456, radix));
5124514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr6, resultStr), 0);
5134514f5e3Sopenharmony_ci
5144514f5e3Sopenharmony_ci    radix = 2;
5154514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.2e+2");
5164514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr7(thread, NumberHelper::DoubleToExponential(thread, 123.456, radix));
5174514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr7, resultStr), 0);
5184514f5e3Sopenharmony_ci
5194514f5e3Sopenharmony_ci    radix = 16;
5204514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.234560000000000e+2");
5214514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr8(thread, NumberHelper::DoubleToExponential(thread, 123.456, radix));
5224514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr8, resultStr), 0);
5234514f5e3Sopenharmony_ci}
5244514f5e3Sopenharmony_ci
5254514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToExponential02)
5264514f5e3Sopenharmony_ci{
5274514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
5284514f5e3Sopenharmony_ci    int radix;
5294514f5e3Sopenharmony_ci
5304514f5e3Sopenharmony_ci    radix = -4;
5314514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr = factory->NewFromASCII("1.239876e+2");
5324514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr1(thread, NumberHelper::DoubleToExponential(thread, 123.9876, radix));
5334514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr1, resultStr), 0);
5344514f5e3Sopenharmony_ci
5354514f5e3Sopenharmony_ci    radix = -6;
5364514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.239876e+2");
5374514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr2(thread, NumberHelper::DoubleToExponential(thread, 123.9876, radix));
5384514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr2, resultStr), 0);
5394514f5e3Sopenharmony_ci
5404514f5e3Sopenharmony_ci    radix = 3;
5414514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.24e+2");
5424514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr3(thread, NumberHelper::DoubleToExponential(thread, 123.567, radix));
5434514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr3, resultStr), 0);
5444514f5e3Sopenharmony_ci
5454514f5e3Sopenharmony_ci    radix = 7;
5464514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.234567e+2");
5474514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr4(thread, NumberHelper::DoubleToExponential(thread, 123.4567, radix));
5484514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr4, resultStr), 0);
5494514f5e3Sopenharmony_ci
5504514f5e3Sopenharmony_ci    radix = 8;
5514514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.2345670e+2");
5524514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr5(thread, NumberHelper::DoubleToExponential(thread, 123.45670, radix));
5534514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr5, resultStr), 0);
5544514f5e3Sopenharmony_ci
5554514f5e3Sopenharmony_ci    radix = 4;
5564514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.230e+2");
5574514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr6(thread, NumberHelper::DoubleToExponential(thread, 123.0123, radix));
5584514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr6, resultStr), 0);
5594514f5e3Sopenharmony_ci}
5604514f5e3Sopenharmony_ci
5614514f5e3Sopenharmony_ci/**
5624514f5e3Sopenharmony_ci * @tc.name: StringToDoubleWithRadix
5634514f5e3Sopenharmony_ci * @tc.desc: Convert double decimal type to Precision type through "DoubleToPrecision" function.If the logarithm
5644514f5e3Sopenharmony_ci *           of number based on ten is less than zero and radix Digit is more than zero or it is greater than zero
5654514f5e3Sopenharmony_ci *           and radix Digit is less than MAX_EXPONENT_DIGIT call the DoubleToFixed function.other call
5664514f5e3Sopenharmony_ci *           DoubleToExponential function.
5674514f5e3Sopenharmony_ci * @tc.type: FUNC
5684514f5e3Sopenharmony_ci * @tc.require:
5694514f5e3Sopenharmony_ci */
5704514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, StringToDoubleWithRadix)
5714514f5e3Sopenharmony_ci{
5724514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
5734514f5e3Sopenharmony_ci    int radix;
5744514f5e3Sopenharmony_ci    Span<const uint8_t> sp;
5754514f5e3Sopenharmony_ci    CVector<uint8_t> buf;
5764514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr;
5774514f5e3Sopenharmony_ci
5784514f5e3Sopenharmony_ci    radix = 3;
5794514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("-12");
5804514f5e3Sopenharmony_ci    sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf);
5814514f5e3Sopenharmony_ci    bool negative = false;
5824514f5e3Sopenharmony_ci    // 5 = 1 * 3 + 2
5834514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), -5);
5844514f5e3Sopenharmony_ci
5854514f5e3Sopenharmony_ci    radix = 4;
5864514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1234567");
5874514f5e3Sopenharmony_ci    sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf);
5884514f5e3Sopenharmony_ci    negative = false;
5894514f5e3Sopenharmony_ci    // 27 = (1 * 4 + 2) * 4 + 3
5904514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 27);
5914514f5e3Sopenharmony_ci    // string has space
5924514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII(" 12345 ");
5934514f5e3Sopenharmony_ci    sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf);
5944514f5e3Sopenharmony_ci    negative = false;
5954514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 27);
5964514f5e3Sopenharmony_ci
5974514f5e3Sopenharmony_ci    radix = 16;
5984514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0x00ff");
5994514f5e3Sopenharmony_ci    sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf);
6004514f5e3Sopenharmony_ci    negative = false;
6014514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 255);
6024514f5e3Sopenharmony_ci
6034514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0x0010");
6044514f5e3Sopenharmony_ci    sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf);
6054514f5e3Sopenharmony_ci    negative = false;
6064514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 16);
6074514f5e3Sopenharmony_ci
6084514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0x1234");
6094514f5e3Sopenharmony_ci    sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf);
6104514f5e3Sopenharmony_ci    negative = false;
6114514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 4660);
6124514f5e3Sopenharmony_ci    // string has space
6134514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII(" 0x12  ");
6144514f5e3Sopenharmony_ci    sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf);
6154514f5e3Sopenharmony_ci    negative = false;
6164514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 18);
6174514f5e3Sopenharmony_ci
6184514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0x1234XX");
6194514f5e3Sopenharmony_ci    sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf);
6204514f5e3Sopenharmony_ci    negative = false;
6214514f5e3Sopenharmony_ci    EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 4660);
6224514f5e3Sopenharmony_ci}
6234514f5e3Sopenharmony_ci
6244514f5e3Sopenharmony_ci/**
6254514f5e3Sopenharmony_ci * @tc.name: IntToString
6264514f5e3Sopenharmony_ci * @tc.desc: Convert integer type to string type through "IntToString" function.
6274514f5e3Sopenharmony_ci * @tc.type: FUNC
6284514f5e3Sopenharmony_ci * @tc.require:
6294514f5e3Sopenharmony_ci */
6304514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, IntToString)
6314514f5e3Sopenharmony_ci{
6324514f5e3Sopenharmony_ci    EXPECT_STREQ(NumberHelper::IntToString(0).c_str(), "0");
6334514f5e3Sopenharmony_ci    EXPECT_STREQ(NumberHelper::IntToString(-100).c_str(), "-100");
6344514f5e3Sopenharmony_ci    EXPECT_STREQ(NumberHelper::IntToString(123).c_str(), "123");
6354514f5e3Sopenharmony_ci    EXPECT_STREQ(NumberHelper::IntToString(1234).c_str(), "1234");
6364514f5e3Sopenharmony_ci}
6374514f5e3Sopenharmony_ci
6384514f5e3Sopenharmony_ci/**
6394514f5e3Sopenharmony_ci * @tc.name: IntegerToString
6404514f5e3Sopenharmony_ci * @tc.desc: Convert the decimal number into the hexadecimal number corresponding to Radix and convert it into a string
6414514f5e3Sopenharmony_ci *           Check whether the returned string result is the same as the actual conversion result.
6424514f5e3Sopenharmony_ci * @tc.type: FUNC
6434514f5e3Sopenharmony_ci * @tc.require:
6444514f5e3Sopenharmony_ci */
6454514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, IntegerToString)
6464514f5e3Sopenharmony_ci{
6474514f5e3Sopenharmony_ci    int radix = 2;
6484514f5e3Sopenharmony_ci    // number = (radix + 1) * MAX_MANTISSA
6494514f5e3Sopenharmony_ci    CString integerStr = NumberHelper::IntegerToString(static_cast<double>((radix + 1) * (0x1ULL << 52U)), radix);
6504514f5e3Sopenharmony_ci    EXPECT_STREQ(integerStr.c_str(), "110000000000000000000000000000000000000000000000000000");
6514514f5e3Sopenharmony_ci
6524514f5e3Sopenharmony_ci    integerStr = NumberHelper::IntegerToString(static_cast<double>(10), radix);
6534514f5e3Sopenharmony_ci    EXPECT_STREQ(integerStr.c_str(), "1010");
6544514f5e3Sopenharmony_ci
6554514f5e3Sopenharmony_ci    radix = 3;
6564514f5e3Sopenharmony_ci    integerStr = NumberHelper::IntegerToString(static_cast<double>(33), radix);
6574514f5e3Sopenharmony_ci    EXPECT_STREQ(integerStr.c_str(), "1020");
6584514f5e3Sopenharmony_ci
6594514f5e3Sopenharmony_ci    radix = 8;
6604514f5e3Sopenharmony_ci    integerStr = NumberHelper::IntegerToString(static_cast<double>(128), radix);
6614514f5e3Sopenharmony_ci    EXPECT_STREQ(integerStr.c_str(), "200");
6624514f5e3Sopenharmony_ci
6634514f5e3Sopenharmony_ci    integerStr = NumberHelper::IntegerToString(static_cast<double>(128.985), radix);
6644514f5e3Sopenharmony_ci    EXPECT_STREQ(integerStr.c_str(), "200");
6654514f5e3Sopenharmony_ci
6664514f5e3Sopenharmony_ci    radix = 16;
6674514f5e3Sopenharmony_ci    integerStr = NumberHelper::IntegerToString(static_cast<double>(256), radix);
6684514f5e3Sopenharmony_ci    EXPECT_STREQ(integerStr.c_str(), "100");
6694514f5e3Sopenharmony_ci
6704514f5e3Sopenharmony_ci    radix = 24;
6714514f5e3Sopenharmony_ci    integerStr = NumberHelper::IntegerToString(static_cast<double>(987654), radix);
6724514f5e3Sopenharmony_ci    EXPECT_STREQ(integerStr.c_str(), "2nag6");
6734514f5e3Sopenharmony_ci
6744514f5e3Sopenharmony_ci    integerStr = NumberHelper::IntegerToString(static_cast<double>(23), radix);
6754514f5e3Sopenharmony_ci    EXPECT_STREQ(integerStr.c_str(), "n");
6764514f5e3Sopenharmony_ci}
6774514f5e3Sopenharmony_ci
6784514f5e3Sopenharmony_ci/**
6794514f5e3Sopenharmony_ci * @tc.name: NumberToString
6804514f5e3Sopenharmony_ci * @tc.desc: The abstract operation NumberToString converts a Number m to String format
6814514f5e3Sopenharmony_ci * @tc.type: FUNC
6824514f5e3Sopenharmony_ci * @tc.require:
6834514f5e3Sopenharmony_ci */
6844514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, NumberToString)
6854514f5e3Sopenharmony_ci{
6864514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
6874514f5e3Sopenharmony_ci    double d = 8.1999999999999993;
6884514f5e3Sopenharmony_ci    JSHandle<EcmaString> result = NumberHelper::NumberToString(thread, JSTaggedValue(d));
6894514f5e3Sopenharmony_ci    JSHandle<EcmaString> target = factory->NewFromASCII("8.2");
6904514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, result, target), 0);
6914514f5e3Sopenharmony_ci
6924514f5e3Sopenharmony_ci    double d2 = 0.30000000000000004;
6934514f5e3Sopenharmony_ci    JSHandle<EcmaString> result1 = NumberHelper::NumberToString(thread, JSTaggedValue(d2));
6944514f5e3Sopenharmony_ci    JSHandle<EcmaString> target1 = factory->NewFromASCII("0.30000000000000004");
6954514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, result1, target1), 0);
6964514f5e3Sopenharmony_ci}
6974514f5e3Sopenharmony_ci
6984514f5e3Sopenharmony_ci/**
6994514f5e3Sopenharmony_ci * @tc.name: DoubleToInt64
7004514f5e3Sopenharmony_ci * @tc.desc: The abstract operation DoubleToInt64 converts a double value to int64_t
7014514f5e3Sopenharmony_ci * @tc.type: FUNC
7024514f5e3Sopenharmony_ci * @tc.require:
7034514f5e3Sopenharmony_ci */
7044514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToInt64)
7054514f5e3Sopenharmony_ci{
7064514f5e3Sopenharmony_ci    int64_t d = NumberHelper::DoubleToInt64(std::numeric_limits<double>::max());
7074514f5e3Sopenharmony_ci    EXPECT_EQ(d, std::numeric_limits<int64_t>::max());
7084514f5e3Sopenharmony_ci
7094514f5e3Sopenharmony_ci    int64_t d1 = NumberHelper::DoubleToInt64(static_cast<double>(std::numeric_limits<int64_t>::max()));
7104514f5e3Sopenharmony_ci    EXPECT_EQ(d1, std::numeric_limits<int64_t>::max());
7114514f5e3Sopenharmony_ci    int64_t d2 = NumberHelper::DoubleToInt64(static_cast<double>(std::numeric_limits<int64_t>::min()));
7124514f5e3Sopenharmony_ci    EXPECT_EQ(d2, std::numeric_limits<int64_t>::min());
7134514f5e3Sopenharmony_ci
7144514f5e3Sopenharmony_ci    int64_t d3 = NumberHelper::DoubleToInt64(static_cast<double>(std::numeric_limits<int64_t>::max()) + 1);
7154514f5e3Sopenharmony_ci    EXPECT_EQ(d3, std::numeric_limits<int64_t>::max());
7164514f5e3Sopenharmony_ci    int64_t d4 = NumberHelper::DoubleToInt64(static_cast<double>(std::numeric_limits<int64_t>::min()) - 1);
7174514f5e3Sopenharmony_ci    EXPECT_EQ(d4, std::numeric_limits<int64_t>::min());
7184514f5e3Sopenharmony_ci
7194514f5e3Sopenharmony_ci    int64_t d5 = NumberHelper::DoubleToInt64(0);
7204514f5e3Sopenharmony_ci    EXPECT_EQ(d5, 0);
7214514f5e3Sopenharmony_ci}
7224514f5e3Sopenharmony_ci/**
7234514f5e3Sopenharmony_ci * @tc.name: DoubleToASCII
7244514f5e3Sopenharmony_ci * @tc.desc: When flag is equal to 2, the calculation result of DoubleToASCII is number.toFixed()
7254514f5e3Sopenharmony_ci * @tc.type: FUNC
7264514f5e3Sopenharmony_ci * @tc.require:
7274514f5e3Sopenharmony_ci */
7284514f5e3Sopenharmony_ci
7294514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToASCII_001)
7304514f5e3Sopenharmony_ci{
7314514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
7324514f5e3Sopenharmony_ci    int flags = 2;
7334514f5e3Sopenharmony_ci    int digit = 2;
7344514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr = factory->NewFromASCII("0.10");
7354514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr(thread, NumberHelper::DoubleToASCII(thread,
7364514f5e3Sopenharmony_ci                                       0.10000000000000001, digit, flags));
7374514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr, resultStr), 0);
7384514f5e3Sopenharmony_ci
7394514f5e3Sopenharmony_ci    digit = 3;
7404514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0.100");
7414514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr1(thread, NumberHelper::DoubleToASCII(thread,
7424514f5e3Sopenharmony_ci                                        0.10000000000000001, digit, flags));
7434514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr1, resultStr), 0);
7444514f5e3Sopenharmony_ci
7454514f5e3Sopenharmony_ci    digit = 2;
7464514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0.01");
7474514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr2(thread, NumberHelper::DoubleToASCII(thread,
7484514f5e3Sopenharmony_ci                                        0.01, digit, flags));
7494514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr2, resultStr), 0);
7504514f5e3Sopenharmony_ci
7514514f5e3Sopenharmony_ci    digit = 3;
7524514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0.010");
7534514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr3(thread, NumberHelper::DoubleToASCII(thread,
7544514f5e3Sopenharmony_ci                                        0.01, digit, flags));
7554514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr3, resultStr), 0);
7564514f5e3Sopenharmony_ci
7574514f5e3Sopenharmony_ci    digit = 7;
7584514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0.0000006");
7594514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr4(thread, NumberHelper::DoubleToASCII(thread,
7604514f5e3Sopenharmony_ci                                        5.9999999999999997e-07, digit, flags));
7614514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr4, resultStr), 0);
7624514f5e3Sopenharmony_ci
7634514f5e3Sopenharmony_ci    digit = 8;
7644514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0.00000006");
7654514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr5(thread, NumberHelper::DoubleToASCII(thread,
7664514f5e3Sopenharmony_ci                                        5.9999999999999997e-08, digit, flags));
7674514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr5, resultStr), 0);
7684514f5e3Sopenharmony_ci
7694514f5e3Sopenharmony_ci    digit = 1;
7704514f5e3Sopenharmony_ci#ifdef PANDA_TARGET_ARM32
7714514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.2");
7724514f5e3Sopenharmony_ci#else
7734514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.3");
7744514f5e3Sopenharmony_ci#endif
7754514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr6(thread, NumberHelper::DoubleToASCII(thread, 1.25, digit, flags));
7764514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr6, resultStr), 0);
7774514f5e3Sopenharmony_ci
7784514f5e3Sopenharmony_ci    digit = 1;
7794514f5e3Sopenharmony_ci#ifdef PANDA_TARGET_ARM32
7804514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("-1.2");
7814514f5e3Sopenharmony_ci#else
7824514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("-1.3");
7834514f5e3Sopenharmony_ci#endif
7844514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr7(thread, NumberHelper::DoubleToASCII(thread, -1.25, digit, flags));
7854514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr7, resultStr), 0);
7864514f5e3Sopenharmony_ci}
7874514f5e3Sopenharmony_ci
7884514f5e3Sopenharmony_ci/**
7894514f5e3Sopenharmony_ci * @tc.name: DoubleToASCII
7904514f5e3Sopenharmony_ci * @tc.desc: When flag is equal to 1, the calculation result of DoubleToASCII is number.toPrecision()
7914514f5e3Sopenharmony_ci * @tc.type: FUNC
7924514f5e3Sopenharmony_ci * @tc.require:
7934514f5e3Sopenharmony_ci */
7944514f5e3Sopenharmony_ciHWTEST_F_L0(NumberHelperTest, DoubleToASCII_002)
7954514f5e3Sopenharmony_ci{
7964514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
7974514f5e3Sopenharmony_ci    int flags = 1;
7984514f5e3Sopenharmony_ci    int digit = 2;
7994514f5e3Sopenharmony_ci    JSHandle<EcmaString> resultStr = factory->NewFromASCII("-1.2e-9");
8004514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr(thread, NumberHelper::DoubleToASCII(thread, -1.2345e-09, digit, flags));
8014514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr, resultStr), 0);
8024514f5e3Sopenharmony_ci
8034514f5e3Sopenharmony_ci    digit = 2;
8044514f5e3Sopenharmony_ci    flags = 1;
8054514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.2e-8");
8064514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr1(thread, NumberHelper::DoubleToASCII(thread,
8074514f5e3Sopenharmony_ci                                        1.2345000000000001e-08, digit, flags));
8084514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr1, resultStr), 0);
8094514f5e3Sopenharmony_ci
8104514f5e3Sopenharmony_ci    digit = 2;
8114514f5e3Sopenharmony_ci    flags = 1;
8124514f5e3Sopenharmony_ci#ifdef PANDA_TARGET_ARM32
8134514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.2");
8144514f5e3Sopenharmony_ci#else
8154514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.3");
8164514f5e3Sopenharmony_ci#endif
8174514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr2(thread, NumberHelper::DoubleToASCII(thread, 1.25, digit, flags));
8184514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr2, resultStr), 0);
8194514f5e3Sopenharmony_ci
8204514f5e3Sopenharmony_ci    digit = 2;
8214514f5e3Sopenharmony_ci    flags = 1;
8224514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("1.4");
8234514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr3(thread, NumberHelper::DoubleToASCII(thread, 1.35, digit, flags));
8244514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr3, resultStr), 0);
8254514f5e3Sopenharmony_ci
8264514f5e3Sopenharmony_ci
8274514f5e3Sopenharmony_ci    digit = 15;
8284514f5e3Sopenharmony_ci    flags = 1;
8294514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("0.000555000000000000");
8304514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr4(thread, NumberHelper::DoubleToASCII(thread,
8314514f5e3Sopenharmony_ci                                        0.00055500000000000005, digit, flags));
8324514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr4, resultStr), 0);
8334514f5e3Sopenharmony_ci
8344514f5e3Sopenharmony_ci    digit = 15;
8354514f5e3Sopenharmony_ci    flags = 1;
8364514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("5.55000000000000e-7");
8374514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr5(thread, NumberHelper::DoubleToASCII(thread,
8384514f5e3Sopenharmony_ci                                        5.5499999999999998e-07, digit, flags));
8394514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr5, resultStr), 0);
8404514f5e3Sopenharmony_ci
8414514f5e3Sopenharmony_ci    digit = 15;
8424514f5e3Sopenharmony_ci    flags = 1;
8434514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("-5.55000000000000e-7");
8444514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr6(thread, NumberHelper::DoubleToASCII(thread,
8454514f5e3Sopenharmony_ci                                        -5.5499999999999998e-07, digit, flags));
8464514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr6, resultStr), 0);
8474514f5e3Sopenharmony_ci
8484514f5e3Sopenharmony_ci    digit = 2;
8494514f5e3Sopenharmony_ci    flags = 1;
8504514f5e3Sopenharmony_ci    resultStr = factory->NewFromASCII("-12");
8514514f5e3Sopenharmony_ci    JSHandle<EcmaString> handleEcmaStr7(thread, NumberHelper::DoubleToASCII(thread,
8524514f5e3Sopenharmony_ci                                        -12.345000000000001, digit, flags));
8534514f5e3Sopenharmony_ci    EXPECT_EQ(EcmaStringAccessor::Compare(instance, handleEcmaStr7, resultStr), 0);
8544514f5e3Sopenharmony_ci}
8554514f5e3Sopenharmony_ci
8564514f5e3Sopenharmony_ci} // namespace panda::ecmascript
857