diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java index e96c934cb..db8b80949 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java @@ -16,11 +16,18 @@ package com.android.inputmethod.latin; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import android.text.TextUtils; import android.util.Pair; +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.LargeTest; +import androidx.test.runner.AndroidJUnit4; + import com.android.inputmethod.latin.NgramContext.WordInfo; import com.android.inputmethod.latin.common.CodePointUtils; import com.android.inputmethod.latin.common.FileUtils; @@ -30,6 +37,11 @@ import com.android.inputmethod.latin.makedict.WeightedString; import com.android.inputmethod.latin.makedict.WordProperty; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -39,26 +51,25 @@ import java.util.Locale; import java.util.Random; @LargeTest -public class BinaryDictionaryTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class BinaryDictionaryTests { private static final String TEST_DICT_FILE_EXTENSION = ".testDict"; private static final String TEST_LOCALE = "test"; private static final String DICTIONARY_ID = "TestBinaryDictionary"; private HashSet<File> mDictFilesToBeDeleted = new HashSet<>(); - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { mDictFilesToBeDeleted.clear(); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { for (final File dictFile : mDictFilesToBeDeleted) { dictFile.delete(); } mDictFilesToBeDeleted.clear(); - super.tearDown(); } private File createEmptyDictionaryAndGetFile(final int formatVersion) { @@ -82,7 +93,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { private File createEmptyVer4DictionaryAndGetFile(final int formatVersion, final HashMap<String, String> attributeMap) throws IOException { final File file = File.createTempFile(DICTIONARY_ID, TEST_DICT_FILE_EXTENSION, - getContext().getCacheDir()); + InstrumentationRegistry.getTargetContext().getCacheDir()); file.delete(); file.mkdir(); if (BinaryDictionaryUtils.createEmptyDictFile(file.getAbsolutePath(), formatVersion, @@ -106,6 +117,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); } + @Test public void testIsValidDictionary() { final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); @@ -121,6 +133,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.close(); } + @Test public void testConstructingDictionaryOnMemory() { final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); FileUtils.deleteRecursively(dictFile); @@ -142,6 +155,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.close(); } + @Test public void testAddTooLongWord() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final StringBuffer stringBuilder = new StringBuffer(); @@ -209,6 +223,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { new NgramContext(new WordInfo(word1), new WordInfo(word0)), word2); } + @Test public void testAddUnigramWord() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final int probability = 100; @@ -236,6 +251,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { assertEquals(updatedProbability, binaryDictionary.getFrequency("aaa")); } + @Test public void testRandomlyAddUnigramWord() { final int wordCount = 1000; final int codePointSetSize = 50; @@ -258,6 +274,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testAddBigramWords() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); @@ -311,6 +328,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { getBigramProbability(binaryDictionary, "abcde", "fghij")); } + @Test public void testRandomlyAddBigramWords() { final int wordCount = 100; final int bigramCount = 1000; @@ -357,6 +375,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testAddTrigramWords() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final int unigramProbability = 100; @@ -383,6 +402,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { getTrigramProbability(binaryDictionary, "bcc", "abb", "aaa")); } + @Test public void testFlushDictionary() { final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); @@ -417,6 +437,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.close(); } + @Test public void testFlushWithGCDictionary() { final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); @@ -447,6 +468,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.close(); } + @Test public void testAddBigramWordsAndFlashWithGC() { final int wordCount = 100; final int bigramCount = 1000; @@ -499,6 +521,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testRandomOperationsAndFlashWithGC() { final int maxUnigramCount = 5000; final int maxBigramCount = 10000; @@ -593,6 +616,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testAddManyUnigramsAndFlushWithGC() { final int flashWithGCIterationCount = 3; final int codePointSetSize = 50; @@ -628,6 +652,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testUnigramAndBigramCount() { final int maxUnigramCount = 5000; final int maxBigramCount = 10000; @@ -684,6 +709,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testGetWordProperties() { final long seed = System.currentTimeMillis(); final Random random = new Random(seed); @@ -769,6 +795,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } } + @Test public void testIterateAllWords() { final long seed = System.currentTimeMillis(); final Random random = new Random(seed); @@ -852,6 +879,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { assertTrue(bigramSet.isEmpty()); } + @Test public void testPossiblyOffensiveAttributeMaintained() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); @@ -860,6 +888,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { assertEquals(true, wordProperty.mIsPossiblyOffensive); } + @Test public void testBeginningOfSentence() { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final int dummyProbability = 0; |