Merge "Change how the length of the random words are chosen."

main
Jean Chalard 2013-07-05 02:48:13 +00:00 committed by Android (Google) Code Review
commit 9aa1efdf46
1 changed files with 13 additions and 4 deletions

View File

@ -151,11 +151,20 @@ public class BinaryDictIOTests extends AndroidTestCase {
* Generates a random word. * Generates a random word.
*/ */
private String generateWord(final Random random, final int[] codePointSet) { private String generateWord(final Random random, final int[] codePointSet) {
StringBuilder builder = new StringBuilder("a"); StringBuilder builder = new StringBuilder();
int count = random.nextInt() % 30; // Arbitrarily 30 chars max // 8 * 4 = 32 chars max, but we do it the following way so as to bias the random toward
while (count > 0) { // longer words. This should be closer to natural language, and more importantly, it will
// exercise the algorithms in dicttool much more.
final int count = 1 + (Math.abs(random.nextInt()) % 5)
+ (Math.abs(random.nextInt()) % 5)
+ (Math.abs(random.nextInt()) % 5)
+ (Math.abs(random.nextInt()) % 5)
+ (Math.abs(random.nextInt()) % 5)
+ (Math.abs(random.nextInt()) % 5)
+ (Math.abs(random.nextInt()) % 5)
+ (Math.abs(random.nextInt()) % 5);
while (builder.length() < count) {
builder.appendCodePoint(codePointSet[Math.abs(random.nextInt()) % codePointSet.length]); builder.appendCodePoint(codePointSet[Math.abs(random.nextInt()) % codePointSet.length]);
--count;
} }
return builder.toString(); return builder.toString();
} }