Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
ca1f906e
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ca1f906e
编写于
4月 17, 2011
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7036582: Improve test coverage of java.math.BigDecimal
Reviewed-by: darcy Contributed-by: sergey.kuksenko@oracle.com
上级
0ea812f8
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
6081 addition
and
8 deletion
+6081
-8
test/ProblemList.txt
test/ProblemList.txt
+0
-6
test/java/math/BigDecimal/DivideMcTests.java
test/java/math/BigDecimal/DivideMcTests.java
+5797
-0
test/java/math/BigDecimal/FloatDoubleValueTests.java
test/java/math/BigDecimal/FloatDoubleValueTests.java
+23
-0
test/java/math/BigDecimal/RangeTests.java
test/java/math/BigDecimal/RangeTests.java
+245
-0
test/java/math/BigDecimal/StrippingZerosTest.java
test/java/math/BigDecimal/StrippingZerosTest.java
+7
-0
test/java/math/BigDecimal/ToPlainStringTests.java
test/java/math/BigDecimal/ToPlainStringTests.java
+9
-2
未找到文件。
test/ProblemList.txt
浏览文件 @
ca1f906e
...
@@ -288,12 +288,6 @@ javax/management/monitor/AttributeArbitraryDataTypeTest.java generic-all
...
@@ -288,12 +288,6 @@ javax/management/monitor/AttributeArbitraryDataTypeTest.java generic-all
# jdk_math
# jdk_math
# Problems with rounding add failures on solaris-sparcv9 and -server
java/math/BigDecimal/AddTests.java solaris-sparcv9
# Should be samevm? But seems problematic with samevm on windows
java/math/BigInteger/ModPow65537.java generic-all
############################################################################
############################################################################
# jdk_misc
# jdk_misc
...
...
test/java/math/BigDecimal/DivideMcTests.java
0 → 100644
浏览文件 @
ca1f906e
此差异已折叠。
点击以展开。
test/java/math/BigDecimal/FloatDoubleValueTests.java
浏览文件 @
ca1f906e
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
* @test
* @test
* @bug 6274390
* @bug 6274390
* @summary Verify {float, double}Value methods work with condensed representation
* @summary Verify {float, double}Value methods work with condensed representation
* @run main FloatDoubleValueTests
* @run main/othervm -XX:+AggressiveOpts FloatDoubleValueTests
*/
*/
import
java.math.*
;
import
java.math.*
;
...
@@ -64,6 +66,7 @@ public class FloatDoubleValueTests {
...
@@ -64,6 +66,7 @@ public class FloatDoubleValueTests {
static
void
checkDouble
(
BigDecimal
bd
,
double
d
)
{
static
void
checkDouble
(
BigDecimal
bd
,
double
d
)
{
double
dbd
=
bd
.
doubleValue
();
double
dbd
=
bd
.
doubleValue
();
if
(
d
!=
dbd
)
{
if
(
d
!=
dbd
)
{
String
message
=
String
.
format
(
"Bad conversion:"
+
String
message
=
String
.
format
(
"Bad conversion:"
+
"got %g (%a)\texpected %g (%a)"
,
"got %g (%a)\texpected %g (%a)"
,
...
@@ -156,9 +159,29 @@ public class FloatDoubleValueTests {
...
@@ -156,9 +159,29 @@ public class FloatDoubleValueTests {
}
}
}
}
static
void
testFloatValue1
()
{
checkFloat
(
new
BigDecimal
(
"85070591730234615847396907784232501249"
),
8.507059
e
+
37
f
);
checkFloat
(
new
BigDecimal
(
"7784232501249e12"
),
7.7842326e24f
);
checkFloat
(
new
BigDecimal
(
"907784232501249e-12"
),
907.78424f
);
checkFloat
(
new
BigDecimal
(
"7784e8"
),
7.7839997e11f
);
checkFloat
(
new
BigDecimal
(
"9077e-8"
),
9.077
e
-
5
f
);
}
static
void
testDoubleValue1
()
{
checkDouble
(
new
BigDecimal
(
"85070591730234615847396907784232501249"
),
8.507059173023462e37
);
checkDouble
(
new
BigDecimal
(
"7784232501249e12"
),
7.784232501249e24
);
checkDouble
(
new
BigDecimal
(
"907784232501249e-12"
),
907.784232501249
);
checkDouble
(
new
BigDecimal
(
"7784e8"
),
7.784e11
);
checkDouble
(
new
BigDecimal
(
"9077e-8"
),
9.077
e
-
5
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
testFloatDoubleValue
();
testFloatDoubleValue
();
testDoubleValue
();
testDoubleValue
();
testFloatValue
();
testFloatValue
();
testFloatValue1
();
testDoubleValue1
();
}
}
}
}
test/java/math/BigDecimal/RangeTests.java
0 → 100644
浏览文件 @
ca1f906e
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7036582
* @summary Some new tests for the add method and constructor with MathContext.
* @run main RangeTests
* @run main/othervm -XX:+AggressiveOpts RangeTests
* @author Sergey V. Kuksenko
*/
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.math.MathContext
;
public
class
RangeTests
{
private
static
int
addTest
(
BigDecimal
arg1
,
BigDecimal
arg2
,
BigDecimal
expectedResult
)
{
int
failures
=
0
;
BigDecimal
result
=
arg1
.
add
(
arg2
);
if
(!
result
.
equals
(
expectedResult
))
{
System
.
out
.
println
(
"Sum:"
+
arg1
+
" + "
+
arg2
+
" == "
+
result
+
"; expected "
+
expectedResult
);
failures
++;
}
result
=
arg2
.
add
(
arg1
);
if
(!
result
.
equals
(
expectedResult
))
{
System
.
out
.
println
(
"Sum:"
+
arg2
+
" + "
+
arg1
+
" == "
+
result
+
"; expected "
+
expectedResult
);
failures
++;
}
return
failures
;
}
/*
* Test BigDecimal.add(BigDecimal) when values are withing different ranges:
* 1. within 32 bits
* 2. within 64 bits
* 3. outside 64 bits.
*/
private
static
int
addBoundaryTest
()
{
int
failures
=
0
;
failures
+=
addTest
(
new
BigDecimal
(
"85070591730234615847396907784232501249"
),
BigDecimal
.
valueOf
(
0
),
new
BigDecimal
(
"85070591730234615847396907784232501249"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"-85070591730234615847396907784232501249"
),
BigDecimal
.
valueOf
(
0
),
new
BigDecimal
(
"-85070591730234615847396907784232501249"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"85070591730234615847396907784232501249"
),
BigDecimal
.
valueOf
(
1
),
new
BigDecimal
(
"85070591730234615847396907784232501250"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"85070591730234615847396907784232501249"
),
BigDecimal
.
valueOf
(-
1
),
new
BigDecimal
(
"85070591730234615847396907784232501248"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"-85070591730234615847396907784232501250"
),
BigDecimal
.
valueOf
(-
1
),
new
BigDecimal
(
"-85070591730234615847396907784232501251"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"-85070591730234615847396907784232501249"
),
BigDecimal
.
valueOf
(
1
),
new
BigDecimal
(
"-85070591730234615847396907784232501248"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"147573952589676412927"
),
BigDecimal
.
valueOf
(
Integer
.
MAX_VALUE
),
new
BigDecimal
(
"147573952591823896574"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"-147573952589676412927"
),
BigDecimal
.
valueOf
(
Integer
.
MAX_VALUE
),
new
BigDecimal
(
"-147573952587528929280"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"79228162514264337593543950335"
),
BigDecimal
.
valueOf
(
999
),
new
BigDecimal
(
"79228162514264337593543951334"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"79228162514264337593543950335"
),
BigDecimal
.
valueOf
(
Integer
.
MAX_VALUE
/
2
),
new
BigDecimal
(
"79228162514264337594617692158"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"79228162514264337593543950335"
),
BigDecimal
.
valueOf
(
Integer
.
MIN_VALUE
/
2
),
new
BigDecimal
(
"79228162514264337592470208511"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"-79228162514264337593543950335"
),
BigDecimal
.
valueOf
(
Integer
.
MAX_VALUE
/
2
),
new
BigDecimal
(
"-79228162514264337592470208512"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"79228162514264337593543950335"
),
BigDecimal
.
valueOf
(-(
Integer
.
MIN_VALUE
/
2
)),
new
BigDecimal
(
"79228162514264337594617692159"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"79228162514264337593543950335"
),
BigDecimal
.
valueOf
(
Long
.
MAX_VALUE
/
2
),
new
BigDecimal
(
"79228162518876023611971338238"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"79228162514264337593543950335"
),
BigDecimal
.
valueOf
(
Long
.
MIN_VALUE
/
2
),
new
BigDecimal
(
"79228162509652651575116562431"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"-79228162514264337593543950335"
),
BigDecimal
.
valueOf
(
Long
.
MAX_VALUE
/
2
),
new
BigDecimal
(
"-79228162509652651575116562432"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"79228162514264337593543950335"
),
BigDecimal
.
valueOf
(-(
Long
.
MIN_VALUE
/
2
)),
new
BigDecimal
(
"79228162518876023611971338239"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"-9223372036854775808"
),
BigDecimal
.
valueOf
(
1
),
new
BigDecimal
(
"-9223372036854775807"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"-9223372036854775808"
),
BigDecimal
.
valueOf
(
Long
.
MAX_VALUE
/
2
),
new
BigDecimal
(
"-4611686018427387905"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"9223372036854775808"
),
BigDecimal
.
valueOf
(-
1
),
new
BigDecimal
(
"9223372036854775807"
)
);
failures
+=
addTest
(
new
BigDecimal
(
"9223372036854775808"
),
BigDecimal
.
valueOf
(-
Long
.
MAX_VALUE
/
2
),
new
BigDecimal
(
"4611686018427387905"
)
);
return
failures
;
}
private
static
int
testRoundingFromBigInteger
(
BigInteger
bi
,
int
scale
,
MathContext
mc
)
{
int
failures
=
0
;
BigDecimal
bd1
=
new
BigDecimal
(
bi
,
scale
,
mc
);
BigDecimal
bd2
=
(
new
BigDecimal
(
bi
,
scale
)).
round
(
mc
);
if
(!
bd1
.
equals
(
bd2
))
{
System
.
out
.
println
(
"new BigDecimal(BigInteger,int,MathContext):"
+
"BigInteger == "
+
bi
+
"; scale == "
+
scale
+
"; result == "
+
bd1
+
"; expected == "
+
bd2
);
failures
++;
}
return
failures
;
}
private
static
int
roundingConstructorTest
()
{
int
failures
=
0
;
failures
+=
testRoundingFromBigInteger
(
new
BigInteger
(
"85070591730234615847396907784232501249"
),
7
,
MathContext
.
DECIMAL64
);
failures
+=
testRoundingFromBigInteger
(
new
BigInteger
(
"85070591730234615847396907784232501249"
),
0
,
MathContext
.
DECIMAL64
);
failures
+=
testRoundingFromBigInteger
(
new
BigInteger
(
"85070591730234615847396907784232501249"
),
-
7
,
MathContext
.
DECIMAL64
);
failures
+=
testRoundingFromBigInteger
(
new
BigInteger
(
"85070591730234615847396907784232501249"
),
7
,
MathContext
.
DECIMAL128
);
failures
+=
testRoundingFromBigInteger
(
new
BigInteger
(
"85070591730234615847396907784232501249"
),
177
,
MathContext
.
DECIMAL128
);
failures
+=
testRoundingFromBigInteger
(
new
BigInteger
(
"85070591730234615847396907784232501249"
),
177
,
MathContext
.
DECIMAL32
);
failures
+=
testRoundingFromBigInteger
(
new
BigInteger
(
"85070591730234615847396907784232501249"
),
177
,
MathContext
.
UNLIMITED
);
failures
+=
testRoundingFromBigInteger
(
new
BigInteger
(
"85070591730234615847396907784232501249"
),
0
,
MathContext
.
UNLIMITED
);
return
failures
;
}
private
static
int
minLongConstructorTest
(
MathContext
mc
)
{
int
failures
=
0
;
BigDecimal
bd1
=
new
BigDecimal
(
Long
.
MIN_VALUE
,
mc
);
BigDecimal
bd2
=
new
BigDecimal
(
Long
.
MIN_VALUE
).
round
(
mc
);
if
(!
bd1
.
equals
(
bd2
))
{
System
.
out
.
println
(
"new BigDecimal(long,MathContext):"
+
"long == "
+
Long
.
MIN_VALUE
+
"; result == "
+
bd1
+
"; expected == "
+
bd2
);
failures
++;
}
return
failures
;
}
private
static
int
minLongConstructorTest
()
{
int
failures
=
0
;
failures
+=
minLongConstructorTest
(
MathContext
.
UNLIMITED
);
failures
+=
minLongConstructorTest
(
MathContext
.
DECIMAL32
);
failures
+=
minLongConstructorTest
(
MathContext
.
DECIMAL64
);
failures
+=
minLongConstructorTest
(
MathContext
.
DECIMAL128
);
return
failures
;
}
public
static
void
main
(
String
argv
[])
{
int
failures
=
0
;
failures
+=
addBoundaryTest
();
failures
+=
roundingConstructorTest
();
failures
+=
minLongConstructorTest
();
if
(
failures
>
0
)
{
throw
new
RuntimeException
(
"Incurred "
+
failures
+
" failures while testing."
);
}
}
}
test/java/math/BigDecimal/StrippingZerosTest.java
浏览文件 @
ca1f906e
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
* @test
* @test
* @bug 4108852
* @bug 4108852
* @summary A few tests of stripTrailingZeros
* @summary A few tests of stripTrailingZeros
* @run main StrippingZerosTest
* @run main/othervm -XX:+AggressiveOpts StrippingZerosTest
* @author Joseph D. Darcy
* @author Joseph D. Darcy
*/
*/
...
@@ -53,6 +55,11 @@ public class StrippingZerosTest {
...
@@ -53,6 +55,11 @@ public class StrippingZerosTest {
{
new
BigDecimal
(
"10000000e2"
),
new
BigDecimal
(
"1e9"
)},
{
new
BigDecimal
(
"10000000e2"
),
new
BigDecimal
(
"1e9"
)},
{
new
BigDecimal
(
"1000000e3"
),
new
BigDecimal
(
"1e9"
)},
{
new
BigDecimal
(
"1000000e3"
),
new
BigDecimal
(
"1e9"
)},
{
new
BigDecimal
(
"100000e4"
),
new
BigDecimal
(
"1e9"
)},
{
new
BigDecimal
(
"100000e4"
),
new
BigDecimal
(
"1e9"
)},
// BD value which larger than Long.MaxValue
{
new
BigDecimal
(
"1.0000000000000000000000000000"
),
new
BigDecimal
(
"1"
)},
{
new
BigDecimal
(
"-1.0000000000000000000000000000"
),
new
BigDecimal
(
"-1"
)},
{
new
BigDecimal
(
"1.00000000000000000000000000001"
),
new
BigDecimal
(
"1.00000000000000000000000000001"
)},
{
new
BigDecimal
(
"1000000000000000000000000000000e4"
),
new
BigDecimal
(
"1e34"
)},
};
};
for
(
int
i
=
0
;
i
<
testCases
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
testCases
.
length
;
i
++)
{
...
...
test/java/math/BigDecimal/ToPlainStringTests.java
浏览文件 @
ca1f906e
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
* @test
* @test
* @bug 4984872
* @bug 4984872
* @summary Basic tests of toPlainString method
* @summary Basic tests of toPlainString method
* @run main ToPlainStringTests
* @run main/othervm -XX:+AggressiveOpts ToPlainStringTests
* @author Joseph D. Darcy
* @author Joseph D. Darcy
*/
*/
...
@@ -60,6 +62,11 @@ public class ToPlainStringTests {
...
@@ -60,6 +62,11 @@ public class ToPlainStringTests {
{
"8e-8"
,
"0.00000008"
},
{
"8e-8"
,
"0.00000008"
},
{
"9e-9"
,
"0.000000009"
},
{
"9e-9"
,
"0.000000009"
},
{
"9000e-12"
,
"0.000000009000"
},
{
"9000e-12"
,
"0.000000009000"
},
{
"9000e-22"
,
"0.0000000000000000009000"
},
{
"12345678901234567890"
,
"12345678901234567890"
},
{
"12345678901234567890e22"
,
"123456789012345678900000000000000000000000"
},
{
"12345678901234567890e-22"
,
"0.0012345678901234567890"
},
};
};
int
errors
=
0
;
int
errors
=
0
;
...
@@ -73,8 +80,8 @@ public class ToPlainStringTests {
...
@@ -73,8 +80,8 @@ public class ToPlainStringTests {
s
+
"'' from BigDecimal "
+
s
+
"'' from BigDecimal "
+
bd
);
bd
);
}
}
bd
=
new
BigDecimal
(
"-"
+
testCase
[
0
]);
if
(
!(
s
=(
"-"
+
bd
.
toPlainString
())).
equals
(
"-"
+
testCase
[
1
]))
{
if
(
bd
.
signum
()!=
0
&&
!(
s
=(
bd
.
toPlainString
())).
equals
(
"-"
+
testCase
[
1
]))
{
errors
++;
errors
++;
System
.
err
.
println
(
"Unexpected plain result ``"
+
System
.
err
.
println
(
"Unexpected plain result ``"
+
s
+
"'' from BigDecimal "
+
s
+
"'' from BigDecimal "
+
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录