1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "number_format_test.h"
17
18 #include "locale_config.h"
19 #include "number_format.h"
20 #include "simple_number_format.h"
21 #include "styled_number_format.h"
22 #include "unicode/locid.h"
23 #include "utils.h"
24
25 using namespace OHOS::Global::I18n;
26 using testing::ext::TestSize;
27 using namespace std;
28
29 namespace OHOS {
30 namespace Global {
31 namespace I18n {
32 string NumberFormatTest::originalLanguage;
33 string NumberFormatTest::originalRegion;
34 string NumberFormatTest::originalLocale;
35 string NumberFormatTest::deviceType;
36
SetUpTestCase(void)37 void NumberFormatTest::SetUpTestCase(void)
38 {
39 originalLanguage = LocaleConfig::GetSystemLanguage();
40 originalRegion = LocaleConfig::GetSystemRegion();
41 originalLocale = LocaleConfig::GetSystemLocale();
42 LocaleConfig::SetSystemLanguage("zh-Hans");
43 LocaleConfig::SetSystemRegion("CN");
44 LocaleConfig::SetSystemLocale("zh-Hans-CN");
45 NumberFormatTest::deviceType = ReadSystemParameter("const.product.devicetype", LocaleConfig::CONFIG_LEN);
46 }
47
TearDownTestCase(void)48 void NumberFormatTest::TearDownTestCase(void)
49 {
50 LocaleConfig::SetSystemLanguage(originalLanguage);
51 LocaleConfig::SetSystemRegion(originalRegion);
52 LocaleConfig::SetSystemLocale(originalLocale);
53 }
54
SetUp(void)55 void NumberFormatTest::SetUp(void)
56 {}
57
TearDown(void)58 void NumberFormatTest::TearDown(void)
59 {}
60
61 /**
62 * @tc.name: NumberFormatFuncTest001
63 * @tc.desc: Test Intl NumberFormat.format
64 * @tc.type: FUNC
65 */
66 HWTEST_F(NumberFormatTest, NumberFormatFuncTest001, TestSize.Level1)
67 {
68 string locale = "en-IN";
69 string expects = "+1,23,456.79 euros";
70 vector<string> locales{locale};
71 string useGrouping = "true";
72 string minimumIntegerDigits = "7";
73 string maximumFractionDigits = "2";
74 string style = "currency";
75 string currency = "978";
76 map<string, string> options = { { "useGrouping", useGrouping },
77 { "style", style },
78 { "currency", currency },
79 { "currencyDisplay", "name" },
80 { "currencySign", "accounting" },
81 { "signDisplay", "always" } };
82 std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
83 ASSERT_TRUE(numFmt != nullptr);
84 string out = numFmt->Format(123456.789);
85 EXPECT_EQ(out, expects);
86 EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
87 EXPECT_EQ(numFmt->GetStyle(), style);
88 EXPECT_EQ(numFmt->GetCurrency(), "EUR");
89 }
90
91 /**
92 * @tc.name: NumberFormatFuncTest002
93 * @tc.desc: Test Intl NumberFormat.format
94 * @tc.type: FUNC
95 */
96 HWTEST_F(NumberFormatTest, NumberFormatFuncTest002, TestSize.Level1)
97 {
98 string locale = "en-IN";
99 string expects = "+1,23,456.789";
100 vector<string> locales{locale};
101 string useGrouping = "true";
102 string minimumIntegerDigits = "7";
103 string maximumFractionDigits = "2";
104 string style = "currency";
105 string currency = "111";
106 map<string, string> options = { { "useGrouping", useGrouping },
107 { "style", style },
108 { "currency", currency },
109 { "currencyDisplay", "name" },
110 { "currencySign", "accounting" },
111 { "signDisplay", "always" } };
112 std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
113 ASSERT_TRUE(numFmt != nullptr);
114 string out = numFmt->Format(123456.789);
115 EXPECT_EQ(out, expects);
116 EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
117 EXPECT_EQ(numFmt->GetStyle(), style);
118 EXPECT_EQ(numFmt->GetCurrency(), "");
119 }
120
121 /**
122 * @tc.name: NumberFormatFuncTest003
123 * @tc.desc: Test Intl NumberFormat.format
124 * @tc.type: FUNC
125 */
126 HWTEST_F(NumberFormatTest, NumberFormatFuncTest003, TestSize.Level1)
127 {
128 string locale = "en-IN";
129 string expects = "+1,23,456.789";
130 vector<string> locales{locale};
131 string useGrouping = "true";
132 string minimumIntegerDigits = "7";
133 string maximumFractionDigits = "2";
134 string style = "currency";
135 string currency = "a1b";
136 map<string, string> options = { { "useGrouping", useGrouping },
137 { "style", style },
138 { "currency", currency },
139 { "currencyDisplay", "name" },
140 { "currencySign", "accounting" },
141 { "signDisplay", "always" } };
142 std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
143 ASSERT_TRUE(numFmt != nullptr);
144 string out = numFmt->Format(123456.789);
145 EXPECT_EQ(out, expects);
146 EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
147 EXPECT_EQ(numFmt->GetStyle(), style);
148 EXPECT_EQ(numFmt->GetCurrency(), "");
149 }
150
151 /**
152 * @tc.name: NumberFormatFuncTest004
153 * @tc.desc: Test Intl NumberFormat.format
154 * @tc.type: FUNC
155 */
156 HWTEST_F(NumberFormatTest, NumberFormatFuncTest004, TestSize.Level1)
157 {
158 string locale = "en-IN";
159 string expects = "+1,23,456.789";
160 vector<string> locales{locale};
161 string useGrouping = "true";
162 string minimumIntegerDigits = "7";
163 string maximumFractionDigits = "2";
164 string style = "currency";
165 string currency = "a#b";
166 map<string, string> options = { { "useGrouping", useGrouping },
167 { "style", style },
168 { "currency", currency },
169 { "currencyDisplay", "name" },
170 { "currencySign", "accounting" },
171 { "signDisplay", "always" } };
172 std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
173 ASSERT_TRUE(numFmt != nullptr);
174 string out = numFmt->Format(123456.789);
175 EXPECT_EQ(out, expects);
176 EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
177 EXPECT_EQ(numFmt->GetStyle(), style);
178 EXPECT_EQ(numFmt->GetCurrency(), "");
179 }
180
181 /**
182 * @tc.name: NumberFormatFuncTest005
183 * @tc.desc: Test Intl NumberFormat.format
184 * @tc.type: FUNC
185 */
186 HWTEST_F(NumberFormatTest, NumberFormatFuncTest005, TestSize.Level1)
187 {
188 string locale = "en-IN";
189 string expects = "+1,23,456.789";
190 vector<string> locales{locale};
191 string useGrouping = "true";
192 string minimumIntegerDigits = "7";
193 string maximumFractionDigits = "2";
194 string style = "currency";
195 string currency = "ab";
196 map<string, string> options = { { "useGrouping", useGrouping },
197 { "style", style },
198 { "currency", currency },
199 { "currencyDisplay", "name" },
200 { "currencySign", "accounting" },
201 { "signDisplay", "always" } };
202 std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
203 ASSERT_TRUE(numFmt != nullptr);
204 string out = numFmt->Format(123456.789);
205 EXPECT_EQ(out, expects);
206 EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
207 EXPECT_EQ(numFmt->GetStyle(), style);
208 EXPECT_EQ(numFmt->GetCurrency(), "");
209 }
210
211 /**
212 * @tc.name: NumberFormatFuncTest006
213 * @tc.desc: Test Intl NumberFormat.format
214 * @tc.type: FUNC
215 */
216 HWTEST_F(NumberFormatTest, NumberFormatFuncTest006, TestSize.Level1)
217 {
218 string locale = "en-IN";
219 string expects = "+1,23,456.789";
220 vector<string> locales{locale};
221 string useGrouping = "true";
222 string minimumIntegerDigits = "7";
223 string maximumFractionDigits = "2";
224 string style = "currency";
225 string currency = "abcd";
226 map<string, string> options = { { "useGrouping", useGrouping },
227 { "style", style },
228 { "currency", currency },
229 { "currencyDisplay", "name" },
230 { "currencySign", "accounting" },
231 { "signDisplay", "always" } };
232 std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
233 ASSERT_TRUE(numFmt != nullptr);
234 string out = numFmt->Format(123456.789);
235 EXPECT_EQ(out, expects);
236 EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
237 EXPECT_EQ(numFmt->GetStyle(), style);
238 EXPECT_EQ(numFmt->GetCurrency(), "");
239 }
240
241 /**
242 * @tc.name: NumberFormatFuncTest007
243 * @tc.desc: Test Intl NumberFormat.format
244 * @tc.type: FUNC
245 */
246 HWTEST_F(NumberFormatTest, NumberFormatFuncTest007, TestSize.Level1)
247 {
248 string localeCN = "zh-CN";
249 vector<string> localesCN{localeCN};
250 string localeUS = "en-US";
251 vector<string> localesUS{localeUS};
252 string localeGB = "en-GB";
253 vector<string> localesGB{localeGB};
254 string localeBO = "bo";
255 vector<string> localesBO{localeBO};
256 string localeUG = "ug";
257 vector<string> localesUG{localeUG};
258 string localeHK = "zh-HK";
259 vector<string> localesHK{localeHK};
260 string localeTW = "zh-TW";
261 vector<string> localesTW{localeTW};
262 string style = "unit";
263 string unit = "beat-per-minute";
264 string unitStyle = "long";
265 map<string, string> options = { { "style", style},
266 { "unit", unit },
267 { "unitStyle", unitStyle } };
268 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
269 ASSERT_TRUE(numFmtCN != nullptr);
270 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟");
271 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
272 ASSERT_TRUE(numFmtUS != nullptr);
273 EXPECT_EQ(numFmtUS->Format(1), "1 bpm");
274 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 bpm");
275 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
276 ASSERT_TRUE(numFmtGB != nullptr);
277 EXPECT_EQ(numFmtGB->Format(1), "1 bpm");
278 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 bpm");
279 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
280 ASSERT_TRUE(numFmtBO != nullptr);
281 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89");
282 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
283 ASSERT_TRUE(numFmtUG != nullptr);
284 EXPECT_EQ(numFmtUG->Format(1), "1 ق/م");
285 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م");
286 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
287 ASSERT_TRUE(numFmtHK != nullptr);
288 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
289 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
290 ASSERT_TRUE(numFmtTW != nullptr);
291 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘");
292 }
293
294 /**
295 * @tc.name: NumberFormatFuncTest008
296 * @tc.desc: Test Intl NumberFormat.format
297 * @tc.type: FUNC
298 */
299 HWTEST_F(NumberFormatTest, NumberFormatFuncTest008, TestSize.Level1)
300 {
301 string localeCN = "zh-CN";
302 vector<string> localesCN{localeCN};
303 string localeUS = "en-US";
304 vector<string> localesUS{localeUS};
305 string localeGB = "en-GB";
306 vector<string> localesGB{localeGB};
307 string localeBO = "bo";
308 vector<string> localesBO{localeBO};
309 string localeUG = "ug";
310 vector<string> localesUG{localeUG};
311 string localeHK = "zh-HK";
312 vector<string> localesHK{localeHK};
313 string localeTW = "zh-TW";
314 vector<string> localesTW{localeTW};
315 string style = "unit";
316 string unit = "beat-per-minute";
317 string unitStyle = "short";
318 map<string, string> options = { { "style", style},
319 { "unit", unit },
320 { "unitStyle", unitStyle } };
321 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
322 ASSERT_TRUE(numFmtCN != nullptr);
323 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟");
324 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
325 ASSERT_TRUE(numFmtUS != nullptr);
326 EXPECT_EQ(numFmtUS->Format(1), "1 bpm");
327 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 bpm");
328 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
329 ASSERT_TRUE(numFmtGB != nullptr);
330 EXPECT_EQ(numFmtGB->Format(1), "1 bpm");
331 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 bpm");
332 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
333 ASSERT_TRUE(numFmtBO != nullptr);
334 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89");
335 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
336 ASSERT_TRUE(numFmtUG != nullptr);
337 EXPECT_EQ(numFmtUG->Format(1), "1 ق/م");
338 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م");
339 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
340 ASSERT_TRUE(numFmtHK != nullptr);
341 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
342 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
343 ASSERT_TRUE(numFmtTW != nullptr);
344 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘");
345 }
346
347 /**
348 * @tc.name: NumberFormatFuncTest009
349 * @tc.desc: Test Intl NumberFormat.format
350 * @tc.type: FUNC
351 */
352 HWTEST_F(NumberFormatTest, NumberFormatFuncTest009, TestSize.Level1)
353 {
354 string localeCN = "zh-CN";
355 vector<string> localesCN{localeCN};
356 string localeUS = "en-US";
357 vector<string> localesUS{localeUS};
358 string localeGB = "en-GB";
359 vector<string> localesGB{localeGB};
360 string localeBO = "bo";
361 vector<string> localesBO{localeBO};
362 string localeUG = "ug";
363 vector<string> localesUG{localeUG};
364 string localeHK = "zh-HK";
365 vector<string> localesHK{localeHK};
366 string localeTW = "zh-TW";
367 vector<string> localesTW{localeTW};
368 string style = "unit";
369 string unit = "beat-per-minute";
370 string unitStyle = "narrow";
371 map<string, string> options = { { "style", style},
372 { "unit", unit },
373 { "unitStyle", unitStyle } };
374 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
375 ASSERT_TRUE(numFmtCN != nullptr);
376 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟");
377 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
378 ASSERT_TRUE(numFmtUS != nullptr);
379 EXPECT_EQ(numFmtUS->Format(1), "1 bpm");
380 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 bpm");
381 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
382 ASSERT_TRUE(numFmtGB != nullptr);
383 EXPECT_EQ(numFmtGB->Format(1), "1 bpm");
384 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 bpm");
385 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
386 ASSERT_TRUE(numFmtBO != nullptr);
387 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89");
388 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
389 ASSERT_TRUE(numFmtUG != nullptr);
390 EXPECT_EQ(numFmtUG->Format(1), "1 ق/م");
391 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م");
392 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
393 ASSERT_TRUE(numFmtHK != nullptr);
394 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
395 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
396 ASSERT_TRUE(numFmtTW != nullptr);
397 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘");
398 }
399
400 /**
401 * @tc.name: NumberFormatFuncTest0010
402 * @tc.desc: Test Intl NumberFormat.format
403 * @tc.type: FUNC
404 */
405 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0010, TestSize.Level1)
406 {
407 string localeCN = "zh-CN";
408 vector<string> localesCN{localeCN};
409 string localeUS = "en-US";
410 vector<string> localesUS{localeUS};
411 string localeGB = "en-GB";
412 vector<string> localesGB{localeGB};
413 string localeBO = "bo";
414 vector<string> localesBO{localeBO};
415 string localeUG = "ug";
416 vector<string> localesUG{localeUG};
417 string localeHK = "zh-HK";
418 vector<string> localesHK{localeHK};
419 string localeTW = "zh-TW";
420 vector<string> localesTW{localeTW};
421 string style = "unit";
422 string unit = "body-weight-per-second";
423 string unitStyle = "long";
424 map<string, string> options = { { "style", style},
425 { "unit", unit },
426 { "unitStyle", unitStyle } };
427 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
428 ASSERT_TRUE(numFmtCN != nullptr);
429 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 BW/s");
430 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
431 ASSERT_TRUE(numFmtUS != nullptr);
432 EXPECT_EQ(numFmtUS->Format(1), "1 BW/s");
433 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 BW/s");
434 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
435 ASSERT_TRUE(numFmtGB != nullptr);
436 EXPECT_EQ(numFmtGB->Format(1), "1 BW/s");
437 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 BW/s");
438 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
439 ASSERT_TRUE(numFmtBO != nullptr);
440 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 BW/s");
441 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
442 ASSERT_TRUE(numFmtUG != nullptr);
443 EXPECT_EQ(numFmtUG->Format(1), "1 BW/s");
444 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 BW/s");
445 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
446 ASSERT_TRUE(numFmtHK != nullptr);
447 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 體重/秒");
448 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
449 ASSERT_TRUE(numFmtTW != nullptr);
450 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 BW/s");
451 }
452
453 /**
454 * @tc.name: NumberFormatFuncTest0011
455 * @tc.desc: Test Intl NumberFormat.format
456 * @tc.type: FUNC
457 */
458 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0011, TestSize.Level1)
459 {
460 string localeCN = "zh-CN";
461 vector<string> localesCN{localeCN};
462 string localeUS = "en-US";
463 vector<string> localesUS{localeUS};
464 string localeGB = "en-GB";
465 vector<string> localesGB{localeGB};
466 string localeBO = "bo";
467 vector<string> localesBO{localeBO};
468 string localeUG = "ug";
469 vector<string> localesUG{localeUG};
470 string localeHK = "zh-HK";
471 vector<string> localesHK{localeHK};
472 string localeTW = "zh-TW";
473 vector<string> localesTW{localeTW};
474 string style = "unit";
475 string unit = "body-weight-per-second";
476 string unitStyle = "short";
477 map<string, string> options = { { "style", style},
478 { "unit", unit },
479 { "unitStyle", unitStyle } };
480 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
481 ASSERT_TRUE(numFmtCN != nullptr);
482 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 BW/s");
483 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
484 ASSERT_TRUE(numFmtUS != nullptr);
485 EXPECT_EQ(numFmtUS->Format(1), "1 BW/s");
486 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 BW/s");
487 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
488 ASSERT_TRUE(numFmtGB != nullptr);
489 EXPECT_EQ(numFmtGB->Format(1), "1 BW/s");
490 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 BW/s");
491 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
492 ASSERT_TRUE(numFmtBO != nullptr);
493 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 BW/s");
494 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
495 ASSERT_TRUE(numFmtUG != nullptr);
496 EXPECT_EQ(numFmtUG->Format(1), "1 BW/s");
497 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 BW/s");
498 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
499 ASSERT_TRUE(numFmtHK != nullptr);
500 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 體重/秒");
501 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
502 ASSERT_TRUE(numFmtTW != nullptr);
503 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 BW/s");
504 }
505
506 /**
507 * @tc.name: NumberFormatFuncTest0012
508 * @tc.desc: Test Intl NumberFormat.format
509 * @tc.type: FUNC
510 */
511 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0012, TestSize.Level1)
512 {
513 string localeCN = "zh-CN";
514 vector<string> localesCN{localeCN};
515 string localeUS = "en-US";
516 vector<string> localesUS{localeUS};
517 string localeGB = "en-GB";
518 vector<string> localesGB{localeGB};
519 string localeBO = "bo";
520 vector<string> localesBO{localeBO};
521 string localeUG = "ug";
522 vector<string> localesUG{localeUG};
523 string localeHK = "zh-HK";
524 vector<string> localesHK{localeHK};
525 string localeTW = "zh-TW";
526 vector<string> localesTW{localeTW};
527 string style = "unit";
528 string unit = "body-weight-per-second";
529 string unitStyle = "narrow";
530 map<string, string> options = { { "style", style},
531 { "unit", unit },
532 { "unitStyle", unitStyle } };
533 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
534 ASSERT_TRUE(numFmtCN != nullptr);
535 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 BW/s");
536 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
537 ASSERT_TRUE(numFmtUS != nullptr);
538 EXPECT_EQ(numFmtUS->Format(1), "1 BW/s");
539 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 BW/s");
540 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
541 ASSERT_TRUE(numFmtGB != nullptr);
542 EXPECT_EQ(numFmtGB->Format(1), "1 BW/s");
543 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 BW/s");
544 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
545 ASSERT_TRUE(numFmtBO != nullptr);
546 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 BW/s");
547 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
548 ASSERT_TRUE(numFmtUG != nullptr);
549 EXPECT_EQ(numFmtUG->Format(1), "1 BW/s");
550 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 BW/s");
551 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
552 ASSERT_TRUE(numFmtHK != nullptr);
553 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 體重/秒");
554 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
555 ASSERT_TRUE(numFmtTW != nullptr);
556 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 BW/s");
557 }
558
559 /**
560 * @tc.name: NumberFormatFuncTest0013
561 * @tc.desc: Test Intl NumberFormat.format
562 * @tc.type: FUNC
563 */
564 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0013, TestSize.Level1)
565 {
566 string localeCN = "zh-CN";
567 vector<string> localesCN{localeCN};
568 string localeUS = "en-US";
569 vector<string> localesUS{localeUS};
570 string localeGB = "en-GB";
571 vector<string> localesGB{localeGB};
572 string localeBO = "bo";
573 vector<string> localesBO{localeBO};
574 string localeUG = "ug";
575 vector<string> localesUG{localeUG};
576 string localeHK = "zh-HK";
577 vector<string> localesHK{localeHK};
578 string localeTW = "zh-TW";
579 vector<string> localesTW{localeTW};
580 string style = "unit";
581 string unit = "breath-per-minute";
582 string unitStyle = "long";
583 map<string, string> options = { { "style", style},
584 { "unit", unit },
585 { "unitStyle", unitStyle } };
586 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
587 ASSERT_TRUE(numFmtCN != nullptr);
588 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分");
589 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
590 ASSERT_TRUE(numFmtUS != nullptr);
591 EXPECT_EQ(numFmtUS->Format(1), "1 brpm");
592 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 brpm");
593 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
594 ASSERT_TRUE(numFmtGB != nullptr);
595 EXPECT_EQ(numFmtGB->Format(1), "1 brpm");
596 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 brpm");
597 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
598 ASSERT_TRUE(numFmtBO != nullptr);
599 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89");
600 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
601 ASSERT_TRUE(numFmtUG != nullptr);
602 EXPECT_EQ(numFmtUG->Format(1), "1 ق/م");
603 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م");
604 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
605 ASSERT_TRUE(numFmtHK != nullptr);
606 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
607 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
608 ASSERT_TRUE(numFmtTW != nullptr);
609 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分");
610 }
611
612 /**
613 * @tc.name: NumberFormatFuncTest0014
614 * @tc.desc: Test Intl NumberFormat.format
615 * @tc.type: FUNC
616 */
617 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0014, TestSize.Level1)
618 {
619 string localeCN = "zh-CN";
620 vector<string> localesCN{localeCN};
621 string localeUS = "en-US";
622 vector<string> localesUS{localeUS};
623 string localeGB = "en-GB";
624 vector<string> localesGB{localeGB};
625 string localeBO = "bo";
626 vector<string> localesBO{localeBO};
627 string localeUG = "ug";
628 vector<string> localesUG{localeUG};
629 string localeHK = "zh-HK";
630 vector<string> localesHK{localeHK};
631 string localeTW = "zh-TW";
632 vector<string> localesTW{localeTW};
633 string style = "unit";
634 string unit = "breath-per-minute";
635 string unitStyle = "short";
636 map<string, string> options = { { "style", style},
637 { "unit", unit },
638 { "unitStyle", unitStyle } };
639 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
640 ASSERT_TRUE(numFmtCN != nullptr);
641 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分");
642 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
643 ASSERT_TRUE(numFmtUS != nullptr);
644 EXPECT_EQ(numFmtUS->Format(1), "1 brpm");
645 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 brpm");
646 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
647 ASSERT_TRUE(numFmtGB != nullptr);
648 EXPECT_EQ(numFmtGB->Format(1), "1 brpm");
649 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 brpm");
650 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
651 ASSERT_TRUE(numFmtBO != nullptr);
652 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89");
653 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
654 ASSERT_TRUE(numFmtUG != nullptr);
655 EXPECT_EQ(numFmtUG->Format(1), "1 ق/م");
656 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م");
657 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
658 ASSERT_TRUE(numFmtHK != nullptr);
659 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
660 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
661 ASSERT_TRUE(numFmtTW != nullptr);
662 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分");
663 }
664
665 /**
666 * @tc.name: NumberFormatFuncTest0015
667 * @tc.desc: Test Intl NumberFormat.format
668 * @tc.type: FUNC
669 */
670 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0015, TestSize.Level1)
671 {
672 string localeCN = "zh-CN";
673 vector<string> localesCN{localeCN};
674 string localeUS = "en-US";
675 vector<string> localesUS{localeUS};
676 string localeGB = "en-GB";
677 vector<string> localesGB{localeGB};
678 string localeBO = "bo";
679 vector<string> localesBO{localeBO};
680 string localeUG = "ug";
681 vector<string> localesUG{localeUG};
682 string localeHK = "zh-HK";
683 vector<string> localesHK{localeHK};
684 string localeTW = "zh-TW";
685 vector<string> localesTW{localeTW};
686 string style = "unit";
687 string unit = "breath-per-minute";
688 string unitStyle = "narrow";
689 map<string, string> options = { { "style", style},
690 { "unit", unit },
691 { "unitStyle", unitStyle } };
692 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
693 ASSERT_TRUE(numFmtCN != nullptr);
694 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分");
695 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
696 ASSERT_TRUE(numFmtUS != nullptr);
697 EXPECT_EQ(numFmtUS->Format(1), "1 brpm");
698 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 brpm");
699 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
700 ASSERT_TRUE(numFmtGB != nullptr);
701 EXPECT_EQ(numFmtGB->Format(1), "1 brpm");
702 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 brpm");
703 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
704 ASSERT_TRUE(numFmtBO != nullptr);
705 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89");
706 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
707 ASSERT_TRUE(numFmtUG != nullptr);
708 EXPECT_EQ(numFmtUG->Format(1), "1 ق/م");
709 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م");
710 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
711 ASSERT_TRUE(numFmtHK != nullptr);
712 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
713 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
714 ASSERT_TRUE(numFmtTW != nullptr);
715 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分");
716 }
717
718 /**
719 * @tc.name: NumberFormatFuncTest0016
720 * @tc.desc: Test Intl NumberFormat.format
721 * @tc.type: FUNC
722 */
723 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0016, TestSize.Level1)
724 {
725 string localeCN = "zh-CN";
726 vector<string> localesCN{localeCN};
727 string localeUS = "en-US";
728 vector<string> localesUS{localeUS};
729 string localeGB = "en-GB";
730 vector<string> localesGB{localeGB};
731 string localeBO = "bo";
732 vector<string> localesBO{localeBO};
733 string localeUG = "ug";
734 vector<string> localesUG{localeUG};
735 string localeHK = "zh-HK";
736 vector<string> localesHK{localeHK};
737 string localeTW = "zh-TW";
738 vector<string> localesTW{localeTW};
739 string style = "unit";
740 string unit = "foot-per-hour";
741 string unitStyle = "long";
742 map<string, string> options = { { "style", style},
743 { "unit", unit },
744 { "unitStyle", unitStyle } };
745 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
746 ASSERT_TRUE(numFmtCN != nullptr);
747 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 英尺/小时");
748 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
749 ASSERT_TRUE(numFmtUS != nullptr);
750 EXPECT_EQ(numFmtUS->Format(1), "1 ft/h");
751 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ft/h");
752 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
753 ASSERT_TRUE(numFmtGB != nullptr);
754 EXPECT_EQ(numFmtGB->Format(1), "1 ft/h");
755 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ft/h");
756 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
757 ASSERT_TRUE(numFmtBO != nullptr);
758 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ft/h");
759 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
760 ASSERT_TRUE(numFmtUG != nullptr);
761 EXPECT_EQ(numFmtUG->Format(1), "1 ft/h");
762 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ft/h");
763 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
764 ASSERT_TRUE(numFmtHK != nullptr);
765 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 呎/小時");
766 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
767 ASSERT_TRUE(numFmtTW != nullptr);
768 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 英尺/小時");
769 }
770
771 /**
772 * @tc.name: NumberFormatFuncTest0017
773 * @tc.desc: Test Intl NumberFormat.format
774 * @tc.type: FUNC
775 */
776 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0017, TestSize.Level1)
777 {
778 string localeCN = "zh-CN";
779 vector<string> localesCN{localeCN};
780 string localeUS = "en-US";
781 vector<string> localesUS{localeUS};
782 string localeGB = "en-GB";
783 vector<string> localesGB{localeGB};
784 string localeBO = "bo";
785 vector<string> localesBO{localeBO};
786 string localeUG = "ug";
787 vector<string> localesUG{localeUG};
788 string localeHK = "zh-HK";
789 vector<string> localesHK{localeHK};
790 string localeTW = "zh-TW";
791 vector<string> localesTW{localeTW};
792 string style = "unit";
793 string unit = "foot-per-hour";
794 string unitStyle = "short";
795 map<string, string> options = { { "style", style},
796 { "unit", unit },
797 { "unitStyle", unitStyle } };
798 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
799 ASSERT_TRUE(numFmtCN != nullptr);
800 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 英尺/小时");
801 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
802 ASSERT_TRUE(numFmtUS != nullptr);
803 EXPECT_EQ(numFmtUS->Format(1), "1 ft/h");
804 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ft/h");
805 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
806 ASSERT_TRUE(numFmtGB != nullptr);
807 EXPECT_EQ(numFmtGB->Format(1), "1 ft/h");
808 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ft/h");
809 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
810 ASSERT_TRUE(numFmtBO != nullptr);
811 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ft/h");
812 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
813 ASSERT_TRUE(numFmtUG != nullptr);
814 EXPECT_EQ(numFmtUG->Format(1), "1 ft/h");
815 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ft/h");
816 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
817 ASSERT_TRUE(numFmtHK != nullptr);
818 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 呎/小時");
819 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
820 ASSERT_TRUE(numFmtTW != nullptr);
821 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 英尺/小時");
822 }
823
824 /**
825 * @tc.name: NumberFormatFuncTest0018
826 * @tc.desc: Test Intl NumberFormat.format
827 * @tc.type: FUNC
828 */
829 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0018, TestSize.Level1)
830 {
831 string localeCN = "zh-CN";
832 vector<string> localesCN{localeCN};
833 string localeUS = "en-US";
834 vector<string> localesUS{localeUS};
835 string localeGB = "en-GB";
836 vector<string> localesGB{localeGB};
837 string localeBO = "bo";
838 vector<string> localesBO{localeBO};
839 string localeUG = "ug";
840 vector<string> localesUG{localeUG};
841 string localeHK = "zh-HK";
842 vector<string> localesHK{localeHK};
843 string localeTW = "zh-TW";
844 vector<string> localesTW{localeTW};
845 string style = "unit";
846 string unit = "foot-per-hour";
847 string unitStyle = "narrow";
848 map<string, string> options = { { "style", style},
849 { "unit", unit },
850 { "unitStyle", unitStyle } };
851 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
852 ASSERT_TRUE(numFmtCN != nullptr);
853 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 英尺/小时");
854 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
855 ASSERT_TRUE(numFmtUS != nullptr);
856 EXPECT_EQ(numFmtUS->Format(1), "1 ft/h");
857 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ft/h");
858 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
859 ASSERT_TRUE(numFmtGB != nullptr);
860 EXPECT_EQ(numFmtGB->Format(1), "1 ft/h");
861 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ft/h");
862 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
863 ASSERT_TRUE(numFmtBO != nullptr);
864 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ft/h");
865 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
866 ASSERT_TRUE(numFmtUG != nullptr);
867 EXPECT_EQ(numFmtUG->Format(1), "1 ft/h");
868 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ft/h");
869 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
870 ASSERT_TRUE(numFmtHK != nullptr);
871 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 呎/小時");
872 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
873 ASSERT_TRUE(numFmtTW != nullptr);
874 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 英尺/小時");
875 }
876
877 /**
878 * @tc.name: NumberFormatFuncTest0019
879 * @tc.desc: Test Intl NumberFormat.format
880 * @tc.type: FUNC
881 */
882 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0019, TestSize.Level1)
883 {
884 string localeCN = "zh-CN";
885 vector<string> localesCN{localeCN};
886 string localeUS = "en-US";
887 vector<string> localesUS{localeUS};
888 string localeGB = "en-GB";
889 vector<string> localesGB{localeGB};
890 string localeBO = "bo";
891 vector<string> localesBO{localeBO};
892 string localeUG = "ug";
893 vector<string> localesUG{localeUG};
894 string localeHK = "zh-HK";
895 vector<string> localesHK{localeHK};
896 string localeTW = "zh-TW";
897 vector<string> localesTW{localeTW};
898 string style = "unit";
899 string unit = "jump-rope-per-minute";
900 string unitStyle = "long";
901 map<string, string> options = { { "style", style},
902 { "unit", unit },
903 { "unitStyle", unitStyle } };
904 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
905 ASSERT_TRUE(numFmtCN != nullptr);
906 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 个/分钟");
907 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
908 ASSERT_TRUE(numFmtUS != nullptr);
909 EXPECT_EQ(numFmtUS->Format(1), "1 jump/minute");
910 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 jumps/minute");
911 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
912 ASSERT_TRUE(numFmtGB != nullptr);
913 EXPECT_EQ(numFmtGB->Format(1), "1 skip/minute");
914 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 skips/minute");
915 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
916 ASSERT_TRUE(numFmtBO != nullptr);
917 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ 1,234,567.89");
918 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
919 ASSERT_TRUE(numFmtUG != nullptr);
920 EXPECT_EQ(numFmtUG->Format(1), "1 ئاتلام/مىنۇت");
921 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ئاتلام/مىنۇت");
922 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
923 ASSERT_TRUE(numFmtHK != nullptr);
924 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
925 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
926 ASSERT_TRUE(numFmtTW != nullptr);
927 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 個/分鐘");
928 }
929
930 /**
931 * @tc.name: NumberFormatFuncTest0020
932 * @tc.desc: Test Intl NumberFormat.format
933 * @tc.type: FUNC
934 */
935 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0020, TestSize.Level1)
936 {
937 string localeCN = "zh-CN";
938 vector<string> localesCN{localeCN};
939 string localeUS = "en-US";
940 vector<string> localesUS{localeUS};
941 string localeGB = "en-GB";
942 vector<string> localesGB{localeGB};
943 string localeBO = "bo";
944 vector<string> localesBO{localeBO};
945 string localeUG = "ug";
946 vector<string> localesUG{localeUG};
947 string localeHK = "zh-HK";
948 vector<string> localesHK{localeHK};
949 string localeTW = "zh-TW";
950 vector<string> localesTW{localeTW};
951 string style = "unit";
952 string unit = "jump-rope-per-minute";
953 string unitStyle = "short";
954 map<string, string> options = { { "style", style},
955 { "unit", unit },
956 { "unitStyle", unitStyle } };
957 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
958 ASSERT_TRUE(numFmtCN != nullptr);
959 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 个/分钟");
960 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
961 ASSERT_TRUE(numFmtUS != nullptr);
962 EXPECT_EQ(numFmtUS->Format(1), "1 jump/minute");
963 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 jumps/minute");
964 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
965 ASSERT_TRUE(numFmtGB != nullptr);
966 EXPECT_EQ(numFmtGB->Format(1), "1 skip/minute");
967 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 skips/minute");
968 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
969 ASSERT_TRUE(numFmtBO != nullptr);
970 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ 1,234,567.89");
971 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
972 ASSERT_TRUE(numFmtUG != nullptr);
973 EXPECT_EQ(numFmtUG->Format(1), "1 ئاتلام/مىنۇت");
974 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ئاتلام/مىنۇت");
975 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
976 ASSERT_TRUE(numFmtHK != nullptr);
977 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
978 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
979 ASSERT_TRUE(numFmtTW != nullptr);
980 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 個/分鐘");
981 }
982
983 /**
984 * @tc.name: NumberFormatFuncTest0021
985 * @tc.desc: Test Intl NumberFormat.format
986 * @tc.type: FUNC
987 */
988 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0021, TestSize.Level1)
989 {
990 string localeCN = "zh-CN";
991 vector<string> localesCN{localeCN};
992 string localeUS = "en-US";
993 vector<string> localesUS{localeUS};
994 string localeGB = "en-GB";
995 vector<string> localesGB{localeGB};
996 string localeBO = "bo";
997 vector<string> localesBO{localeBO};
998 string localeUG = "ug";
999 vector<string> localesUG{localeUG};
1000 string localeHK = "zh-HK";
1001 vector<string> localesHK{localeHK};
1002 string localeTW = "zh-TW";
1003 vector<string> localesTW{localeTW};
1004 string style = "unit";
1005 string unit = "jump-rope-per-minute";
1006 string unitStyle = "narrow";
1007 map<string, string> options = { { "style", style},
1008 { "unit", unit },
1009 { "unitStyle", unitStyle } };
1010 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1011 ASSERT_TRUE(numFmtCN != nullptr);
1012 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 个/分钟");
1013 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1014 ASSERT_TRUE(numFmtUS != nullptr);
1015 EXPECT_EQ(numFmtUS->Format(1), "1 jump/minute");
1016 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 jumps/minute");
1017 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1018 ASSERT_TRUE(numFmtGB != nullptr);
1019 EXPECT_EQ(numFmtGB->Format(1), "1 skip/minute");
1020 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 skips/minute");
1021 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1022 ASSERT_TRUE(numFmtBO != nullptr);
1023 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ 1,234,567.89");
1024 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1025 ASSERT_TRUE(numFmtUG != nullptr);
1026 EXPECT_EQ(numFmtUG->Format(1), "1 ئاتلام/مىنۇت");
1027 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ئاتلام/مىنۇت");
1028 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1029 ASSERT_TRUE(numFmtHK != nullptr);
1030 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
1031 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1032 ASSERT_TRUE(numFmtTW != nullptr);
1033 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 個/分鐘");
1034 }
1035
1036 /**
1037 * @tc.name: NumberFormatFuncTest0022
1038 * @tc.desc: Test Intl NumberFormat.format
1039 * @tc.type: FUNC
1040 */
1041 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0022, TestSize.Level1)
1042 {
1043 string localeCN = "zh-CN";
1044 vector<string> localesCN{localeCN};
1045 string localeUS = "en-US";
1046 vector<string> localesUS{localeUS};
1047 string localeGB = "en-GB";
1048 vector<string> localesGB{localeGB};
1049 string localeBO = "bo";
1050 vector<string> localesBO{localeBO};
1051 string localeUG = "ug";
1052 vector<string> localesUG{localeUG};
1053 string localeHK = "zh-HK";
1054 vector<string> localesHK{localeHK};
1055 string localeTW = "zh-TW";
1056 vector<string> localesTW{localeTW};
1057 string style = "unit";
1058 string unit = "meter-per-hour";
1059 string unitStyle = "long";
1060 map<string, string> options = { { "style", style},
1061 { "unit", unit },
1062 { "unitStyle", unitStyle } };
1063 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1064 ASSERT_TRUE(numFmtCN != nullptr);
1065 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 米/小时");
1066 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1067 ASSERT_TRUE(numFmtUS != nullptr);
1068 EXPECT_EQ(numFmtUS->Format(1), "1 m/h");
1069 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 m/h");
1070 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1071 ASSERT_TRUE(numFmtGB != nullptr);
1072 EXPECT_EQ(numFmtGB->Format(1), "1 m/h");
1073 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 m/h");
1074 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1075 ASSERT_TRUE(numFmtBO != nullptr);
1076 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 m/h");
1077 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1078 ASSERT_TRUE(numFmtUG != nullptr);
1079 EXPECT_EQ(numFmtUG->Format(1), "1 m/h");
1080 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 m/h");
1081 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1082 ASSERT_TRUE(numFmtHK != nullptr);
1083 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 米/小時");
1084 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1085 ASSERT_TRUE(numFmtTW != nullptr);
1086 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 公尺/小時");
1087 }
1088
1089 /**
1090 * @tc.name: NumberFormatFuncTest0023
1091 * @tc.desc: Test Intl NumberFormat.format
1092 * @tc.type: FUNC
1093 */
1094 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0023, TestSize.Level1)
1095 {
1096 string localeCN = "zh-CN";
1097 vector<string> localesCN{localeCN};
1098 string localeUS = "en-US";
1099 vector<string> localesUS{localeUS};
1100 string localeGB = "en-GB";
1101 vector<string> localesGB{localeGB};
1102 string localeBO = "bo";
1103 vector<string> localesBO{localeBO};
1104 string localeUG = "ug";
1105 vector<string> localesUG{localeUG};
1106 string localeHK = "zh-HK";
1107 vector<string> localesHK{localeHK};
1108 string localeTW = "zh-TW";
1109 vector<string> localesTW{localeTW};
1110 string style = "unit";
1111 string unit = "meter-per-hour";
1112 string unitStyle = "short";
1113 map<string, string> options = { { "style", style},
1114 { "unit", unit },
1115 { "unitStyle", unitStyle } };
1116 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1117 ASSERT_TRUE(numFmtCN != nullptr);
1118 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 米/小时");
1119 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1120 ASSERT_TRUE(numFmtUS != nullptr);
1121 EXPECT_EQ(numFmtUS->Format(1), "1 m/h");
1122 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 m/h");
1123 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1124 ASSERT_TRUE(numFmtGB != nullptr);
1125 EXPECT_EQ(numFmtGB->Format(1), "1 m/h");
1126 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 m/h");
1127 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1128 ASSERT_TRUE(numFmtBO != nullptr);
1129 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 m/h");
1130 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1131 ASSERT_TRUE(numFmtUG != nullptr);
1132 EXPECT_EQ(numFmtUG->Format(1), "1 m/h");
1133 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 m/h");
1134 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1135 ASSERT_TRUE(numFmtHK != nullptr);
1136 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 米/小時");
1137 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1138 ASSERT_TRUE(numFmtTW != nullptr);
1139 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 公尺/小時");
1140 }
1141
1142 /**
1143 * @tc.name: NumberFormatFuncTest0024
1144 * @tc.desc: Test Intl NumberFormat.format
1145 * @tc.type: FUNC
1146 */
1147 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0024, TestSize.Level1)
1148 {
1149 string localeCN = "zh-CN";
1150 vector<string> localesCN{localeCN};
1151 string localeUS = "en-US";
1152 vector<string> localesUS{localeUS};
1153 string localeGB = "en-GB";
1154 vector<string> localesGB{localeGB};
1155 string localeBO = "bo";
1156 vector<string> localesBO{localeBO};
1157 string localeUG = "ug";
1158 vector<string> localesUG{localeUG};
1159 string localeHK = "zh-HK";
1160 vector<string> localesHK{localeHK};
1161 string localeTW = "zh-TW";
1162 vector<string> localesTW{localeTW};
1163 string style = "unit";
1164 string unit = "meter-per-hour";
1165 string unitStyle = "narrow";
1166 map<string, string> options = { { "style", style},
1167 { "unit", unit },
1168 { "unitStyle", unitStyle } };
1169 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1170 ASSERT_TRUE(numFmtCN != nullptr);
1171 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 米/小时");
1172 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1173 ASSERT_TRUE(numFmtUS != nullptr);
1174 EXPECT_EQ(numFmtUS->Format(1), "1 m/h");
1175 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 m/h");
1176 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1177 ASSERT_TRUE(numFmtGB != nullptr);
1178 EXPECT_EQ(numFmtGB->Format(1), "1 m/h");
1179 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 m/h");
1180 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1181 ASSERT_TRUE(numFmtBO != nullptr);
1182 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 m/h");
1183 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1184 ASSERT_TRUE(numFmtUG != nullptr);
1185 EXPECT_EQ(numFmtUG->Format(1), "1 m/h");
1186 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 m/h");
1187 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1188 ASSERT_TRUE(numFmtHK != nullptr);
1189 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 米/小時");
1190 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1191 ASSERT_TRUE(numFmtTW != nullptr);
1192 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 公尺/小時");
1193 }
1194
1195 /**
1196 * @tc.name: NumberFormatFuncTest0025
1197 * @tc.desc: Test Intl NumberFormat.format
1198 * @tc.type: FUNC
1199 */
1200 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0025, TestSize.Level1)
1201 {
1202 string localeCN = "zh-CN";
1203 vector<string> localesCN{localeCN};
1204 string localeUS = "en-US";
1205 vector<string> localesUS{localeUS};
1206 string localeGB = "en-GB";
1207 vector<string> localesGB{localeGB};
1208 string localeBO = "bo";
1209 vector<string> localesBO{localeBO};
1210 string localeUG = "ug";
1211 vector<string> localesUG{localeUG};
1212 string localeHK = "zh-HK";
1213 vector<string> localesHK{localeHK};
1214 string localeTW = "zh-TW";
1215 vector<string> localesTW{localeTW};
1216 string style = "unit";
1217 string unit = "milliliter-per-minute-per-kilogram";
1218 string unitStyle = "long";
1219 map<string, string> options = { { "style", style},
1220 { "unit", unit },
1221 { "unitStyle", unitStyle } };
1222 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1223 ASSERT_TRUE(numFmtCN != nullptr);
1224 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ml/kg/min");
1225 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1226 ASSERT_TRUE(numFmtUS != nullptr);
1227 EXPECT_EQ(numFmtUS->Format(1), "1 ml/kg/min");
1228 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ml/kg/min");
1229 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1230 ASSERT_TRUE(numFmtGB != nullptr);
1231 EXPECT_EQ(numFmtGB->Format(1), "1 ml/kg/min");
1232 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ml/kg/min");
1233 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1234 ASSERT_TRUE(numFmtBO != nullptr);
1235 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ml/kg/min");
1236 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1237 ASSERT_TRUE(numFmtUG != nullptr);
1238 EXPECT_EQ(numFmtUG->Format(1), "1 ml/kg/min");
1239 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ml/kg/min");
1240 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1241 ASSERT_TRUE(numFmtHK != nullptr);
1242 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 ml/kg/min");
1243 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1244 ASSERT_TRUE(numFmtTW != nullptr);
1245 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 ml/kg/min");
1246 }
1247
1248 /**
1249 * @tc.name: NumberFormatFuncTest0026
1250 * @tc.desc: Test Intl NumberFormat.format
1251 * @tc.type: FUNC
1252 */
1253 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0026, TestSize.Level1)
1254 {
1255 string localeCN = "zh-CN";
1256 vector<string> localesCN{localeCN};
1257 string localeUS = "en-US";
1258 vector<string> localesUS{localeUS};
1259 string localeGB = "en-GB";
1260 vector<string> localesGB{localeGB};
1261 string localeBO = "bo";
1262 vector<string> localesBO{localeBO};
1263 string localeUG = "ug";
1264 vector<string> localesUG{localeUG};
1265 string localeHK = "zh-HK";
1266 vector<string> localesHK{localeHK};
1267 string localeTW = "zh-TW";
1268 vector<string> localesTW{localeTW};
1269 string style = "unit";
1270 string unit = "milliliter-per-minute-per-kilogram";
1271 string unitStyle = "short";
1272 map<string, string> options = { { "style", style},
1273 { "unit", unit },
1274 { "unitStyle", unitStyle } };
1275 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1276 ASSERT_TRUE(numFmtCN != nullptr);
1277 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ml/kg/min");
1278 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1279 ASSERT_TRUE(numFmtUS != nullptr);
1280 EXPECT_EQ(numFmtUS->Format(1), "1 ml/kg/min");
1281 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ml/kg/min");
1282 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1283 ASSERT_TRUE(numFmtGB != nullptr);
1284 EXPECT_EQ(numFmtGB->Format(1), "1 ml/kg/min");
1285 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ml/kg/min");
1286 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1287 ASSERT_TRUE(numFmtBO != nullptr);
1288 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ml/kg/min");
1289 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1290 ASSERT_TRUE(numFmtUG != nullptr);
1291 EXPECT_EQ(numFmtUG->Format(1), "1 ml/kg/min");
1292 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ml/kg/min");
1293 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1294 ASSERT_TRUE(numFmtHK != nullptr);
1295 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 ml/kg/min");
1296 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1297 ASSERT_TRUE(numFmtTW != nullptr);
1298 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 ml/kg/min");
1299 }
1300
1301 /**
1302 * @tc.name: NumberFormatFuncTest0027
1303 * @tc.desc: Test Intl NumberFormat.format
1304 * @tc.type: FUNC
1305 */
1306 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0027, TestSize.Level1)
1307 {
1308 string localeCN = "zh-CN";
1309 vector<string> localesCN{localeCN};
1310 string localeUS = "en-US";
1311 vector<string> localesUS{localeUS};
1312 string localeGB = "en-GB";
1313 vector<string> localesGB{localeGB};
1314 string localeBO = "bo";
1315 vector<string> localesBO{localeBO};
1316 string localeUG = "ug";
1317 vector<string> localesUG{localeUG};
1318 string localeHK = "zh-HK";
1319 vector<string> localesHK{localeHK};
1320 string localeTW = "zh-TW";
1321 vector<string> localesTW{localeTW};
1322 string style = "unit";
1323 string unit = "milliliter-per-minute-per-kilogram";
1324 string unitStyle = "narrow";
1325 map<string, string> options = { { "style", style},
1326 { "unit", unit },
1327 { "unitStyle", unitStyle } };
1328 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1329 ASSERT_TRUE(numFmtCN != nullptr);
1330 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 ml/kg/min");
1331 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1332 ASSERT_TRUE(numFmtUS != nullptr);
1333 EXPECT_EQ(numFmtUS->Format(1), "1 ml/kg/min");
1334 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 ml/kg/min");
1335 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1336 ASSERT_TRUE(numFmtGB != nullptr);
1337 EXPECT_EQ(numFmtGB->Format(1), "1 ml/kg/min");
1338 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 ml/kg/min");
1339 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1340 ASSERT_TRUE(numFmtBO != nullptr);
1341 EXPECT_EQ(numFmtBO->Format(1234567.89), "1,234,567.89 ml/kg/min");
1342 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1343 ASSERT_TRUE(numFmtUG != nullptr);
1344 EXPECT_EQ(numFmtUG->Format(1), "1 ml/kg/min");
1345 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ml/kg/min");
1346 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1347 ASSERT_TRUE(numFmtHK != nullptr);
1348 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 ml/kg/min");
1349 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1350 ASSERT_TRUE(numFmtTW != nullptr);
1351 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 ml/kg/min");
1352 }
1353
1354 /**
1355 * @tc.name: NumberFormatFuncTest0028
1356 * @tc.desc: Test Intl NumberFormat.format
1357 * @tc.type: FUNC
1358 */
1359 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0028, TestSize.Level1)
1360 {
1361 string localeCN = "zh-CN";
1362 vector<string> localesCN{localeCN};
1363 string localeUS = "en-US";
1364 vector<string> localesUS{localeUS};
1365 string localeGB = "en-GB";
1366 vector<string> localesGB{localeGB};
1367 string localeBO = "bo";
1368 vector<string> localesBO{localeBO};
1369 string localeUG = "ug";
1370 vector<string> localesUG{localeUG};
1371 string localeHK = "zh-HK";
1372 vector<string> localesHK{localeHK};
1373 string localeTW = "zh-TW";
1374 vector<string> localesTW{localeTW};
1375 string style = "unit";
1376 string unit = "rotation-per-minute";
1377 string unitStyle = "long";
1378 map<string, string> options = { { "style", style},
1379 { "unit", unit },
1380 { "unitStyle", unitStyle } };
1381 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1382 ASSERT_TRUE(numFmtCN != nullptr);
1383 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 转/分钟");
1384 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1385 ASSERT_TRUE(numFmtUS != nullptr);
1386 EXPECT_EQ(numFmtUS->Format(1), "1 rpm");
1387 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 rpm");
1388 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1389 ASSERT_TRUE(numFmtGB != nullptr);
1390 EXPECT_EQ(numFmtGB->Format(1), "1 rpm");
1391 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 rpm");
1392 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1393 ASSERT_TRUE(numFmtBO != nullptr);
1394 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་སྐོར་བ་ 1,234,567.89");
1395 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1396 ASSERT_TRUE(numFmtUG != nullptr);
1397 EXPECT_EQ(numFmtUG->Format(1), "1 ق/م");
1398 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م");
1399 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1400 ASSERT_TRUE(numFmtHK != nullptr);
1401 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 轉/分鐘");
1402 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1403 ASSERT_TRUE(numFmtTW != nullptr);
1404 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 轉/分鐘");
1405 }
1406
1407 /**
1408 * @tc.name: NumberFormatFuncTest0029
1409 * @tc.desc: Test Intl NumberFormat.format
1410 * @tc.type: FUNC
1411 */
1412 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0029, TestSize.Level1)
1413 {
1414 string localeCN = "zh-CN";
1415 vector<string> localesCN{localeCN};
1416 string localeUS = "en-US";
1417 vector<string> localesUS{localeUS};
1418 string localeGB = "en-GB";
1419 vector<string> localesGB{localeGB};
1420 string localeBO = "bo";
1421 vector<string> localesBO{localeBO};
1422 string localeUG = "ug";
1423 vector<string> localesUG{localeUG};
1424 string localeHK = "zh-HK";
1425 vector<string> localesHK{localeHK};
1426 string localeTW = "zh-TW";
1427 vector<string> localesTW{localeTW};
1428 string style = "unit";
1429 string unit = "rotation-per-minute";
1430 string unitStyle = "short";
1431 map<string, string> options = { { "style", style},
1432 { "unit", unit },
1433 { "unitStyle", unitStyle } };
1434 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1435 ASSERT_TRUE(numFmtCN != nullptr);
1436 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 转/分钟");
1437 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1438 ASSERT_TRUE(numFmtUS != nullptr);
1439 EXPECT_EQ(numFmtUS->Format(1), "1 rpm");
1440 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 rpm");
1441 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1442 ASSERT_TRUE(numFmtGB != nullptr);
1443 EXPECT_EQ(numFmtGB->Format(1), "1 rpm");
1444 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 rpm");
1445 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1446 ASSERT_TRUE(numFmtBO != nullptr);
1447 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་སྐོར་བ་ 1,234,567.89");
1448 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1449 ASSERT_TRUE(numFmtUG != nullptr);
1450 EXPECT_EQ(numFmtUG->Format(1), "1 ق/م");
1451 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م");
1452 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1453 ASSERT_TRUE(numFmtHK != nullptr);
1454 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 轉/分鐘");
1455 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1456 ASSERT_TRUE(numFmtTW != nullptr);
1457 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 轉/分鐘");
1458 }
1459
1460 /**
1461 * @tc.name: NumberFormatFuncTest0030
1462 * @tc.desc: Test Intl NumberFormat.format
1463 * @tc.type: FUNC
1464 */
1465 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0030, TestSize.Level1)
1466 {
1467 string localeCN = "zh-CN";
1468 vector<string> localesCN{localeCN};
1469 string localeUS = "en-US";
1470 vector<string> localesUS{localeUS};
1471 string localeGB = "en-GB";
1472 vector<string> localesGB{localeGB};
1473 string localeBO = "bo";
1474 vector<string> localesBO{localeBO};
1475 string localeUG = "ug";
1476 vector<string> localesUG{localeUG};
1477 string localeHK = "zh-HK";
1478 vector<string> localesHK{localeHK};
1479 string localeTW = "zh-TW";
1480 vector<string> localesTW{localeTW};
1481 string style = "unit";
1482 string unit = "rotation-per-minute";
1483 string unitStyle = "narrow";
1484 map<string, string> options = { { "style", style},
1485 { "unit", unit },
1486 { "unitStyle", unitStyle } };
1487 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1488 ASSERT_TRUE(numFmtCN != nullptr);
1489 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 转/分钟");
1490 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1491 ASSERT_TRUE(numFmtUS != nullptr);
1492 EXPECT_EQ(numFmtUS->Format(1), "1 rpm");
1493 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 rpm");
1494 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1495 ASSERT_TRUE(numFmtGB != nullptr);
1496 EXPECT_EQ(numFmtGB->Format(1), "1 rpm");
1497 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 rpm");
1498 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1499 ASSERT_TRUE(numFmtBO != nullptr);
1500 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་སྐོར་བ་ 1,234,567.89");
1501 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1502 ASSERT_TRUE(numFmtUG != nullptr);
1503 EXPECT_EQ(numFmtUG->Format(1), "1 ق/م");
1504 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 ق/م");
1505 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1506 ASSERT_TRUE(numFmtHK != nullptr);
1507 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 轉/分鐘");
1508 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1509 ASSERT_TRUE(numFmtTW != nullptr);
1510 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 轉/分鐘");
1511 }
1512
1513 /**
1514 * @tc.name: NumberFormatFuncTest0031
1515 * @tc.desc: Test Intl NumberFormat.format
1516 * @tc.type: FUNC
1517 */
1518 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0031, TestSize.Level1)
1519 {
1520 string localeCN = "zh-CN";
1521 vector<string> localesCN{localeCN};
1522 string localeUS = "en-US";
1523 vector<string> localesUS{localeUS};
1524 string localeGB = "en-GB";
1525 vector<string> localesGB{localeGB};
1526 string localeBO = "bo";
1527 vector<string> localesBO{localeBO};
1528 string localeUG = "ug";
1529 vector<string> localesUG{localeUG};
1530 string localeHK = "zh-HK";
1531 vector<string> localesHK{localeHK};
1532 string localeTW = "zh-TW";
1533 vector<string> localesTW{localeTW};
1534 string style = "unit";
1535 string unit = "step-per-minute";
1536 string unitStyle = "long";
1537 map<string, string> options = { { "style", style},
1538 { "unit", unit },
1539 { "unitStyle", unitStyle } };
1540 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1541 ASSERT_TRUE(numFmtCN != nullptr);
1542 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 步/分钟");
1543 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1544 ASSERT_TRUE(numFmtUS != nullptr);
1545 EXPECT_EQ(numFmtUS->Format(1), "1 step/min");
1546 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 steps/min");
1547 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1548 ASSERT_TRUE(numFmtGB != nullptr);
1549 EXPECT_EQ(numFmtGB->Format(1), "1 step/min");
1550 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 steps/min");
1551 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1552 ASSERT_TRUE(numFmtBO != nullptr);
1553 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་གོམ་པ་ 1,234,567.89");
1554 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1555 ASSERT_TRUE(numFmtUG != nullptr);
1556 EXPECT_EQ(numFmtUG->Format(1), "1 قەدەم/مىنۇت");
1557 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 قەدەم/مىنۇت");
1558 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1559 ASSERT_TRUE(numFmtHK != nullptr);
1560 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 步/分鐘");
1561 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1562 ASSERT_TRUE(numFmtTW != nullptr);
1563 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 步/分鐘");
1564 }
1565
1566 /**
1567 * @tc.name: NumberFormatFuncTest0032
1568 * @tc.desc: Test Intl NumberFormat.format
1569 * @tc.type: FUNC
1570 */
1571 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0032, TestSize.Level1)
1572 {
1573 string localeCN = "zh-CN";
1574 vector<string> localesCN{localeCN};
1575 string localeUS = "en-US";
1576 vector<string> localesUS{localeUS};
1577 string localeGB = "en-GB";
1578 vector<string> localesGB{localeGB};
1579 string localeBO = "bo";
1580 vector<string> localesBO{localeBO};
1581 string localeUG = "ug";
1582 vector<string> localesUG{localeUG};
1583 string localeHK = "zh-HK";
1584 vector<string> localesHK{localeHK};
1585 string localeTW = "zh-TW";
1586 vector<string> localesTW{localeTW};
1587 string style = "unit";
1588 string unit = "step-per-minute";
1589 string unitStyle = "short";
1590 map<string, string> options = { { "style", style},
1591 { "unit", unit },
1592 { "unitStyle", unitStyle } };
1593 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1594 ASSERT_TRUE(numFmtCN != nullptr);
1595 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 步/分钟");
1596 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1597 ASSERT_TRUE(numFmtUS != nullptr);
1598 EXPECT_EQ(numFmtUS->Format(1), "1 step/min");
1599 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 steps/min");
1600 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1601 ASSERT_TRUE(numFmtGB != nullptr);
1602 EXPECT_EQ(numFmtGB->Format(1), "1 step/min");
1603 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 steps/min");
1604 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1605 ASSERT_TRUE(numFmtBO != nullptr);
1606 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་གོམ་པ་ 1,234,567.89");
1607 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1608 ASSERT_TRUE(numFmtUG != nullptr);
1609 EXPECT_EQ(numFmtUG->Format(1), "1 قەدەم/مىنۇت");
1610 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 قەدەم/مىنۇت");
1611 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1612 ASSERT_TRUE(numFmtHK != nullptr);
1613 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 步/分鐘");
1614 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1615 ASSERT_TRUE(numFmtTW != nullptr);
1616 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 步/分鐘");
1617 }
1618
1619 /**
1620 * @tc.name: NumberFormatFuncTest0033
1621 * @tc.desc: Test Intl NumberFormat.format
1622 * @tc.type: FUNC
1623 */
1624 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0033, TestSize.Level1)
1625 {
1626 string localeCN = "zh-CN";
1627 vector<string> localesCN{localeCN};
1628 string localeUS = "en-US";
1629 vector<string> localesUS{localeUS};
1630 string localeGB = "en-GB";
1631 vector<string> localesGB{localeGB};
1632 string localeBO = "bo";
1633 vector<string> localesBO{localeBO};
1634 string localeUG = "ug";
1635 vector<string> localesUG{localeUG};
1636 string localeHK = "zh-HK";
1637 vector<string> localesHK{localeHK};
1638 string localeTW = "zh-TW";
1639 vector<string> localesTW{localeTW};
1640 string style = "unit";
1641 string unit = "step-per-minute";
1642 string unitStyle = "narrow";
1643 map<string, string> options = { { "style", style},
1644 { "unit", unit },
1645 { "unitStyle", unitStyle } };
1646 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1647 ASSERT_TRUE(numFmtCN != nullptr);
1648 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 步/分钟");
1649 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1650 ASSERT_TRUE(numFmtUS != nullptr);
1651 EXPECT_EQ(numFmtUS->Format(1), "1 step/min");
1652 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 steps/min");
1653 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1654 ASSERT_TRUE(numFmtGB != nullptr);
1655 EXPECT_EQ(numFmtGB->Format(1), "1 step/min");
1656 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 steps/min");
1657 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1658 ASSERT_TRUE(numFmtBO != nullptr);
1659 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་གོམ་པ་ 1,234,567.89");
1660 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1661 ASSERT_TRUE(numFmtUG != nullptr);
1662 EXPECT_EQ(numFmtUG->Format(1), "1 قەدەم/مىنۇت");
1663 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 قەدەم/مىنۇت");
1664 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1665 ASSERT_TRUE(numFmtHK != nullptr);
1666 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 步/分鐘");
1667 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1668 ASSERT_TRUE(numFmtTW != nullptr);
1669 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 步/分鐘");
1670 }
1671
1672 /**
1673 * @tc.name: NumberFormatFuncTest0034
1674 * @tc.desc: Test Intl NumberFormat.format
1675 * @tc.type: FUNC
1676 */
1677 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0034, TestSize.Level1)
1678 {
1679 string localeCN = "zh-CN";
1680 vector<string> localesCN{localeCN};
1681 string localeUS = "en-US";
1682 vector<string> localesUS{localeUS};
1683 string localeGB = "en-GB";
1684 vector<string> localesGB{localeGB};
1685 string localeBO = "bo";
1686 vector<string> localesBO{localeBO};
1687 string localeUG = "ug";
1688 vector<string> localesUG{localeUG};
1689 string localeHK = "zh-HK";
1690 vector<string> localesHK{localeHK};
1691 string localeTW = "zh-TW";
1692 vector<string> localesTW{localeTW};
1693 string style = "unit";
1694 string unit = "stroke-per-minute";
1695 string unitStyle = "long";
1696 map<string, string> options = { { "style", style},
1697 { "unit", unit },
1698 { "unitStyle", unitStyle } };
1699 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1700 ASSERT_TRUE(numFmtCN != nullptr);
1701 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟");
1702 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1703 ASSERT_TRUE(numFmtUS != nullptr);
1704 EXPECT_EQ(numFmtUS->Format(1), "1 stroke/min");
1705 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 strokes/min");
1706 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1707 ASSERT_TRUE(numFmtGB != nullptr);
1708 EXPECT_EQ(numFmtGB->Format(1), "1 stroke/min");
1709 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 strokes/min");
1710 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1711 ASSERT_TRUE(numFmtBO != nullptr);
1712 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89");
1713 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1714 ASSERT_TRUE(numFmtUG != nullptr);
1715 EXPECT_EQ(numFmtUG->Format(1), "1 پالاق/مىنۇت");
1716 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 پالاق/مىنۇت");
1717 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1718 ASSERT_TRUE(numFmtHK != nullptr);
1719 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
1720 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1721 ASSERT_TRUE(numFmtTW != nullptr);
1722 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘");
1723 }
1724
1725 /**
1726 * @tc.name: NumberFormatFuncTest0035
1727 * @tc.desc: Test Intl NumberFormat.format
1728 * @tc.type: FUNC
1729 */
1730 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0035, TestSize.Level1)
1731 {
1732 string localeCN = "zh-CN";
1733 vector<string> localesCN{localeCN};
1734 string localeUS = "en-US";
1735 vector<string> localesUS{localeUS};
1736 string localeGB = "en-GB";
1737 vector<string> localesGB{localeGB};
1738 string localeBO = "bo";
1739 vector<string> localesBO{localeBO};
1740 string localeUG = "ug";
1741 vector<string> localesUG{localeUG};
1742 string localeHK = "zh-HK";
1743 vector<string> localesHK{localeHK};
1744 string localeTW = "zh-TW";
1745 vector<string> localesTW{localeTW};
1746 string style = "unit";
1747 string unit = "stroke-per-minute";
1748 string unitStyle = "short";
1749 map<string, string> options = { { "style", style},
1750 { "unit", unit },
1751 { "unitStyle", unitStyle } };
1752 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1753 ASSERT_TRUE(numFmtCN != nullptr);
1754 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟");
1755 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1756 ASSERT_TRUE(numFmtUS != nullptr);
1757 EXPECT_EQ(numFmtUS->Format(1), "1 stroke/min");
1758 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 strokes/min");
1759 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1760 ASSERT_TRUE(numFmtGB != nullptr);
1761 EXPECT_EQ(numFmtGB->Format(1), "1 stroke/min");
1762 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 strokes/min");
1763 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1764 ASSERT_TRUE(numFmtBO != nullptr);
1765 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89");
1766 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1767 ASSERT_TRUE(numFmtUG != nullptr);
1768 EXPECT_EQ(numFmtUG->Format(1), "1 پالاق/مىنۇت");
1769 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 پالاق/مىنۇت");
1770 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1771 ASSERT_TRUE(numFmtHK != nullptr);
1772 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
1773 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1774 ASSERT_TRUE(numFmtTW != nullptr);
1775 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘");
1776 }
1777
1778 /**
1779 * @tc.name: NumberFormatFuncTest0036
1780 * @tc.desc: Test Intl NumberFormat.format
1781 * @tc.type: FUNC
1782 */
1783 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0036, TestSize.Level1)
1784 {
1785 string localeCN = "zh-CN";
1786 vector<string> localesCN{localeCN};
1787 string localeUS = "en-US";
1788 vector<string> localesUS{localeUS};
1789 string localeGB = "en-GB";
1790 vector<string> localesGB{localeGB};
1791 string localeBO = "bo";
1792 vector<string> localesBO{localeBO};
1793 string localeUG = "ug";
1794 vector<string> localesUG{localeUG};
1795 string localeHK = "zh-HK";
1796 vector<string> localesHK{localeHK};
1797 string localeTW = "zh-TW";
1798 vector<string> localesTW{localeTW};
1799 string style = "unit";
1800 string unit = "stroke-per-minute";
1801 string unitStyle = "narrow";
1802 map<string, string> options = { { "style", style},
1803 { "unit", unit },
1804 { "unitStyle", unitStyle } };
1805 std::unique_ptr<NumberFormat> numFmtCN = std::make_unique<NumberFormat>(localesCN, options);
1806 ASSERT_TRUE(numFmtCN != nullptr);
1807 EXPECT_EQ(numFmtCN->Format(1234567.89), "1,234,567.89 次/分钟");
1808 std::unique_ptr<NumberFormat> numFmtUS = std::make_unique<NumberFormat>(localesUS, options);
1809 ASSERT_TRUE(numFmtUS != nullptr);
1810 EXPECT_EQ(numFmtUS->Format(1), "1 stroke/min");
1811 EXPECT_EQ(numFmtUS->Format(1234567.89), "1,234,567.89 strokes/min");
1812 std::unique_ptr<NumberFormat> numFmtGB = std::make_unique<NumberFormat>(localesGB, options);
1813 ASSERT_TRUE(numFmtGB != nullptr);
1814 EXPECT_EQ(numFmtGB->Format(1), "1 stroke/min");
1815 EXPECT_EQ(numFmtGB->Format(1234567.89), "1,234,567.89 strokes/min");
1816 std::unique_ptr<NumberFormat> numFmtBO = std::make_unique<NumberFormat>(localesBO, options);
1817 ASSERT_TRUE(numFmtBO != nullptr);
1818 EXPECT_EQ(numFmtBO->Format(1234567.89), "སྐར་མ་རེར་ཐེངས་ 1,234,567.89");
1819 std::unique_ptr<NumberFormat> numFmtUG = std::make_unique<NumberFormat>(localesUG, options);
1820 ASSERT_TRUE(numFmtUG != nullptr);
1821 EXPECT_EQ(numFmtUG->Format(1), "1 پالاق/مىنۇت");
1822 EXPECT_EQ(numFmtUG->Format(1234567.89), "1,234,567.89 پالاق/مىنۇت");
1823 std::unique_ptr<NumberFormat> numFmtHK = std::make_unique<NumberFormat>(localesHK, options);
1824 ASSERT_TRUE(numFmtHK != nullptr);
1825 EXPECT_EQ(numFmtHK->Format(1234567.89), "1,234,567.89 下/分鐘");
1826 std::unique_ptr<NumberFormat> numFmtTW = std::make_unique<NumberFormat>(localesTW, options);
1827 ASSERT_TRUE(numFmtTW != nullptr);
1828 EXPECT_EQ(numFmtTW->Format(1234567.89), "1,234,567.89 次/分鐘");
1829 }
1830
1831 /**
1832 * @tc.name: NumberFormatFuncTest0037
1833 * @tc.desc: Test Intl NumberFormat.formatRange
1834 * @tc.type: FUNC
1835 */
1836 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0037, TestSize.Level1)
1837 {
1838 string locale = "en-US";
1839 vector<string> locales{locale};
1840 string unit = "meter";
1841 string style = "unit";
1842 map<string, string> options = { { "style", style},
1843 { "unit", unit } };
1844 std::unique_ptr<NumberFormat> rangeFormatter = std::make_unique<NumberFormat>(locales, options);
1845 ASSERT_TRUE(rangeFormatter != nullptr);
1846 if (NumberFormatTest::deviceType == "wearable" || NumberFormatTest::deviceType == "liteWearable" ||
1847 NumberFormatTest::deviceType == "watch") {
1848 EXPECT_EQ(rangeFormatter->FormatRange(1, 5), "1–5m");
1849 EXPECT_EQ(rangeFormatter->FormatRange(4.9999999, 5.0000001), "~5m");
1850 EXPECT_EQ(rangeFormatter->FormatRange(5, 5), "~5m");
1851 EXPECT_EQ(rangeFormatter->FormatRange(0, 3), "0–3m");
1852 EXPECT_EQ(rangeFormatter->FormatRange(0, 0), "~0m");
1853 EXPECT_EQ(rangeFormatter->FormatRange(3, 3000), "3–3,000m");
1854 EXPECT_EQ(rangeFormatter->FormatRange(3000, 5000), "3,000–5,000m");
1855 EXPECT_EQ(rangeFormatter->FormatRange(4999, 5001), "4,999–5,001m");
1856 EXPECT_EQ(rangeFormatter->FormatRange(5000, 5000), "~5,000m");
1857 EXPECT_EQ(rangeFormatter->FormatRange(5e3, 5e6), "5,000–5,000,000m");
1858 } else if (NumberFormatTest::deviceType == "tablet" || NumberFormatTest::deviceType == "2in1" ||
1859 NumberFormatTest::deviceType == "tv" || NumberFormatTest::deviceType == "pc") {
1860 EXPECT_EQ(rangeFormatter->FormatRange(1, 5), "1–5 meters");
1861 EXPECT_EQ(rangeFormatter->FormatRange(4.9999999, 5.0000001), "~5 meters");
1862 EXPECT_EQ(rangeFormatter->FormatRange(5, 5), "~5 meters");
1863 EXPECT_EQ(rangeFormatter->FormatRange(0, 3), "0–3 meters");
1864 EXPECT_EQ(rangeFormatter->FormatRange(0, 0), "~0 meters");
1865 EXPECT_EQ(rangeFormatter->FormatRange(3, 3000), "3–3,000 meters");
1866 EXPECT_EQ(rangeFormatter->FormatRange(3000, 5000), "3,000–5,000 meters");
1867 EXPECT_EQ(rangeFormatter->FormatRange(4999, 5001), "4,999–5,001 meters");
1868 EXPECT_EQ(rangeFormatter->FormatRange(5000, 5000), "~5,000 meters");
1869 EXPECT_EQ(rangeFormatter->FormatRange(5e3, 5e6), "5,000–5,000,000 meters");
1870 } else {
1871 EXPECT_EQ(rangeFormatter->FormatRange(1, 5), "1–5 m");
1872 EXPECT_EQ(rangeFormatter->FormatRange(4.9999999, 5.0000001), "~5 m");
1873 EXPECT_EQ(rangeFormatter->FormatRange(5, 5), "~5 m");
1874 EXPECT_EQ(rangeFormatter->FormatRange(0, 3), "0–3 m");
1875 EXPECT_EQ(rangeFormatter->FormatRange(0, 0), "~0 m");
1876 EXPECT_EQ(rangeFormatter->FormatRange(3, 3000), "3–3,000 m");
1877 EXPECT_EQ(rangeFormatter->FormatRange(3000, 5000), "3,000–5,000 m");
1878 EXPECT_EQ(rangeFormatter->FormatRange(4999, 5001), "4,999–5,001 m");
1879 EXPECT_EQ(rangeFormatter->FormatRange(5000, 5000), "~5,000 m");
1880 EXPECT_EQ(rangeFormatter->FormatRange(5e3, 5e6), "5,000–5,000,000 m");
1881 }
1882 }
1883
1884 /**
1885 * @tc.name: NumberFormatFuncTest0038
1886 * @tc.desc: Test Intl NumberFormat.formatRange
1887 * @tc.type: FUNC
1888 */
1889 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0038, TestSize.Level1)
1890 {
1891 string locale = "ja";
1892 vector<string> locales{locale};
1893 map<string, string> options = {};
1894 std::unique_ptr<NumberFormat> rangeFormatter = std::make_unique<NumberFormat>(locales, options);
1895 ASSERT_TRUE(rangeFormatter != nullptr);
1896 EXPECT_EQ(rangeFormatter->FormatRange(1, 5), "1~5");
1897 EXPECT_EQ(rangeFormatter->FormatRange(4.9999999, 5.0000001), "約5");
1898 EXPECT_EQ(rangeFormatter->FormatRange(5, 5), "約5");
1899 EXPECT_EQ(rangeFormatter->FormatRange(0, 3), "0~3");
1900 EXPECT_EQ(rangeFormatter->FormatRange(0, 0), "約0");
1901 EXPECT_EQ(rangeFormatter->FormatRange(3, 3000), "3~3,000");
1902 EXPECT_EQ(rangeFormatter->FormatRange(3000, 5000), "3,000~5,000");
1903 EXPECT_EQ(rangeFormatter->FormatRange(4999, 5001), "4,999~5,001");
1904 EXPECT_EQ(rangeFormatter->FormatRange(5000, 5000), "約5,000");
1905 EXPECT_EQ(rangeFormatter->FormatRange(5e3, 5e6), "5,000~5,000,000");
1906 }
1907
1908 /**
1909 * @tc.name: NumberFormatFuncTest0039
1910 * @tc.desc: Test I18n StyledNumberFormat.format
1911 * @tc.type: FUNC
1912 */
1913 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0039, TestSize.Level1)
1914 {
1915 string locale = "en-IN";
1916 string expects = "+1,23,456.79 euros";
1917 vector<string> locales{locale};
1918 string useGrouping = "true";
1919 string minimumIntegerDigits = "7";
1920 string maximumFractionDigits = "2";
1921 string style = "currency";
1922 string currency = "978";
1923 map<string, string> options = { { "useGrouping", useGrouping },
1924 { "style", style },
1925 { "currency", currency },
1926 { "currencyDisplay", "name" },
1927 { "currencySign", "accounting" },
1928 { "signDisplay", "always" } };
1929 std::shared_ptr<NumberFormat> numFmt = std::make_shared<NumberFormat>(locales, options);
1930 ASSERT_TRUE(numFmt != nullptr);
1931 StyledNumberFormat styledNumFmt(true, numFmt, nullptr);
1932 string out = styledNumFmt.Format(123456.789);
1933 EXPECT_EQ(out, expects);
1934 }
1935
1936 /**
1937 * @tc.name: NumberFormatFuncTest0040
1938 * @tc.desc: Test I18n StyledNumberFormat.ParseToParts
1939 * @tc.type: FUNC
1940 */
1941 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0040, TestSize.Level1)
1942 {
1943 string locale = "en-IN";
1944 vector<string> locales{locale};
1945 string useGrouping = "true";
1946 string minimumIntegerDigits = "7";
1947 string maximumFractionDigits = "2";
1948 string style = "currency";
1949 string currency = "978";
1950 map<string, string> options = { { "useGrouping", useGrouping },
1951 { "style", style },
1952 { "currency", currency },
1953 { "currencyDisplay", "name" },
1954 { "currencySign", "accounting" },
1955 { "signDisplay", "always" } };
1956 std::shared_ptr<NumberFormat> numFmt = std::make_shared<NumberFormat>(locales, options);
1957 ASSERT_TRUE(numFmt != nullptr);
1958 StyledNumberFormat styledNumFmt(true, numFmt, nullptr);
1959 std::vector<StyledNumberFormat::NumberPart> out = styledNumFmt.ParseToParts(123456.789);
1960 EXPECT_EQ(out.size(), 5);
1961 EXPECT_EQ(out[0].part_name, "integer");
1962 EXPECT_EQ(out[1].part_name, "integer");
1963 EXPECT_EQ(out[2].part_name, "decimal");
1964 EXPECT_EQ(out[3].part_name, "fraction");
1965 EXPECT_EQ(out[4].part_name, "unit");
1966 }
1967
1968 /**
1969 * @tc.name: NumberFormatFuncTest0041
1970 * @tc.desc: Test I18n StyledNumberFormat.format
1971 * @tc.type: FUNC
1972 */
1973 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0041, TestSize.Level1)
1974 {
1975 I18nErrorCode err = I18nErrorCode::SUCCESS;
1976 std::string skeleton = "percent";
1977 std::shared_ptr<LocaleInfo> localeInfo = std::make_shared<LocaleInfo>("zh-Hans-CN");
1978 ASSERT_TRUE(localeInfo != nullptr);
1979 std::shared_ptr<SimpleNumberFormat> formatter = std::make_shared<SimpleNumberFormat>(skeleton, localeInfo, err);
1980 EXPECT_EQ(err, I18nErrorCode::SUCCESS);
1981 ASSERT_TRUE(formatter != nullptr);
1982 StyledNumberFormat styledNumFmt(false, nullptr, formatter);
1983 std::string result = styledNumFmt.Format(10);
1984 EXPECT_EQ(result, "10%");
1985 }
1986
1987 /**
1988 * @tc.name: NumberFormatFuncTest0042
1989 * @tc.desc: Test I18n StyledNumberFormat.ParseToParts and StyledNumberFormat.Format
1990 * @tc.type: FUNC
1991 */
1992 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0042, TestSize.Level1)
1993 {
1994 string locale = "en";
1995 vector<string> locales{locale};
1996 map<string, string> options = { { "style", "unit" },
1997 { "unit", "minute" },
1998 { "unitUsage", "elapsed-time-second" } };
1999 std::shared_ptr<NumberFormat> numFmt = std::make_shared<NumberFormat>(locales, options);
2000 ASSERT_TRUE(numFmt != nullptr);
2001 StyledNumberFormat styledNumFmt(true, numFmt, nullptr);
2002 if (NumberFormatTest::deviceType == "wearable" || NumberFormatTest::deviceType == "liteWearable" ||
2003 NumberFormatTest::deviceType == "watch") {
2004 EXPECT_EQ(styledNumFmt.Format(1234.5678), "20 hr. ago");
2005 } else if (NumberFormatTest::deviceType == "tablet" || NumberFormatTest::deviceType == "2in1" ||
2006 NumberFormatTest::deviceType == "tv" || NumberFormatTest::deviceType == "pc") {
2007 EXPECT_EQ(styledNumFmt.Format(1234.5678), "20 hours ago");
2008 } else {
2009 EXPECT_EQ(styledNumFmt.Format(1234.5678), "20 hours ago");
2010 }
2011 std::vector<StyledNumberFormat::NumberPart> out = styledNumFmt.ParseToParts(123456.789);
2012 EXPECT_EQ(out.size(), 2);
2013 EXPECT_EQ(out[0].part_name, "integer");
2014 EXPECT_EQ(out[1].part_name, "unit");
2015 }
2016
2017 /**
2018 * @tc.name: NumberFormatFuncTest0043
2019 * @tc.desc: Test Intl NumberFormat.format
2020 * @tc.type: FUNC
2021 */
2022 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0043, TestSize.Level1)
2023 {
2024 string locale = "en";
2025 vector<string> locales{locale};
2026 map<string, string> options = {
2027 {"maximumFractionDigits", "3"},
2028 };
2029 std::unique_ptr<NumberFormat> formatter = std::make_unique<NumberFormat>(locales, options);
2030 ASSERT_TRUE(formatter != nullptr);
2031 EXPECT_EQ(formatter->Format(1.23456), "1.235");
2032 options = {
2033 {"maximumSignificantDigits", "3"},
2034 };
2035 std::unique_ptr<NumberFormat> formatter2 = std::make_unique<NumberFormat>(locales, options);
2036 EXPECT_EQ(formatter2->Format(1.23456), "1.23");
2037 options = {
2038 {"maximumFractionDigits", "3"},
2039 {"maximumSignificantDigits", "3"},
2040 };
2041 std::unique_ptr<NumberFormat> formatter3 = std::make_unique<NumberFormat>(locales, options);
2042 EXPECT_EQ(formatter3->Format(1.23456), "1.23");
2043 options = {
2044 {"roundingPriority", "lessPrecision"},
2045 {"maximumFractionDigits", "3"},
2046 {"maximumSignificantDigits", "3"},
2047 };
2048 std::unique_ptr<NumberFormat> formatter4 = std::make_unique<NumberFormat>(locales, options);
2049 EXPECT_EQ(formatter4->Format(1.23456), "1.23");
2050 options = {
2051 {"roundingPriority", "morePrecision"},
2052 {"maximumFractionDigits", "3"},
2053 {"maximumSignificantDigits", "3"},
2054 };
2055 std::unique_ptr<NumberFormat> formatter5 = std::make_unique<NumberFormat>(locales, options);
2056 EXPECT_EQ(formatter5->Format(1.23456), "1.235");
2057 options = {
2058 {"roundingPriority", "lessPrecision"},
2059 {"minimumFractionDigits", "2"},
2060 {"minimumSignificantDigits", "2"},
2061 };
2062 std::unique_ptr<NumberFormat> formatter6 = std::make_unique<NumberFormat>(locales, options);
2063 EXPECT_EQ(formatter6->Format(1), "1.00");
2064 options = {
2065 {"roundingPriority", "morePrecision"},
2066 {"minimumFractionDigits", "2"},
2067 {"minimumSignificantDigits", "2"},
2068 };
2069 std::unique_ptr<NumberFormat> formatter7 = std::make_unique<NumberFormat>(locales, options);
2070 EXPECT_EQ(formatter7->Format(1), "1.0");
2071 }
2072
2073 /**
2074 * @tc.name: NumberFormatFuncTest0044
2075 * @tc.desc: Test Intl NumberFormat.format
2076 * @tc.type: FUNC
2077 */
2078 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0044, TestSize.Level1)
2079 {
2080 string locale = "en";
2081 vector<string> locales{locale};
2082 map<string, string> options = {
2083 {"roundingMode", "ceil"},
2084 {"maximumSignificantDigits", "2"},
2085 };
2086 std::unique_ptr<NumberFormat> formatter = std::make_unique<NumberFormat>(locales, options);
2087 ASSERT_TRUE(formatter != nullptr);
2088 EXPECT_EQ(formatter->Format(2.23), "2.3");
2089 EXPECT_EQ(formatter->Format(2.25), "2.3");
2090 EXPECT_EQ(formatter->Format(2.28), "2.3");
2091 EXPECT_EQ(formatter->Format(-2.23), "-2.2");
2092 EXPECT_EQ(formatter->Format(-2.25), "-2.2");
2093 EXPECT_EQ(formatter->Format(-2.28), "-2.2");
2094
2095 options = {
2096 {"roundingMode", "halfCeil"},
2097 {"maximumSignificantDigits", "2"},
2098 };
2099 std::unique_ptr<NumberFormat> numFmt = std::make_unique<NumberFormat>(locales, options);
2100 ASSERT_TRUE(numFmt != nullptr);
2101 EXPECT_EQ(numFmt->Format(2.23), "2.2");
2102 EXPECT_EQ(numFmt->Format(2.25), "2.3");
2103 EXPECT_EQ(numFmt->Format(2.28), "2.3");
2104 EXPECT_EQ(numFmt->Format(-2.23), "-2.2");
2105 EXPECT_EQ(numFmt->Format(-2.25), "-2.2");
2106 EXPECT_EQ(numFmt->Format(-2.28), "-2.3");
2107 }
2108
2109 /**
2110 * @tc.name: NumberFormatFuncTest0045
2111 * @tc.desc: Test Intl NumberFormat.format
2112 * @tc.type: FUNC
2113 */
2114 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0045, TestSize.Level1)
2115 {
2116 string locale = "en";
2117 vector<string> locales{locale};
2118 map<string, string> options = {
2119 {"roundingMode", "floor"},
2120 {"maximumSignificantDigits", "2"},
2121 };
2122 std::unique_ptr<NumberFormat> formatter = std::make_unique<NumberFormat>(locales, options);
2123 ASSERT_TRUE(formatter != nullptr);
2124 EXPECT_EQ(formatter->Format(2.23), "2.2");
2125 EXPECT_EQ(formatter->Format(2.25), "2.2");
2126 EXPECT_EQ(formatter->Format(2.28), "2.2");
2127 EXPECT_EQ(formatter->Format(-2.23), "-2.3");
2128 EXPECT_EQ(formatter->Format(-2.25), "-2.3");
2129 EXPECT_EQ(formatter->Format(-2.28), "-2.3");
2130
2131 options = {
2132 {"roundingMode", "halfFloor"},
2133 {"maximumSignificantDigits", "2"},
2134 };
2135 std::unique_ptr<NumberFormat> formatter2 = std::make_unique<NumberFormat>(locales, options);
2136 ASSERT_TRUE(formatter2 != nullptr);
2137 EXPECT_EQ(formatter2->Format(2.23), "2.2");
2138 EXPECT_EQ(formatter2->Format(2.25), "2.2");
2139 EXPECT_EQ(formatter2->Format(2.28), "2.3");
2140 EXPECT_EQ(formatter2->Format(-2.23), "-2.2");
2141 EXPECT_EQ(formatter2->Format(-2.25), "-2.3");
2142 EXPECT_EQ(formatter2->Format(-2.28), "-2.3");
2143 }
2144
2145 /**
2146 * @tc.name: NumberFormatFuncTest0046
2147 * @tc.desc: Test Intl NumberFormat.format
2148 * @tc.type: FUNC
2149 */
2150 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0046, TestSize.Level1)
2151 {
2152 string locale = "en";
2153 vector<string> locales{locale};
2154 map<string, string> options = {
2155 {"roundingMode", "expand"},
2156 {"maximumSignificantDigits", "2"},
2157 };
2158 std::unique_ptr<NumberFormat> formatter = std::make_unique<NumberFormat>(locales, options);
2159 ASSERT_TRUE(formatter != nullptr);
2160 EXPECT_EQ(formatter->Format(2.23), "2.3");
2161 EXPECT_EQ(formatter->Format(2.25), "2.3");
2162 EXPECT_EQ(formatter->Format(2.28), "2.3");
2163 EXPECT_EQ(formatter->Format(-2.23), "-2.3");
2164 EXPECT_EQ(formatter->Format(-2.25), "-2.3");
2165 EXPECT_EQ(formatter->Format(-2.28), "-2.3");
2166
2167 options = {
2168 {"roundingMode", "halfExpand"},
2169 {"maximumSignificantDigits", "2"},
2170 };
2171 std::unique_ptr<NumberFormat> numberFormat = std::make_unique<NumberFormat>(locales, options);
2172 ASSERT_TRUE(numberFormat != nullptr);
2173 EXPECT_EQ(numberFormat->Format(2.23), "2.2");
2174 EXPECT_EQ(numberFormat->Format(2.25), "2.3");
2175 EXPECT_EQ(numberFormat->Format(2.28), "2.3");
2176 EXPECT_EQ(numberFormat->Format(-2.23), "-2.2");
2177 EXPECT_EQ(numberFormat->Format(-2.25), "-2.3");
2178 EXPECT_EQ(numberFormat->Format(-2.28), "-2.3");
2179 }
2180
2181 /**
2182 * @tc.name: NumberFormatFuncTest0047
2183 * @tc.desc: Test Intl NumberFormat.format
2184 * @tc.type: FUNC
2185 */
2186 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0047, TestSize.Level1)
2187 {
2188 string locale = "en";
2189 vector<string> locales{locale};
2190 map<string, string> options = {
2191 {"roundingMode", "trunc"},
2192 {"maximumSignificantDigits", "2"},
2193 };
2194 std::unique_ptr<NumberFormat> formatter = std::make_unique<NumberFormat>(locales, options);
2195 ASSERT_TRUE(formatter != nullptr);
2196 EXPECT_EQ(formatter->Format(2.23), "2.2");
2197 EXPECT_EQ(formatter->Format(2.25), "2.2");
2198 EXPECT_EQ(formatter->Format(2.28), "2.2");
2199 EXPECT_EQ(formatter->Format(-2.23), "-2.2");
2200 EXPECT_EQ(formatter->Format(-2.25), "-2.2");
2201 EXPECT_EQ(formatter->Format(-2.28), "-2.2");
2202
2203 options = {
2204 {"roundingMode", "halfTrunc"},
2205 {"maximumSignificantDigits", "2"},
2206 };
2207 std::unique_ptr<NumberFormat> numberFormat = std::make_unique<NumberFormat>(locales, options);
2208 ASSERT_TRUE(numberFormat != nullptr);
2209 EXPECT_EQ(numberFormat->Format(2.23), "2.2");
2210 EXPECT_EQ(numberFormat->Format(2.25), "2.2");
2211 EXPECT_EQ(numberFormat->Format(2.28), "2.3");
2212 EXPECT_EQ(numberFormat->Format(-2.23), "-2.2");
2213 EXPECT_EQ(numberFormat->Format(-2.25), "-2.2");
2214 EXPECT_EQ(numberFormat->Format(-2.28), "-2.3");
2215 }
2216
2217 /**
2218 * @tc.name: NumberFormatFuncTest0048
2219 * @tc.desc: Test Intl NumberFormat.format
2220 * @tc.type: FUNC
2221 */
2222 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0048, TestSize.Level1)
2223 {
2224 string locale = "en";
2225 vector<string> locales{locale};
2226 map<string, string> options = {
2227 {"roundingMode", "halfEven"},
2228 {"maximumSignificantDigits", "2"},
2229 };
2230 std::unique_ptr<NumberFormat> formatter = std::make_unique<NumberFormat>(locales, options);
2231 ASSERT_TRUE(formatter != nullptr);
2232 EXPECT_EQ(formatter->Format(2.23), "2.2");
2233 EXPECT_EQ(formatter->Format(2.25), "2.2");
2234 EXPECT_EQ(formatter->Format(2.28), "2.3");
2235 EXPECT_EQ(formatter->Format(-2.23), "-2.2");
2236 EXPECT_EQ(formatter->Format(-2.25), "-2.2");
2237 EXPECT_EQ(formatter->Format(-2.28), "-2.3");
2238 }
2239
2240 /**
2241 * @tc.name: NumberFormatFuncTest0049
2242 * @tc.desc: Test Intl NumberFormat.format
2243 * @tc.type: FUNC
2244 */
2245 HWTEST_F(NumberFormatTest, NumberFormatFuncTest0049, TestSize.Level1)
2246 {
2247 string locale = "en-US";
2248 vector<string> locales{locale};
2249 map<string, string> options = {
2250 {"style", "currency"},
2251 {"currency", "USD"},
2252 {"roundingIncrement", "5"},
2253 {"maximumFractionDigits", "2"},
2254 };
2255 std::unique_ptr<NumberFormat> formatter = std::make_unique<NumberFormat>(locales, options);
2256 ASSERT_TRUE(formatter != nullptr);
2257 EXPECT_EQ(formatter->Format(11.29), "$11.30");
2258 EXPECT_EQ(formatter->Format(11.25), "$11.25");
2259 EXPECT_EQ(formatter->Format(11.22), "$11.20");
2260
2261 options = {
2262 {"style", "currency"},
2263 {"currency", "USD"},
2264 {"roundingIncrement", "5"},
2265 {"maximumFractionDigits", "2"},
2266 {"roundingMode", "halfCeil"},
2267 };
2268 std::unique_ptr<NumberFormat> numberFmt = std::make_unique<NumberFormat>(locales, options);
2269 ASSERT_TRUE(numberFmt != nullptr);
2270 EXPECT_EQ(numberFmt->Format(11.21), "$11.20");
2271 EXPECT_EQ(numberFmt->Format(11.22), "$11.20");
2272 EXPECT_EQ(numberFmt->Format(11.224), "$11.20");
2273 EXPECT_EQ(numberFmt->Format(11.225), "$11.25");
2274 EXPECT_EQ(numberFmt->Format(11.23), "$11.25");
2275 }
2276 } // namespace I18n
2277 } // namespace Global
2278 } // namespace OHOS