提交 69799fc8 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved tests.

上级 ce8a983b
......@@ -104,7 +104,7 @@ public class MathUtils {
return cachedSecureRandom;
}
private static byte[] generateAlternativeSeed() {
public static byte[] generateAlternativeSeed() {
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bout);
......
......@@ -10,6 +10,7 @@ import java.math.BigInteger;
import java.util.Random;
import org.h2.test.TestBase;
import org.h2.test.utils.AssertThrows;
import org.h2.util.MathUtils;
/**
* Tests math utility methods.
......@@ -26,10 +27,32 @@ public class TestMathUtils extends TestBase {
}
public void test() {
testRandom();
testReverse();
testFactorial();
}
private void testRandom() {
int bits = 0;
for (int i = 0; i < 1000; i++) {
bits |= 1 << MathUtils.randomInt(8);
}
assertEquals(255, bits);
bits = 0;
for (int i = 0; i < 1000; i++) {
bits |= 1 << MathUtils.secureRandomInt(8);
}
assertEquals(255, bits);
bits = 0;
for (int i = 0; i < 1000; i++) {
bits |= 1 << (MathUtils.secureRandomLong() & 7);
}
assertEquals(255, bits);
// just verify the method doesn't throw an exception
byte[] data = MathUtils.generateAlternativeSeed();
assertTrue(data.length > 10);
}
private void testReverse() {
assertEquals(Integer.reverse(0), Integer.reverse(0));
assertEquals(Integer.reverse(Integer.MAX_VALUE), Integer.reverse(Integer.MAX_VALUE));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论