Speedup MessageDigestTests#testToHexString
The purpose of this commit is to speed up the runtime of MessageDigestTests#testToHexString. As written, the test contains a loop that creates 1024 test cases leading to a test runtime on the order of a few seconds. Given build infrastructure, a single test case should suffice. Therefore, this commit removes this loop so that the test can execute on the order of a couple hundred milliseconds.
This commit is contained in:
parent
bf382ce5d8
commit
cbeae225b9
|
@ -59,16 +59,14 @@ public class MessageDigestsTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testToHexString() throws Exception {
|
public void testToHexString() throws Exception {
|
||||||
for (int i = 0; i < 1024; i++) {
|
BigInteger expected = BigInteger.probablePrime(256, random());
|
||||||
BigInteger expected = BigInteger.probablePrime(256, random());
|
byte[] bytes = expected.toByteArray();
|
||||||
byte[] bytes = expected.toByteArray();
|
String hex = MessageDigests.toHexString(bytes);
|
||||||
String hex = MessageDigests.toHexString(bytes);
|
String zeros = new String(new char[2 * bytes.length]).replace("\0", "0");
|
||||||
String zeros = new String(new char[2 * bytes.length]).replace("\0", "0");
|
String expectedAsString = expected.toString(16);
|
||||||
String expectedAsString = expected.toString(16);
|
String expectedHex = zeros.substring(expectedAsString.length()) + expectedAsString;
|
||||||
String expectedHex = zeros.substring(expectedAsString.length()) + expectedAsString;
|
assertEquals(expectedHex, hex);
|
||||||
assertEquals(expectedHex, hex);
|
BigInteger actual = new BigInteger(hex, 16);
|
||||||
BigInteger actual = new BigInteger(hex, 16);
|
assertEquals(expected, actual);
|
||||||
assertEquals(expected, actual);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue