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