From 749687bc77b2daf14d7a537b6f73073062e5d9f6 Mon Sep 17 00:00:00 2001 From: Thad Hughes Date: Tue, 12 Oct 2010 11:38:09 -0700 Subject: [PATCH] go --- .../dictionary/engine/DictionaryTest.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/com/hughes/android/dictionary/engine/DictionaryTest.java diff --git a/src/com/hughes/android/dictionary/engine/DictionaryTest.java b/src/com/hughes/android/dictionary/engine/DictionaryTest.java new file mode 100644 index 0000000..59bb031 --- /dev/null +++ b/src/com/hughes/android/dictionary/engine/DictionaryTest.java @@ -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)); + } + + } + + +} -- 2.43.0