aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-04-01 15:23:24 +0900
committerJean Chalard <jchalard@google.com>2013-04-01 17:06:19 +0900
commita411595b169c1f136d09d114a458def1f99f91d9 (patch)
treedccc5927d38eadfbf8f6b5ba588c022a8873b62d /tests/src
parent48d8d8d0ae573605f938b3859bf58e1972f0d737 (diff)
downloadlatinime-a411595b169c1f136d09d114a458def1f99f91d9.tar.gz
latinime-a411595b169c1f136d09d114a458def1f99f91d9.tar.xz
latinime-a411595b169c1f136d09d114a458def1f99f91d9.zip
Fix two nasty bugs with surrogate pairs.
The important bug is in findWordInTree. The problem, which is not obvious, is that we were calling codePointAt() with the code point index in the string, instead of the char index. The other bug this change fixes was harmless in the practice, because it's in the iteration which is only used for debug and pretty printing purposes. It's very similar in that it would substract a length in code point to a length in chars and truncate a StringBuilder at that length, so it would fail in a quite similar manner. This changes the meaning of the "length" attribute in Position, but it's clearer this way anyway. Bug: 8450145 Change-Id: If396f883a9e6449de39351553ba83f5be5bd30f0
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java28
1 files changed, 14 insertions, 14 deletions
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
index ade010981..bd8729203 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
@@ -72,15 +72,12 @@ public class BinaryDictIOTests extends AndroidTestCase {
private static final FormatSpec.FormatOptions VERSION3_WITH_DYNAMIC_UPDATE =
new FormatSpec.FormatOptions(3, true /* supportsDynamicUpdate */);
- private static final String[] CHARACTERS = {
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
- "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
- };
-
public BinaryDictIOTests() {
super();
- final Random random = new Random(123456);
+ final long time = System.currentTimeMillis();
+ Log.e(TAG, "Testing dictionary: seed is " + time);
+ final Random random = new Random(time);
sWords.clear();
generateWords(MAX_UNIGRAMS, random);
@@ -132,13 +129,16 @@ public class BinaryDictIOTests extends AndroidTestCase {
/**
* Generates a random word.
*/
- private String generateWord(final int value) {
- final int lengthOfChars = CHARACTERS.length;
+ private String generateWord(final Random random) {
StringBuilder builder = new StringBuilder("a");
- long lvalue = Math.abs((long)value);
- while (lvalue > 0) {
- builder.append(CHARACTERS[(int)(lvalue % lengthOfChars)]);
- lvalue /= lengthOfChars;
+ int count = random.nextInt() % 30; // Arbitrarily 30 chars max
+ while (count > 0) {
+ final long r = Math.abs(random.nextInt());
+ if (r < 0) continue;
+ // Don't insert 0~20, but insert any other code point.
+ // Code points are in the range 0~0x10FFFF.
+ builder.appendCodePoint((int)(20 + r % (0x10FFFF - 20)));
+ --count;
}
return builder.toString();
}
@@ -146,7 +146,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
private void generateWords(final int number, final Random random) {
final Set<String> wordSet = CollectionUtils.newHashSet();
while (wordSet.size() < number) {
- wordSet.add(generateWord(random.nextInt()));
+ wordSet.add(generateWord(random));
}
sWords.addAll(wordSet);
}
@@ -555,7 +555,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
// Test a word that isn't contained within the dictionary.
final Random random = new Random((int)System.currentTimeMillis());
for (int i = 0; i < 1000; ++i) {
- final String word = generateWord(random.nextInt());
+ final String word = generateWord(random);
if (sWords.indexOf(word) != -1) continue;
runGetTerminalPosition(buffer, word, i, false);
}