1 package com.hughes.android.dictionary;
\r
4 import java.io.IOException;
\r
5 import java.io.RandomAccessFile;
\r
6 import java.util.Arrays;
\r
7 import java.util.List;
\r
9 import junit.framework.TestCase;
\r
11 import com.hughes.android.dictionary.Dictionary.IndexEntry;
\r
12 import com.hughes.android.dictionary.Dictionary.Row;
\r
14 public class DictionaryTest extends TestCase {
\r
16 public void testDictionary() throws IOException {
\r
17 final File file = File.createTempFile("asdf", "asdf");
\r
18 file.deleteOnExit();
\r
20 final Dictionary goldenDict;
\r
21 final List<Entry> entries = Arrays.asList(
\r
22 new Entry("der Hund", "the dog"),
\r
23 new Entry("Die grosse Katze", "The big cat"),
\r
24 new Entry("die Katze", "the cat"),
\r
25 new Entry("gross", "big"),
\r
26 new Entry("Dieb", "thief"),
\r
27 new Entry("rennen", "run"));
\r
30 final Dictionary dict = new Dictionary("de", "en");
\r
31 for (final Entry entry : entries) {
\r
32 dict.entries.add(entry);
\r
34 DictionaryBuilder.createIndex(dict, Entry.LANG1);
\r
35 DictionaryBuilder.createIndex(dict, Entry.LANG2);
\r
36 final RandomAccessFile raf = new RandomAccessFile(file, "rw");
\r
43 final RandomAccessFile raf = new RandomAccessFile(file, "r");
\r
44 final Dictionary dict = new Dictionary(raf);
\r
46 assertEquals(entries, dict.entries);
\r
48 assertEquals("der", dict.languages[0].sortedIndex.get(0).word);
\r
49 assertEquals("Die", dict.languages[0].sortedIndex.get(1).word);
\r
51 for (final IndexEntry indexEntry : dict.languages[0].sortedIndex) {
\r
52 System.out.println(indexEntry);
\r
56 for (final Row row : dict.languages[0].rows) {
\r
57 if (row.index >= 0) {
\r
58 System.out.println(" " + rowCount + ":" + dict.entries.get(row.index));
\r
60 System.out.println(rowCount + ":" + dict.languages[0].sortedIndex.get(-row.index - 1));
\r