1 package com.hughes.android.dictionary;
\r
3 import java.io.IOException;
\r
4 import java.io.RandomAccessFile;
\r
5 import java.util.LinkedHashSet;
\r
6 import java.util.Set;
\r
8 import junit.framework.TestCase;
\r
10 import com.hughes.android.dictionary.Index.Node;
\r
11 import com.hughes.util.FileUtil;
\r
13 public class IndexTest extends TestCase {
\r
15 static final String file = "c:\\dict-de-en.txt";
\r
16 static final String file_index = file + "_index_0";
\r
18 public void testRoot() throws IOException {
\r
19 System.out.println(" testRoot");
\r
20 final Index index = new Index(file_index);
\r
21 final Node node = index.lookup("");
\r
22 assertNotNull(node);
\r
24 assertEquals(312220, node.descendantTokenCount);
\r
25 assertEquals(1087063, node.descendantEntryCount);
\r
27 for (final String token : node.tokenToOffsets.keySet()) {
\r
28 System.out.println(token);
\r
29 assertTrue(token.toLowerCase().contains("handhubwagen"));
\r
33 public void testLookup() throws IOException {
\r
34 System.out.println(" testLookup");
\r
35 final Index index = new Index(file_index);
\r
36 final Node node = index.lookup("handhubwagen");
\r
37 assertNotNull(node);
\r
39 assertEquals(1, node.descendantTokenCount);
\r
40 assertEquals(2, node.descendantEntryCount);
\r
42 for (final String token : node.tokenToOffsets.keySet()) {
\r
43 System.out.println(token);
\r
44 assertTrue(token.toLowerCase().contains("handhubwagen"));
\r
48 public void testGetDescendantOffsets() throws IOException {
\r
49 System.out.println(" testGetDescendantOffsets");
\r
50 final Index index = new Index(file_index);
\r
52 final Node node = index.lookup("handhebe");
\r
53 assertNotNull(node);
\r
54 assertEquals("handhebel", node.nodeHandle.normalizedToken);
\r
55 final Set<Integer> offsets = new LinkedHashSet<Integer>();
\r
56 node.getDescendantEntryOffsets(offsets, 10);
\r
57 final RandomAccessFile raf = new RandomAccessFile(file, "r");
\r
58 for (final Integer offset : offsets) {
\r
59 final String entry = FileUtil.readLine(raf, offset);
\r
60 System.out.println(entry);
\r
61 assertTrue(entry.toLowerCase().contains(node.nodeHandle.normalizedToken));
\r
65 public void testGetDescendants() throws IOException {
\r
66 System.out.println(" testGetDescendant");
\r
67 final Index index = new Index(file_index);
\r
68 final RandomAccessFile raf = new RandomAccessFile(file, "r");
\r
69 for (int i = 1000000; i < 1000050; ++i) {
\r
70 final Object o = index.root.getDescendant(i);
\r
71 if (o instanceof Integer) {
\r
72 System.out.println(" " + FileUtil.readLine(raf, (Integer)o));
\r
74 System.out.println(o);
\r