Merge "Add args to dicttool test."
commit
edf5842568
|
@ -44,9 +44,10 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
|
||||||
private static final String TAG = BinaryDictIOUtilsTests.class.getSimpleName();
|
private static final String TAG = BinaryDictIOUtilsTests.class.getSimpleName();
|
||||||
private static final FormatSpec.FormatOptions FORMAT_OPTIONS =
|
private static final FormatSpec.FormatOptions FORMAT_OPTIONS =
|
||||||
new FormatSpec.FormatOptions(3, true);
|
new FormatSpec.FormatOptions(3, true);
|
||||||
private static final int MAX_UNIGRAMS = 1500;
|
|
||||||
|
|
||||||
private static final ArrayList<String> sWords = CollectionUtils.newArrayList();
|
private static final ArrayList<String> sWords = CollectionUtils.newArrayList();
|
||||||
|
public static final int DEFAULT_MAX_UNIGRAMS = 1500;
|
||||||
|
private final int mMaxUnigrams;
|
||||||
|
|
||||||
private static final String[] CHARACTERS = {
|
private static final String[] CHARACTERS = {
|
||||||
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
|
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
|
||||||
|
@ -57,15 +58,17 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
|
||||||
};
|
};
|
||||||
|
|
||||||
public BinaryDictIOUtilsTests() {
|
public BinaryDictIOUtilsTests() {
|
||||||
this(System.currentTimeMillis());
|
// 1500 is the default max unigrams
|
||||||
|
this(System.currentTimeMillis(), DEFAULT_MAX_UNIGRAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BinaryDictIOUtilsTests(final long seed) {
|
public BinaryDictIOUtilsTests(final long seed, final int maxUnigrams) {
|
||||||
super();
|
super();
|
||||||
Log.d(TAG, "Seed for test is " + seed);
|
Log.d(TAG, "Seed for test is " + seed + ", maxUnigrams is " + maxUnigrams);
|
||||||
|
mMaxUnigrams = maxUnigrams;
|
||||||
final Random random = new Random(seed);
|
final Random random = new Random(seed);
|
||||||
sWords.clear();
|
sWords.clear();
|
||||||
for (int i = 0; i < MAX_UNIGRAMS; ++i) {
|
for (int i = 0; i < maxUnigrams; ++i) {
|
||||||
sWords.add(generateWord(random.nextInt()));
|
sWords.add(generateWord(random.nextInt()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,6 +398,6 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
|
||||||
|
|
||||||
Log.d(TAG, "max = " + ((double)maxTimeToInsert/1000000) + " ms.");
|
Log.d(TAG, "max = " + ((double)maxTimeToInsert/1000000) + " ms.");
|
||||||
Log.d(TAG, "min = " + ((double)minTimeToInsert/1000000) + " ms.");
|
Log.d(TAG, "min = " + ((double)minTimeToInsert/1000000) + " ms.");
|
||||||
Log.d(TAG, "avg = " + ((double)sum/MAX_UNIGRAMS/1000000) + " ms.");
|
Log.d(TAG, "avg = " + ((double)sum/mMaxUnigrams/1000000) + " ms.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,33 +19,80 @@ package com.android.inputmethod.latin.dicttool;
|
||||||
import com.android.inputmethod.latin.makedict.BinaryDictIOUtilsTests;
|
import com.android.inputmethod.latin.makedict.BinaryDictIOUtilsTests;
|
||||||
import com.android.inputmethod.latin.makedict.BinaryDictInputOutputTest;
|
import com.android.inputmethod.latin.makedict.BinaryDictInputOutputTest;
|
||||||
import com.android.inputmethod.latin.makedict.FusionDictionaryTest;
|
import com.android.inputmethod.latin.makedict.FusionDictionaryTest;
|
||||||
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dicttool command implementing self-tests.
|
* Dicttool command implementing self-tests.
|
||||||
*/
|
*/
|
||||||
public class Test extends Dicttool.Command {
|
public class Test extends Dicttool.Command {
|
||||||
public static final String COMMAND = "test";
|
public static final String COMMAND = "test";
|
||||||
|
private long mSeed = System.currentTimeMillis();
|
||||||
|
private int mMaxUnigrams = BinaryDictIOUtilsTests.DEFAULT_MAX_UNIGRAMS;
|
||||||
|
|
||||||
|
private static final Class<?>[] sClassesToTest = {
|
||||||
|
BinaryDictOffdeviceUtilsTests.class,
|
||||||
|
FusionDictionaryTest.class,
|
||||||
|
BinaryDictInputOutputTest.class,
|
||||||
|
BinaryDictIOUtilsTests.class
|
||||||
|
};
|
||||||
|
private ArrayList<Method> mAllTestMethods = new ArrayList<Method>();
|
||||||
|
private ArrayList<String> mUsedTestMethods = new ArrayList<String>();
|
||||||
|
|
||||||
public Test() {
|
public Test() {
|
||||||
|
for (final Class<?> c : sClassesToTest) {
|
||||||
|
for (final Method m : c.getDeclaredMethods()) {
|
||||||
|
if (m.getName().startsWith("test") && Void.TYPE == m.getReturnType()
|
||||||
|
&& 0 == m.getParameterTypes().length) {
|
||||||
|
mAllTestMethods.add(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelp() {
|
public String getHelp() {
|
||||||
return "test";
|
final StringBuilder s = new StringBuilder("test [-s seed] [-m maxUnigrams] [testName...]\n"
|
||||||
|
+ "If seed is not specified, the current time is used.\nTest list is:\n");
|
||||||
|
for (final Method m : mAllTestMethods) {
|
||||||
|
s.append(" ");
|
||||||
|
s.append(m.getName());
|
||||||
|
s.append("\n");
|
||||||
|
}
|
||||||
|
return s.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() throws IOException, UnsupportedFormatException {
|
public void run() throws IllegalAccessException, InstantiationException,
|
||||||
test();
|
InvocationTargetException {
|
||||||
|
int i = 0;
|
||||||
|
while (i < mArgs.length) {
|
||||||
|
final String arg = mArgs[i++];
|
||||||
|
if ("-s".equals(arg)) {
|
||||||
|
mSeed = Long.parseLong(mArgs[i++]);
|
||||||
|
} else if ("-m".equals(arg)) {
|
||||||
|
mMaxUnigrams = Integer.parseInt(mArgs[i++]);
|
||||||
|
} else {
|
||||||
|
mUsedTestMethods.add(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
runChosenTests();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void test() throws IOException, UnsupportedFormatException {
|
private void runChosenTests() throws IllegalAccessException, InstantiationException,
|
||||||
new BinaryDictOffdeviceUtilsTests().testGetRawDictWorks();
|
InvocationTargetException {
|
||||||
new FusionDictionaryTest().testFusion();
|
for (final Method m : mAllTestMethods) {
|
||||||
new BinaryDictInputOutputTest().testFlattenNodes();
|
final Class<?> declaringClass = m.getDeclaringClass();
|
||||||
new BinaryDictIOUtilsTests().testRandomWords();
|
if (!mUsedTestMethods.isEmpty() && !mUsedTestMethods.contains(m.getName())) continue;
|
||||||
|
final Object instance;
|
||||||
|
if (BinaryDictIOUtilsTests.class == declaringClass) {
|
||||||
|
instance = new BinaryDictIOUtilsTests(mSeed, mMaxUnigrams);
|
||||||
|
} else {
|
||||||
|
instance = declaringClass.newInstance();
|
||||||
|
}
|
||||||
|
m.invoke(instance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue