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