diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/makedict')
3 files changed, 99 insertions, 25 deletions
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java index aa1658301..0189b3334 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -646,7 +646,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } } - public void testDeleteWord() { + private void runTestDeleteWord(final FormatOptions formatOptions) { final String dictName = "testDeleteWord"; final String dictVersion = Long.toString(System.currentTimeMillis()); final File file = setUpDictionaryFile(dictName, dictVersion); @@ -655,10 +655,17 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { new FusionDictionary.DictionaryOptions( new HashMap<String, String>(), false, false)); addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */); - timeWritingDictToFile(file, dict, VERSION3_WITH_DYNAMIC_UPDATE); + timeWritingDictToFile(file, dict, formatOptions); - final Ver3DictUpdater dictUpdater = new Ver3DictUpdater(file, - DictDecoder.USE_WRITABLE_BYTEBUFFER); + final DictUpdater dictUpdater; + if (formatOptions.mVersion == 3) { + dictUpdater = new Ver3DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER); + } else if (formatOptions.mVersion == 4) { + dictUpdater = new Ver4DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER); + } else { + throw new RuntimeException("DictUpdater for version " + formatOptions.mVersion + + " doesn't exist."); + } try { MoreAsserts.assertNotEqual(FormatSpec.NOT_VALID_WORD, @@ -676,4 +683,9 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } catch (UnsupportedFormatException e) { } } + + public void testDeleteWord() { + runTestDeleteWord(VERSION3_WITH_DYNAMIC_UPDATE); + runTestDeleteWord(VERSION4_WITH_DYNAMIC_UPDATE); + } } diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java index acd65856c..afe5adb73 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java @@ -45,6 +45,9 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { private static final String TEST_DICT_FILE_EXTENSION = ".testDict"; + private static final int VERSION3 = 3; + private static final int VERSION4 = 4; + 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", @@ -183,11 +186,16 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { // return amount of time to insert a word private long insertAndCheckWord(final File file, final String word, final int frequency, final boolean exist, final ArrayList<WeightedString> bigrams, - final ArrayList<WeightedString> shortcuts) { + final ArrayList<WeightedString> shortcuts, final int formatVersion) { long amountOfTime = -1; try { - final Ver3DictUpdater dictUpdater = new Ver3DictUpdater(file, - DictDecoder.USE_WRITABLE_BYTEBUFFER); + final DictUpdater dictUpdater; + if (formatVersion == VERSION3) { + dictUpdater = new Ver3DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER); + } else { + throw new RuntimeException("DictUpdater for version " + formatVersion + " doesn't" + + " exist."); + } if (!exist) { assertEquals(FormatSpec.NOT_VALID_WORD, getWordPosition(file, word)); @@ -204,10 +212,15 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { return amountOfTime; } - private void deleteWord(final File file, final String word) { + private void deleteWord(final File file, final String word, final int formatVersion) { try { - final Ver3DictUpdater dictUpdater = new Ver3DictUpdater(file, - DictDecoder.USE_WRITABLE_BYTEBUFFER); + final DictUpdater dictUpdater; + if (formatVersion == VERSION3) { + dictUpdater = new Ver3DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER); + } else { + throw new RuntimeException("DictUpdater for version " + formatVersion + " doesn't" + + " exist."); + } dictUpdater.deleteWord(word); } catch (IOException e) { } catch (UnsupportedFormatException e) { @@ -229,7 +242,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { } } - public void testInsertWord() { + private void runTestInsertWord(final int formatVersion) { File file = null; try { file = File.createTempFile("testInsertWord", TEST_DICT_FILE_EXTENSION, @@ -253,33 +266,37 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { } MoreAsserts.assertNotEqual(FormatSpec.NOT_VALID_WORD, getWordPosition(file, "abcd")); - insertAndCheckWord(file, "abcde", 10, false, null, null); + insertAndCheckWord(file, "abcde", 10, false, null, null, formatVersion); - insertAndCheckWord(file, "abcdefghijklmn", 10, false, null, null); + insertAndCheckWord(file, "abcdefghijklmn", 10, false, null, null, formatVersion); checkReverseLookup(file, "abcdefghijklmn", getWordPosition(file, "abcdefghijklmn")); - insertAndCheckWord(file, "abcdabcd", 10, false, null, null); + insertAndCheckWord(file, "abcdabcd", 10, false, null, null, formatVersion); checkReverseLookup(file, "abcdabcd", getWordPosition(file, "abcdabcd")); // update the existing word. - insertAndCheckWord(file, "abcdabcd", 15, true, null, null); + insertAndCheckWord(file, "abcdabcd", 15, true, null, null, formatVersion); // split 1 - insertAndCheckWord(file, "ab", 20, false, null, null); + insertAndCheckWord(file, "ab", 20, false, null, null, formatVersion); // split 2 - insertAndCheckWord(file, "ami", 30, false, null, null); + insertAndCheckWord(file, "ami", 30, false, null, null, formatVersion); - deleteWord(file, "ami"); + deleteWord(file, "ami", formatVersion); assertEquals(FormatSpec.NOT_VALID_WORD, getWordPosition(file, "ami")); - insertAndCheckWord(file, "abcdabfg", 30, false, null, null); + insertAndCheckWord(file, "abcdabfg", 30, false, null, null, formatVersion); - deleteWord(file, "abcd"); + deleteWord(file, "abcd", formatVersion); assertEquals(FormatSpec.NOT_VALID_WORD, getWordPosition(file, "abcd")); } - public void testInsertWordWithBigrams() { + public void testInsertWord() { + runTestInsertWord(VERSION3); + } + + private void runTestInsertWordWithBigrams(final int formatVersion) { File file = null; try { file = File.createTempFile("testInsertWordWithBigrams", TEST_DICT_FILE_EXTENSION, @@ -306,8 +323,8 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { final ArrayList<WeightedString> banana = new ArrayList<WeightedString>(); banana.add(new WeightedString("banana", 10)); - insertAndCheckWord(file, "banana", 0, false, null, null); - insertAndCheckWord(file, "recursive", 60, true, banana, null); + insertAndCheckWord(file, "banana", 0, false, null, null, formatVersion); + insertAndCheckWord(file, "recursive", 60, true, banana, null, formatVersion); final PtNodeInfo info = findWordFromFile(file, "recursive"); int bananaPos = getWordPosition(file, "banana"); @@ -316,7 +333,11 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { assertEquals(info.mBigrams.get(0).mAddress, bananaPos); } - public void testRandomWords() { + public void testInsertWordWithBigrams() { + runTestInsertWordWithBigrams(VERSION3); + } + + private void runTestRandomWords(final int formatVersion) { File file = null; try { file = File.createTempFile("testRandomWord", TEST_DICT_FILE_EXTENSION, @@ -345,7 +366,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { int cnt = 0; for (final String word : sWords) { final long diff = insertAndCheckWord(file, word, - cnt % FormatSpec.MAX_TERMINAL_FREQUENCY, false, null, null); + cnt % FormatSpec.MAX_TERMINAL_FREQUENCY, false, null, null, formatVersion); maxTimeToInsert = Math.max(maxTimeToInsert, diff); minTimeToInsert = Math.min(minTimeToInsert, diff); sum += diff; @@ -356,8 +377,13 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { MoreAsserts.assertNotEqual(FormatSpec.NOT_VALID_WORD, getWordPosition(file, word)); } + Log.d(TAG, "Test version " + formatVersion); Log.d(TAG, "max = " + ((double)maxTimeToInsert/1000000) + " ms."); Log.d(TAG, "min = " + ((double)minTimeToInsert/1000000) + " ms."); Log.d(TAG, "avg = " + ((double)sum/mMaxUnigrams/1000000) + " ms."); } + + public void testRandomWords() { + runTestRandomWords(VERSION3); + } } diff --git a/tests/src/com/android/inputmethod/latin/makedict/CodePointUtils.java b/tests/src/com/android/inputmethod/latin/makedict/CodePointUtils.java index 36b958af8..a270ee774 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/CodePointUtils.java +++ b/tests/src/com/android/inputmethod/latin/makedict/CodePointUtils.java @@ -24,6 +24,42 @@ public class CodePointUtils { // This utility class is not publicly instantiable. } + public static final int[] LATIN_ALPHABETS_LOWER = { + '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', + 0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */, + 0x00E1 /* LATIN SMALL LETTER A WITH ACUTE */, + 0x00E2 /* LATIN SMALL LETTER A WITH CIRCUMFLEX */, + 0x00E3 /* LATIN SMALL LETTER A WITH TILDE */, + 0x00E4 /* LATIN SMALL LETTER A WITH DIAERESIS */, + 0x00E5 /* LATIN SMALL LETTER A WITH RING ABOVE */, + 0x00E6 /* LATIN SMALL LETTER AE */, + 0x00E7 /* LATIN SMALL LETTER C WITH CEDILLA */, + 0x00E8 /* LATIN SMALL LETTER E WITH GRAVE */, + 0x00E9 /* LATIN SMALL LETTER E WITH ACUTE */, + 0x00EA /* LATIN SMALL LETTER E WITH CIRCUMFLEX */, + 0x00EB /* LATIN SMALL LETTER E WITH DIAERESIS */, + 0x00EC /* LATIN SMALL LETTER I WITH GRAVE */, + 0x00ED /* LATIN SMALL LETTER I WITH ACUTE */, + 0x00EE /* LATIN SMALL LETTER I WITH CIRCUMFLEX */, + 0x00EF /* LATIN SMALL LETTER I WITH DIAERESIS */, + 0x00F0 /* LATIN SMALL LETTER ETH */, + 0x00F1 /* LATIN SMALL LETTER N WITH TILDE */, + 0x00F2 /* LATIN SMALL LETTER O WITH GRAVE */, + 0x00F3 /* LATIN SMALL LETTER O WITH ACUTE */, + 0x00F4 /* LATIN SMALL LETTER O WITH CIRCUMFLEX */, + 0x00F5 /* LATIN SMALL LETTER O WITH TILDE */, + 0x00F6 /* LATIN SMALL LETTER O WITH DIAERESIS */, + 0x00F7 /* LATIN SMALL LETTER O WITH STROKE */, + 0x00F9 /* LATIN SMALL LETTER U WITH GRAVE */, + 0x00FA /* LATIN SMALL LETTER U WITH ACUTE */, + 0x00FB /* LATIN SMALL LETTER U WITH CIRCUMFLEX */, + 0x00FC /* LATIN SMALL LETTER U WITH DIAERESIS */, + 0x00FD /* LATIN SMALL LETTER Y WITH ACUTE */, + 0x00FE /* LATIN SMALL LETTER THORN */, + 0x00FF /* LATIN SMALL LETTER Y WITH DIAERESIS */ + }; + public static int[] generateCodePointSet(final int codePointSetSize, final Random random) { final int[] codePointSet = new int[codePointSetSize]; for (int i = codePointSet.length - 1; i >= 0; ) { |