1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.eos.trie;
17
18 import java.util.HashMap;
19 import java.util.Map;
20 import java.util.Map.Entry;
21
22 import org.junit.Test;
23 import static org.junit.Assert.assertEquals;
24
25
26 public class ByteArrayKeyAnalyzerTest {
27
28 @Test
29 public void byteArrayTest() {
30 final PatriciaTrie<byte[], Integer> trie =
31 new PatriciaTrie<byte[], Integer>(new ByteArrayKeyAnalyzer());
32 final Map<Integer, byte[]> testMap = new HashMap<Integer, byte[]>();
33 int i = 0;
34 for (byte b1 = Byte.MIN_VALUE; b1 < Byte.MAX_VALUE; b1++) {
35 for (byte b2 = Byte.MIN_VALUE; b2 < Byte.MAX_VALUE; b2++, i++) {
36 final byte[] array = new byte[] {b1, b2};
37 trie.put(array, i);
38 testMap.put(i, array);
39 }
40 i++;
41 final byte[] array = new byte[] {b1, Byte.MAX_VALUE};
42 trie.put(array, i);
43 testMap.put(i, array);
44 }
45 for (byte b2 = Byte.MIN_VALUE; b2 < Byte.MAX_VALUE; b2++, i++) {
46 final byte[] array = new byte[] {Byte.MAX_VALUE, b2};
47 trie.put(array, i);
48 testMap.put(i, array);
49 }
50 i++;
51 final byte[] array = new byte[] {Byte.MAX_VALUE, Byte.MAX_VALUE};
52 trie.put(array, i);
53 testMap.put(i, array);
54
55
56
57 int count = 0;
58 for (final Entry<Integer, byte[]> e : testMap.entrySet()) {
59 final byte[] key = e.getValue();
60 final Integer value = e.getKey();
61 System.out.println("count: " + count);
62 count++;
63 assertEquals(value, trie.get(key));
64 }
65 }
66 }