Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/CompactNumberFormat/TestParseBigDecimal.java
41153 views
1
/*
2
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
/*
24
* @test
25
* @bug 8177552
26
* @summary Checks CNF.parse() when parseBigDecimal is set to true
27
* @modules jdk.localedata
28
* @run testng/othervm TestParseBigDecimal
29
*/
30
31
import org.testng.annotations.BeforeTest;
32
import org.testng.annotations.DataProvider;
33
import org.testng.annotations.Test;
34
35
import java.math.BigDecimal;
36
import java.text.CompactNumberFormat;
37
import java.text.NumberFormat;
38
import java.text.ParseException;
39
import java.util.Locale;
40
41
public class TestParseBigDecimal {
42
43
private static final CompactNumberFormat FORMAT_DZ_LONG = (CompactNumberFormat) NumberFormat
44
.getCompactNumberInstance(new Locale("dz"), NumberFormat.Style.LONG);
45
46
private static final CompactNumberFormat FORMAT_EN_US_SHORT = (CompactNumberFormat) NumberFormat
47
.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT);
48
49
private static final CompactNumberFormat FORMAT_EN_LONG = (CompactNumberFormat) NumberFormat
50
.getCompactNumberInstance(new Locale("en"), NumberFormat.Style.LONG);
51
52
private static final CompactNumberFormat FORMAT_HI_IN_LONG = (CompactNumberFormat) NumberFormat
53
.getCompactNumberInstance(new Locale("hi", "IN"), NumberFormat.Style.LONG);
54
55
private static final CompactNumberFormat FORMAT_JA_JP_SHORT = (CompactNumberFormat) NumberFormat
56
.getCompactNumberInstance(Locale.JAPAN, NumberFormat.Style.SHORT);
57
58
private static final CompactNumberFormat FORMAT_IT_SHORT = (CompactNumberFormat) NumberFormat
59
.getCompactNumberInstance(new Locale("it"), NumberFormat.Style.SHORT);
60
61
private static final CompactNumberFormat FORMAT_SW_LONG = (CompactNumberFormat) NumberFormat
62
.getCompactNumberInstance(new Locale("sw"), NumberFormat.Style.LONG);
63
64
private static final CompactNumberFormat FORMAT_SE_SHORT = (CompactNumberFormat) NumberFormat
65
.getCompactNumberInstance(new Locale("se"), NumberFormat.Style.SHORT);
66
67
@BeforeTest
68
public void mutateInstances() {
69
FORMAT_DZ_LONG.setParseBigDecimal(true);
70
FORMAT_EN_US_SHORT.setParseBigDecimal(true);
71
FORMAT_EN_LONG.setParseBigDecimal(true);
72
FORMAT_HI_IN_LONG.setParseBigDecimal(true);
73
FORMAT_JA_JP_SHORT.setParseBigDecimal(true);
74
FORMAT_IT_SHORT.setParseBigDecimal(true);
75
FORMAT_SW_LONG.setParseBigDecimal(true);
76
FORMAT_SE_SHORT.setParseBigDecimal(true);
77
}
78
79
@DataProvider(name = "parse")
80
Object[][] compactParseData() {
81
return new Object[][]{
82
// compact number format instance, string to parse, parsed number
83
{FORMAT_DZ_LONG, "\u0F66\u0F9F\u0F7C\u0F44\u0F0B\u0F55\u0FB2"
84
+ "\u0F42 \u0F21", new BigDecimal("1000")},
85
{FORMAT_DZ_LONG, "-\u0F66\u0F9F\u0F7C\u0F44\u0F0B\u0F55\u0FB2"
86
+ "\u0F42 \u0F23", new BigDecimal("-3000")},
87
{FORMAT_DZ_LONG, "\u0F51\u0F74\u0F44\u0F0B\u0F55\u0FB1\u0F74\u0F62"
88
+ "\u0F0B\u0F66\u0F0B\u0F61\u0F0B \u0F21"
89
+ "\u0F22\u0F23\u0F24\u0F25\u0F27", new BigDecimal("12345700000000000000")},
90
{FORMAT_DZ_LONG, "-\u0F51\u0F74\u0F44\u0F0B\u0F55\u0FB1\u0F74\u0F62"
91
+ "\u0F0B\u0F66\u0F0B\u0F61\u0F0B \u0F21"
92
+ "\u0F22\u0F23\u0F24\u0F25\u0F27", new BigDecimal("-12345700000000000000")},
93
{FORMAT_EN_US_SHORT, "-0.0", new BigDecimal("-0.0")},
94
{FORMAT_EN_US_SHORT, "0", new BigDecimal("0")},
95
{FORMAT_EN_US_SHORT, "499", new BigDecimal("499")},
96
{FORMAT_EN_US_SHORT, "-499", new BigDecimal("-499")},
97
{FORMAT_EN_US_SHORT, "499.89", new BigDecimal("499.89")},
98
{FORMAT_EN_US_SHORT, "-499.89", new BigDecimal("-499.89")},
99
{FORMAT_EN_US_SHORT, "1K", new BigDecimal("1000")},
100
{FORMAT_EN_US_SHORT, "-1K", new BigDecimal("-1000")},
101
{FORMAT_EN_US_SHORT, "3K", new BigDecimal("3000")},
102
{FORMAT_EN_US_SHORT, "-3K", new BigDecimal("-3000")},
103
{FORMAT_EN_US_SHORT, "17K", new BigDecimal("17000")},
104
{FORMAT_EN_US_SHORT, "-17K", new BigDecimal("-17000")},
105
{FORMAT_EN_US_SHORT, "12345678901234567890",
106
new BigDecimal("12345678901234567890")},
107
{FORMAT_EN_US_SHORT, "12345679T", new BigDecimal("12345679000000000000")},
108
{FORMAT_EN_US_SHORT, "-12345679T", new BigDecimal("-12345679000000000000")},
109
{FORMAT_EN_US_SHORT, "599.01K", new BigDecimal("599010.00")},
110
{FORMAT_EN_US_SHORT, "-599.01K", new BigDecimal("-599010.00")},
111
{FORMAT_EN_US_SHORT, "599444444.90T", new BigDecimal("599444444900000000000.00")},
112
{FORMAT_EN_US_SHORT, "-599444444.90T", new BigDecimal("-599444444900000000000.00")},
113
{FORMAT_EN_US_SHORT, "123456789012345.5678K",
114
new BigDecimal("123456789012345567.8000")},
115
{FORMAT_EN_US_SHORT, "17.000K", new BigDecimal("17000.000")},
116
{FORMAT_EN_US_SHORT, "123.56678K", new BigDecimal("123566.78000")},
117
{FORMAT_EN_US_SHORT, "-123.56678K", new BigDecimal("-123566.78000")},
118
{FORMAT_EN_LONG, "999", new BigDecimal("999")},
119
{FORMAT_EN_LONG, "1 thousand", new BigDecimal("1000")},
120
{FORMAT_EN_LONG, "3 thousand", new BigDecimal("3000")},
121
{FORMAT_EN_LONG, "12345679 trillion", new BigDecimal("12345679000000000000")},
122
{FORMAT_HI_IN_LONG, "999", new BigDecimal("999")},
123
{FORMAT_HI_IN_LONG, "-999", new BigDecimal("-999")},
124
{FORMAT_HI_IN_LONG, "1 \u0939\u091C\u093C\u093E\u0930", new BigDecimal("1000")},
125
{FORMAT_HI_IN_LONG, "-1 \u0939\u091C\u093C\u093E\u0930", new BigDecimal("-1000")},
126
{FORMAT_HI_IN_LONG, "3 \u0939\u091C\u093C\u093E\u0930", new BigDecimal("3000")},
127
{FORMAT_HI_IN_LONG, "12345679 \u0916\u0930\u092C", new BigDecimal("1234567900000000000")},
128
{FORMAT_HI_IN_LONG, "-12345679 \u0916\u0930\u092C", new BigDecimal("-1234567900000000000")},
129
{FORMAT_JA_JP_SHORT, "-99", new BigDecimal("-99")},
130
{FORMAT_JA_JP_SHORT, "1\u4E07", new BigDecimal("10000")},
131
{FORMAT_JA_JP_SHORT, "30\u4E07", new BigDecimal("300000")},
132
{FORMAT_JA_JP_SHORT, "-30\u4E07", new BigDecimal("-300000")},
133
{FORMAT_JA_JP_SHORT, "12345679\u5146", new BigDecimal("12345679000000000000")},
134
{FORMAT_JA_JP_SHORT, "-12345679\u5146", new BigDecimal("-12345679000000000000")},
135
{FORMAT_IT_SHORT, "-99", new BigDecimal("-99")},
136
{FORMAT_IT_SHORT, "1\u00a0Mln", new BigDecimal("1000000")},
137
{FORMAT_IT_SHORT, "30\u00a0Mln", new BigDecimal("30000000")},
138
{FORMAT_IT_SHORT, "-30\u00a0Mln", new BigDecimal("-30000000")},
139
{FORMAT_IT_SHORT, "12345679\u00a0Bln", new BigDecimal("12345679000000000000")},
140
{FORMAT_IT_SHORT, "-12345679\u00a0Bln", new BigDecimal("-12345679000000000000")},
141
{FORMAT_SW_LONG, "-0.0", new BigDecimal("-0.0")},
142
{FORMAT_SW_LONG, "499", new BigDecimal("499")},
143
{FORMAT_SW_LONG, "elfu 1", new BigDecimal("1000")},
144
{FORMAT_SW_LONG, "elfu 3", new BigDecimal("3000")},
145
{FORMAT_SW_LONG, "elfu 17", new BigDecimal("17000")},
146
{FORMAT_SW_LONG, "elfu -3", new BigDecimal("-3000")},
147
{FORMAT_SW_LONG, "-499", new BigDecimal("-499")},
148
{FORMAT_SW_LONG, "elfu 1", new BigDecimal("1000")},
149
{FORMAT_SW_LONG, "elfu 3", new BigDecimal("3000")},
150
{FORMAT_SW_LONG, "elfu -3", new BigDecimal("-3000")},
151
{FORMAT_SW_LONG, "elfu 17", new BigDecimal("17000")},
152
{FORMAT_SW_LONG, "trilioni 12345679", new BigDecimal("12345679000000000000")},
153
{FORMAT_SW_LONG, "trilioni -12345679", new BigDecimal("-12345679000000000000")},
154
{FORMAT_SW_LONG, "elfu 599.01", new BigDecimal("599010.00")},
155
{FORMAT_SW_LONG, "elfu -599.01", new BigDecimal("-599010.00")},
156
{FORMAT_SE_SHORT, "999", new BigDecimal("999")},
157
{FORMAT_SE_SHORT, "8\u00a0mn", new BigDecimal("8000000")},
158
{FORMAT_SE_SHORT, "8\u00a0dt", new BigDecimal("8000")},
159
{FORMAT_SE_SHORT, "12345679\u00a0bn", new BigDecimal("12345679000000000000")},
160
{FORMAT_SE_SHORT, "12345679,89\u00a0bn", new BigDecimal("12345679890000000000.00")},
161
{FORMAT_SE_SHORT, "\u2212999", new BigDecimal("-999")},
162
{FORMAT_SE_SHORT, "\u22128\u00a0mn", new BigDecimal("-8000000")},
163
{FORMAT_SE_SHORT, "\u22128\u00a0dt", new BigDecimal("-8000")},
164
{FORMAT_SE_SHORT, "\u221212345679\u00a0bn", new BigDecimal("-12345679000000000000")},
165
{FORMAT_SE_SHORT, "\u221212345679,89\u00a0bn", new BigDecimal("-12345679890000000000.00")},};
166
}
167
168
@Test(dataProvider = "parse")
169
public void testParse(NumberFormat cnf, String parseString,
170
Number expected) throws ParseException {
171
CompactFormatAndParseHelper.testParse(cnf, parseString, expected, null, BigDecimal.class);
172
}
173
}
174
175