]> gitweb.fperrin.net Git - DictionaryPC.git/commitdiff
go
authorThad Hughes <thad.hughes@gmail.com>
Tue, 12 Oct 2010 18:38:09 +0000 (11:38 -0700)
committerThad Hughes <thad.hughes@gmail.com>
Tue, 13 Dec 2011 01:29:17 +0000 (17:29 -0800)
src/com/hughes/android/dictionary/engine/DictionaryTest.java [new file with mode: 0644]

diff --git a/src/com/hughes/android/dictionary/engine/DictionaryTest.java b/src/com/hughes/android/dictionary/engine/DictionaryTest.java
new file mode 100644 (file)
index 0000000..59bb031
--- /dev/null
@@ -0,0 +1,83 @@
+package com.hughes.android.dictionary.engine;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import junit.framework.TestCase;
+
+public class DictionaryTest extends TestCase {
+  
+  RandomAccessFile raf;
+  Dictionary dict;
+  Index deIndex; 
+  
+  @Override
+  public void setUp() {
+    try {
+      raf = new RandomAccessFile("testdata/de_en.dict", "r");
+      dict = new Dictionary(raf);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+
+    deIndex = dict.indices.get(0);
+}
+  
+  @Override
+  public void tearDown() {
+    try {
+      raf.close();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+  
+
+  public void testGermanMetadata() throws IOException {
+    assertEquals("de", deIndex.shortName);
+    assertEquals("de->en", deIndex.longName);
+  }
+  
+  public void testGermanIndex() throws IOException {
+    for (final Index.IndexEntry indexEntry : deIndex.sortedIndexEntries) {
+      System.out.println("testing: " + indexEntry.token);
+      final TokenRow row = deIndex.find(indexEntry.token, new AtomicBoolean(
+          false));
+      assertEquals(indexEntry.token.toLowerCase(), row.getToken().toLowerCase());
+    }
+
+    assertEquals("aaac", deIndex.find("AAAC", new AtomicBoolean(false)).getToken());
+    assertEquals("aaac", deIndex.find("aaac", new AtomicBoolean(false)).getToken());
+    assertEquals("aaac", deIndex.find("AAAc", new AtomicBoolean(false)).getToken());
+    assertEquals("aaac", deIndex.find("aaac", new AtomicBoolean(false)).getToken());
+  }
+  
+  public void testGermanTokenRows() {
+    // Pre-cache a few of these, just to make sure that's working.
+    for (int i = 0; i < deIndex.rows.size(); i += 7) {
+      deIndex.rows.get(i).getTokenRow(true);
+    }
+    
+    // Do the exhaustive searching.
+    TokenRow lastTokenRow = null;
+    for (final RowBase row : deIndex.rows) {
+      if (row instanceof TokenRow) {
+        lastTokenRow = (TokenRow) row;
+      }
+      assertEquals(lastTokenRow, row.getTokenRow(true));
+    }
+
+    // Now they're all cached, we shouldn't have to search.
+    for (final RowBase row : deIndex.rows) {
+      if (row instanceof TokenRow) {
+        lastTokenRow = (TokenRow) row;
+      }
+      // This will break if the Row cache isn't big enough.
+      assertEquals(lastTokenRow, row.getTokenRow(false));
+    }
+
+  }
+
+
+}