01: package org.openrdf.sail.rdbms.schema;
02:
03: import java.util.Arrays;
04:
05: import org.openrdf.model.impl.URIImpl;
06:
07: import junit.framework.TestCase;
08:
09: public class LongIdSequenceTest extends TestCase {
10: private IdSequence ids;
11: private long STEP;
12:
13: public void testStep() throws Exception {
14: assertEquals("0", Long.toBinaryString(0l));
15: assertEquals(x60('1'), Long.toBinaryString(STEP - 1));
16: assertEquals("1" + x60('0'), Long.toBinaryString(STEP));
17: assertEquals("10" + x60('0'), Long.toBinaryString(STEP * 2));
18: }
19:
20: public void testMinMax() throws Exception {
21: for (ValueType code : ValueType.values()) {
22: assertTrue(ids.minId(code).longValue() < ids.maxId(code)
23: .longValue());
24: }
25: }
26:
27: public void testDecode() throws Exception {
28: for (ValueType code : ValueType.values()) {
29: assertEquals(code, ids.valueOf(ids.minId(code)));
30: assertEquals(code, ids
31: .valueOf(ids.minId(code).longValue() + 1));
32: assertEquals(code, ids.valueOf(ids.maxId(code)));
33: assertEquals(code, ids
34: .valueOf(ids.maxId(code).longValue() - 1));
35: }
36: }
37:
38: public void testMin() throws Exception {
39: for (ValueType code : ValueType.values()) {
40: String min = Long.toBinaryString(ids.minId(code)
41: .longValue());
42: if (ids.minId(code).longValue() == 0) {
43: assertEquals("0", min);
44: } else {
45: assertEquals(x60('0'), min.substring(min.length() - 60));
46: }
47: }
48: }
49:
50: public void testMax() throws Exception {
51: for (ValueType code : ValueType.values()) {
52: String max = Long.toBinaryString(ids.maxId(code)
53: .longValue());
54: assertEquals(x60('1'), max.substring(max.length() - 60));
55: }
56: }
57:
58: public void testEncode() throws Exception {
59: assertEquals(ValueType.URI, ids.valueOf(ids.hashOf(new URIImpl(
60: "urn:root"))));
61: assertEquals(ValueType.URI, ids.valueOf(ids.hashOf(new URIImpl(
62: "urn:The quick brown fox jumps over the lazy dog"))));
63: }
64:
65: @Override
66: protected void setUp() throws Exception {
67: ids = new LongIdSequence();
68: ids.init();
69: STEP = ids.minId(ValueType.values()[1]).longValue();
70: }
71:
72: @Override
73: protected void tearDown() throws Exception {
74: }
75:
76: private String x60(char c) {
77: char[] a = new char[60];
78: Arrays.fill(a, 0, a.length, c);
79: return new String(a);
80: }
81: }
|