diff options
author | 2013-07-04 17:09:14 +0900 | |
---|---|---|
committer | 2013-07-04 22:22:34 +0900 | |
commit | 4a1c26aba73525ca965e5d72e0880d8ebd95c311 (patch) | |
tree | f99d6a30c4405bf5e59e93908165950ae548affa | |
parent | cea80fd9554a9db2a8421d267a57999f4f3c53b4 (diff) | |
download | latinime-4a1c26aba73525ca965e5d72e0880d8ebd95c311.tar.gz latinime-4a1c26aba73525ca965e5d72e0880d8ebd95c311.tar.xz latinime-4a1c26aba73525ca965e5d72e0880d8ebd95c311.zip |
Change how the length of the random words are chosen.
This is much more robust and much better for testing.
Change-Id: I43f900f9debc1d1ae4c3f3dd07dbe0ac85d31f52
-rw-r--r-- | tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java index d667db298..55f163255 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java @@ -151,11 +151,20 @@ public class BinaryDictIOTests extends AndroidTestCase { * Generates a random word. */ private String generateWord(final Random random, final int[] codePointSet) { - StringBuilder builder = new StringBuilder("a"); - int count = random.nextInt() % 30; // Arbitrarily 30 chars max - while (count > 0) { + StringBuilder builder = new StringBuilder(); + // 8 * 4 = 32 chars max, but we do it the following way so as to bias the random toward + // 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]); - --count; } return builder.toString(); } |