]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/IndexTest.java
go
[DictionaryPC.git] / src / com / hughes / android / dictionary / IndexTest.java
1 package com.hughes.android.dictionary;\r
2 \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
7 \r
8 import junit.framework.TestCase;\r
9 \r
10 import com.hughes.android.dictionary.Index.Node;\r
11 import com.hughes.util.FileUtil;\r
12 \r
13 public class IndexTest extends TestCase {\r
14 \r
15   static final String file = "c:\\dict-de-en.txt";\r
16   static final String file_index = file + "_index_0";\r
17   \r
18   public void testLookup() throws IOException {\r
19     System.out.println("testLookup");\r
20     final Index index = new Index(file_index);\r
21     final Node node = index.lookup("handhubwagen");\r
22     assertNotNull(node);\r
23     \r
24     final RandomAccessFile raf = new RandomAccessFile(file, "r");\r
25     for (int i = 0; i < node.offsets.length; ++i) {\r
26       final String entry = FileUtil.readLine(raf, node.offsets[i]);\r
27       System.out.println(entry);\r
28       assertTrue(entry.toLowerCase().contains("handhubwagen"));\r
29     }\r
30   }\r
31 \r
32   public void testGetDescendantOffsets() throws IOException {\r
33     System.out.println("testGetDescendantOffsets");\r
34     final Index index = new Index(file_index);\r
35     \r
36     final Node node = index.lookup("handhebe");\r
37     assertNotNull(node);\r
38     assertEquals("handhebel", node.text);\r
39     final Set<Integer> offsets = new LinkedHashSet<Integer>();\r
40     node.getDescendantEntryOffsets(offsets, 10);\r
41     final RandomAccessFile raf = new RandomAccessFile(file, "r");\r
42     for (final Integer offset : offsets) {\r
43       final String entry = FileUtil.readLine(raf, offset);\r
44       System.out.println(entry);\r
45       assertTrue(entry.toLowerCase().contains(node.text));\r
46     }\r
47   }\r
48 \r
49 }\r