Partitioner partitioner = new SimplePartitioner();
IntBox[] partitions = partitioner.partition(NUM_CELLS_X_SPC, NUM_CELLS_Y_SPC, NUM_PARTITIONS_SPC);
IntBox globalSimulation = new IntBox(0, NUM_CELLS_X_SPC - 1, 0, NUM_CELLS_Y_SPC - 1);
int myPartID = 0;
NeighborMap neighborMap = new NeighborMap(
myPartID, partitions, globalSimulation, GeneralBoundaryType.Hardwall);
// Test boundary corner regions
int region = BoundaryRegions.X_MIN + BoundaryRegions.Y_MIN;
int neighbor = neighborMap.getBoundaryNeighbor(region);
Assert.assertEquals(NeighborMap.NO_NEIGHBOR, neighbor);
Point direction = neighborMap.getBoundaryNeighborsDirections(region);
Assert.assertNull(direction);
region = BoundaryRegions.X_MAX + BoundaryRegions.Y_MAX;
neighbor = neighborMap.getBoundaryNeighbor(region);
Assert.assertEquals(3, neighbor);
direction = neighborMap.getBoundaryNeighborsDirections(region);
Assert.assertEquals(new Point(1, 1), direction);
region = BoundaryRegions.X_MIN + BoundaryRegions.Y_MAX;
neighbor = neighborMap.getBoundaryNeighbor(region);
Assert.assertEquals(1, neighbor);
direction = neighborMap.getBoundaryNeighborsDirections(region);
Assert.assertEquals(new Point(0, 1), direction);
// Test boundary edge regions
region = BoundaryRegions.X_MIN + BoundaryRegions.Y_CENTER;
neighbor = neighborMap.getBoundaryNeighbor(region);
Assert.assertEquals(NeighborMap.NO_NEIGHBOR, neighbor);
direction = neighborMap.getBoundaryNeighborsDirections(region);
Assert.assertNull(direction);
region = BoundaryRegions.X_MAX + BoundaryRegions.Y_CENTER;
neighbor = neighborMap.getBoundaryNeighbor(region);
Assert.assertEquals(2, neighbor);
direction = neighborMap.getBoundaryNeighborsDirections(region);
Assert.assertEquals(new Point(1, 0), direction);
region = BoundaryRegions.X_CENTER + BoundaryRegions.Y_MAX;
neighbor = neighborMap.getBoundaryNeighbor(region);
Assert.assertEquals(1, neighbor);
direction = neighborMap.getBoundaryNeighborsDirections(region);
Assert.assertEquals(new Point(0, 1), direction);
// Test border corner regions
region = BorderRegions.X_BORDER_MIN + BorderRegions.Y_BORDER_MAX;
int[] neighbors = neighborMap.getBorderNeighbors(region);
int on1 = assertContains(neighbors, 1);
assertContains(neighbors, NeighborMap.NO_NEIGHBOR);
Point[] directions = neighborMap.getBorderNeighborsDirections(region);
int od1 = assertContainsPoint(directions, new Point(0, 1));
// Test order
Assert.assertEquals(on1, od1);
region = BorderRegions.X_BORDER_MAX + BorderRegions.Y_BORDER_MAX;
neighbors = neighborMap.getBorderNeighbors(region);
on1 = assertContains(neighbors, 1);
int on2 = assertContains(neighbors, 2);
int on3 = assertContains(neighbors, 3);
directions = neighborMap.getBorderNeighborsDirections(region);
od1 = assertContainsPoint(directions, new Point(0, 1));
int od2 = assertContainsPoint(directions, new Point(1, 0));
int od3 = assertContainsPoint(directions, new Point(1, 1));
// Test order
Assert.assertEquals(on1, od1);
Assert.assertEquals(on2, od2);
Assert.assertEquals(on3, od3);
// Test border outside corner regions
region = BorderRegions.X_BORDER_MAX + BorderRegions.Y_BOUNDARY_MIN;
neighbors = neighborMap.getBorderNeighbors(region);
assertContains(neighbors, 2);
directions = neighborMap.getBorderNeighborsDirections(region);
assertContainsPoint(directions, new Point(1, 0));
region = BorderRegions.X_BOUNDARY_MAX + BorderRegions.Y_BORDER_MIN;
neighbors = neighborMap.getBorderNeighbors(region);
assertContains(neighbors, NeighborMap.NO_NEIGHBOR);
directions = neighborMap.getBorderNeighborsDirections(region);
Assert.assertEquals(1, directions.length);
Assert.assertNull(directions[0]);
// Test border edge regions
region = BorderRegions.X_CENTER + BorderRegions.Y_BORDER_MAX;
neighbors = neighborMap.getBorderNeighbors(region);
assertContains(neighbors, 1);
directions = neighborMap.getBorderNeighborsDirections(region);
assertContainsPoint(directions, new Point(0, 1));
region = BorderRegions.X_BORDER_MAX + BorderRegions.Y_CENTER;
neighbors = neighborMap.getBorderNeighbors(region);
assertContains(neighbors, 2);
directions = neighborMap.getBorderNeighborsDirections(region);
assertContainsPoint(directions, new Point(1, 0));
}