1   /* Copyright (c) 2008 Sascha Kohlmann
2    *
3    * This program is free software: you can redistribute it and/or modify
4    * it under the terms of the GNU Affero General Public License as published by
5    * the Free Software Foundation, either version 3 of the License, or
6    * (at your option) any later version.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Affero General Public License for more details.
12   *
13   * You should have received a copy of the GNU Affero General Public License
14   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
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  //        assertEquals(trie.size(), testMap.size());
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  }