diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java
index 012fd811c251202e453078d6a97923dbeb5eecb8..c47190190db600d9e6912dc6511cfe2eb9b3c1f0 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java
@@ -100,7 +100,10 @@ public class Ver2DictEncoder implements DictEncoder {
         Collections.sort(codePointOccurrenceArray, new Comparator<Entry<Integer, Integer>>() {
             @Override
             public int compare(final Entry<Integer, Integer> a, final Entry<Integer, Integer> b) {
-                return b.getValue().compareTo(a.getValue());
+                if (a.getValue() != b.getValue()) {
+                    return b.getValue().compareTo(a.getValue());
+                }
+                return b.getKey().compareTo(a.getKey());
             }
         });
         int currentCodePointTableIndex = FormatSpec.MINIMAL_ONE_BYTE_CHARACTER_VALUE;
diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoderTests.java
index 7c0b92dc3a6a1086b21f9a5f43978ee822103356..9104c2fcb7a830df845ae11ac5c698bfc1500938 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoderTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoderTests.java
@@ -42,8 +42,8 @@ public class Ver2DictEncoderTests extends AndroidTestCase {
         final List<String> words = Arrays.asList(wordSource);
         final String correctCodePointTable = "eotdsanirfg bclwup";
         final String correctCodePointOccurrenceArrayString =
-                "10141164111411531003110297210521142103111911171108198199132111211021";
-        final String correctCodePointExpectedMapString = "323433363538373940494147454644424348";
+                "11641114101411531003114211021052972119111711121108110311021991981321";
+        final String correctCodePointExpectedMapString = "343332363540383937464549484744414243";
         final String dictName = "codePointTableTest";
         final String dictVersion = Long.toString(System.currentTimeMillis());
 
@@ -60,8 +60,8 @@ public class Ver2DictEncoderTests extends AndroidTestCase {
             codePointOccurrenceArrayString.append(entry.getKey());
             codePointOccurrenceArrayString.append(entry.getValue());
         }
-        assertEquals(codePointOccurrenceArrayString.toString(),
-                correctCodePointOccurrenceArrayString);
+        assertEquals(correctCodePointOccurrenceArrayString,
+                codePointOccurrenceArrayString.toString());
 
         // Check if mCodePointToOneByteCodeMap is correct
         final StringBuilder codePointExpectedMapString = new StringBuilder();
@@ -69,7 +69,7 @@ public class Ver2DictEncoderTests extends AndroidTestCase {
             codePointExpectedMapString.append(codePointTable.mCodePointToOneByteCodeMap.get(
                     correctCodePointTable.codePointAt(i)));
         }
-        assertEquals(codePointExpectedMapString.toString(), correctCodePointExpectedMapString);
+        assertEquals(correctCodePointExpectedMapString, codePointExpectedMapString.toString());
     }
 
     /**