01: package org.compass.gps.device.support.parallel;
02:
03: import junit.framework.TestCase;
04:
05: /**
06: * @author kimchy
07: */
08: public class SubIndexIndexEntitiesPartitionerTests extends TestCase {
09:
10: public class MockIndexEntity implements IndexEntity {
11:
12: private String[] subIndexes;
13:
14: public MockIndexEntity(String[] subIndexes) {
15: this .subIndexes = subIndexes;
16: }
17:
18: public String[] getSubIndexes() {
19: return subIndexes;
20: }
21:
22: public String getName() {
23: return "";
24: }
25: }
26:
27: public void testSimplePartition() throws Exception {
28: IndexEntity[] entities = new IndexEntity[] {
29: new MockIndexEntity(new String[] { "a", "b" }),
30: new MockIndexEntity(new String[] { "c", "d" }) };
31: SubIndexIndexEntitiesPartitioner partitioner = new SubIndexIndexEntitiesPartitioner();
32: IndexEntity[][] parEnt = partitioner.partition(entities);
33: assertEquals(2, parEnt.length);
34: }
35:
36: public void testSamePartition() throws Exception {
37: IndexEntity[] entities = new IndexEntity[] {
38: new MockIndexEntity(new String[] { "a", "b" }),
39: new MockIndexEntity(new String[] { "a", "b" }) };
40: SubIndexIndexEntitiesPartitioner partitioner = new SubIndexIndexEntitiesPartitioner();
41: IndexEntity[][] parEnt = partitioner.partition(entities);
42: assertEquals(1, parEnt.length);
43: }
44:
45: public void testJoinedPartition() throws Exception {
46: IndexEntity[] entities = new IndexEntity[] {
47: new MockIndexEntity(new String[] { "a", "b" }),
48: new MockIndexEntity(new String[] { "b", "c" }),
49: new MockIndexEntity(new String[] { "d", "c" }) };
50: SubIndexIndexEntitiesPartitioner partitioner = new SubIndexIndexEntitiesPartitioner();
51: IndexEntity[][] parEnt = partitioner.partition(entities);
52: assertEquals(1, parEnt.length);
53: assertEquals(3, parEnt[0].length);
54: }
55:
56: public void testJoinedPartitionAndOneWithoutAtTheEnd()
57: throws Exception {
58: IndexEntity[] entities = new IndexEntity[] {
59: new MockIndexEntity(new String[] { "a", "b" }),
60: new MockIndexEntity(new String[] { "b", "c" }),
61: new MockIndexEntity(new String[] { "d", "c" }),
62: new MockIndexEntity(new String[] { "e", "f" }) };
63: SubIndexIndexEntitiesPartitioner partitioner = new SubIndexIndexEntitiesPartitioner();
64: IndexEntity[][] parEnt = partitioner.partition(entities);
65: assertEquals(2, parEnt.length);
66: assertEquals(3, parEnt[0].length);
67: assertEquals(1, parEnt[1].length);
68: }
69:
70: public void testJoinedPartitionAndOneWithoutAtTheBeginning()
71: throws Exception {
72: IndexEntity[] entities = new IndexEntity[] {
73: new MockIndexEntity(new String[] { "x", "y" }),
74: new MockIndexEntity(new String[] { "a", "b" }),
75: new MockIndexEntity(new String[] { "b", "c" }),
76: new MockIndexEntity(new String[] { "d", "c" }),
77: new MockIndexEntity(new String[] { "e", "f" }) };
78: SubIndexIndexEntitiesPartitioner partitioner = new SubIndexIndexEntitiesPartitioner();
79: IndexEntity[][] parEnt = partitioner.partition(entities);
80: assertEquals(3, parEnt.length);
81: assertEquals(1, parEnt[0].length);
82: assertEquals(3, parEnt[1].length);
83: assertEquals(1, parEnt[2].length);
84: }
85:
86: }
|