aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java30
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java3
2 files changed, 9 insertions, 24 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java
index b0cd4df5c..26d2e2ad2 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java
@@ -24,27 +24,13 @@ import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
/**
* This class builds an actual keyboard for unit test.
*/
public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder<Key> {
- // Comparator to sort {@link Key}s from top-left to bottom-right order.
- private static final Comparator<Key> ROW_COLUMN_COMPARATOR = new Comparator<Key>() {
- @Override
- public int compare(final Key lhs, final Key rhs) {
- if (lhs.getY() < rhs.getY()) return -1;
- if (lhs.getY() > rhs.getY()) return 1;
- if (lhs.getX() < rhs.getX()) return -1;
- if (lhs.getX() > rhs.getX()) return 1;
- return 0;
- }
- };
-
- private static ArrayList<Key> filterOutSpacerAndSortKeys(final List<Key> keys) {
+ private static ArrayList<Key> filterOutSpacer(final List<Key> keys) {
final ArrayList<Key> filteredKeys = CollectionUtils.newArrayList();
for (final Key key : keys) {
if (key.isSpacer()) {
@@ -52,25 +38,23 @@ public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder<Key> {
}
filteredKeys.add(key);
}
- Collections.sort(filteredKeys, ROW_COLUMN_COMPARATOR);
return filteredKeys;
}
/**
* Create the keyboard that consists of the array of rows of the actual keyboard's keys.
- * @param keys the list of keys of the actual keyboard.
+ * @param sortedKeys the sorted list of keys of the actual keyboard.
* @return the actual keyboard grouped with rows.
*/
- public static Key[][] buildKeyboard(final List<Key> keys) {
- // Filter out spacer and sort keys from top-left to bottom-right order to prepare to
- // create rows.
- final ArrayList<Key> sortedKeys = filterOutSpacerAndSortKeys(keys);
+ public static Key[][] buildKeyboard(final List<Key> sortedKeys) {
+ // Filter out spacer to prepare to create rows.
+ final ArrayList<Key> filteredSortedKeys = filterOutSpacer(sortedKeys);
// Grouping keys into rows.
final ArrayList<ArrayList<Key>> rows = CollectionUtils.newArrayList();
ArrayList<Key> elements = CollectionUtils.newArrayList();
- int lastY = sortedKeys.get(0).getY();
- for (final Key key : sortedKeys) {
+ int lastY = filteredSortedKeys.get(0).getY();
+ for (final Key key : filteredSortedKeys) {
if (lastY != key.getY()) {
// A new row is starting.
lastY = key.getY();
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java
index 555ec8971..4002c49c2 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java
@@ -150,7 +150,8 @@ abstract class LayoutTestsBase extends KeyboardLayoutSetTestsBase {
// Create actual keyboard object.
final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(elementId);
// Create actual keyboard to be compared with the expected keyboard.
- final Key[][] actualKeyboard = ActualKeyboardBuilder.buildKeyboard(keyboard.getKeys());
+ final Key[][] actualKeyboard = ActualKeyboardBuilder.buildKeyboard(
+ keyboard.getSortedKeys());
// Dump human readable definition of expected/actual keyboards.
Log.d(tag, "expected=\n" + ExpectedKeyboardBuilder.toString(expectedKeyboard));