1 package com.hughes.android.dictionary.engine;
3 import java.io.IOException;
4 import java.io.RandomAccessFile;
5 import java.util.concurrent.atomic.AtomicBoolean;
7 import junit.framework.TestCase;
9 public class DictionaryTest extends TestCase {
18 raf = new RandomAccessFile("testdata/de_en.dict", "r");
19 dict = new Dictionary(raf);
20 } catch (IOException e) {
21 throw new RuntimeException(e);
24 deIndex = dict.indices.get(0);
28 public void tearDown() {
31 } catch (IOException e) {
32 throw new RuntimeException(e);
37 public void testGermanMetadata() throws IOException {
38 assertEquals("de", deIndex.shortName);
39 assertEquals("de->en", deIndex.longName);
42 public void testGermanIndex() throws IOException {
43 for (final Index.IndexEntry indexEntry : deIndex.sortedIndexEntries) {
44 System.out.println("testing: " + indexEntry.token);
45 final TokenRow row = deIndex.find(indexEntry.token, new AtomicBoolean(
47 assertEquals(indexEntry.token.toLowerCase(), row.getToken().toLowerCase());
50 assertEquals("aaac", deIndex.find("AAAC", new AtomicBoolean(false)).getToken());
51 assertEquals("aaac", deIndex.find("aaac", new AtomicBoolean(false)).getToken());
52 assertEquals("aaac", deIndex.find("AAAc", new AtomicBoolean(false)).getToken());
53 assertEquals("aaac", deIndex.find("aaac", new AtomicBoolean(false)).getToken());
56 public void testGermanTokenRows() {
57 // Pre-cache a few of these, just to make sure that's working.
58 for (int i = 0; i < deIndex.rows.size(); i += 7) {
59 deIndex.rows.get(i).getTokenRow(true);
62 // Do the exhaustive searching.
63 TokenRow lastTokenRow = null;
64 for (final RowBase row : deIndex.rows) {
65 if (row instanceof TokenRow) {
66 lastTokenRow = (TokenRow) row;
68 assertEquals(lastTokenRow, row.getTokenRow(true));
71 // Now they're all cached, we shouldn't have to search.
72 for (final RowBase row : deIndex.rows) {
73 if (row instanceof TokenRow) {
74 lastTokenRow = (TokenRow) row;
76 // This will break if the Row cache isn't big enough.
77 assertEquals(lastTokenRow, row.getTokenRow(false));