/[xulu]/trunk/src/appl/parallel/test/SplitMapTest.java
ViewVC logotype

Contents of /trunk/src/appl/parallel/test/SplitMapTest.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Wed Feb 25 11:54:01 2009 UTC (15 years, 9 months ago) by mojays
File size: 6024 byte(s)
First Commit, corresponds to Revision 1008 of Wikisquare-SVN 
1 package appl.parallel.test;
2
3 import java.awt.Rectangle;
4 import java.io.File;
5 import java.io.FileInputStream;
6
7
8 import junit.framework.Test;
9 import junit.framework.TestCase;
10 import junit.framework.TestSuite;
11
12 import appl.parallel.data.splittable.SplittableGridLLFactory;
13 import appl.parallel.data.splittable.SplittableLLProxyGrid;
14 import appl.parallel.spmd.split.AbstractSplitMap;
15 import appl.parallel.spmd.split.SplitMap;
16 import appl.parallel.spmd.split.SplitMap1DHorizontal;
17 import appl.parallel.spmd.split.SplitMap1DVertical;
18 import appl.parallel.spmd.split.SplitMap2D;
19 import appl.parallel.util.Helper;
20 import appl.util.GeneralUtil;
21 import appl.util.RasterMetaData;
22 import appl.util.RasterUtil;
23
24 import schmitzm.data.WritableGrid;
25 import schmitzm.data.WritableGridRaster;
26 import schmitzm.geotools.io.GeoImportUtil;
27
28 /**
29 * Generated code for the test suite <b>SplitMapTest</b> located at
30 * <i>/XuluSVN/javasrc/appl/parallel/test/SplitMapTest.testsuite</i>.
31 *
32 * Tests different splitmaps
33 */
34 public class SplitMapTest extends TestCase {
35
36 Rectangle globalCalcBounds;
37
38 Rectangle partitionCalcBounds;
39
40 Rectangle partitionNeighborhoodBounds;
41
42 Rectangle globalNeighborhoodBounds;
43
44 Rectangle localCalcBounds;
45
46 Rectangle localNeighborhoodBounds;
47
48 private SplittableLLProxyGrid baseGrid;
49
50 private SplitMap map;
51
52 /**
53 * Constructor for SplitMapTest.
54 * @param name
55 */
56 public SplitMapTest(String name) {
57 super(name);
58 }
59
60 /**
61 * Returns the JUnit test suite that implements the <b>SplitMapTest</b>
62 * definition.
63 */
64 public static Test suite() {
65 TestSuite splitMapTest = new TestSuite("SplitMapTest");
66 // splitMapTest.setArbiter(DefaultTestArbiter.INSTANCE).setId(
67 // "D35DB07792EF13413F23D9D0B19111DB");
68 //
69 // splitMapTest.addTest(new SplitMapTest("test1DSplitMap").setId(
70 // "D35DB07792EF134149AEAC40B19111DB").setTestInvocationId(
71 // "D35DB07792EF134168064FE0B19111DB"));
72 return splitMapTest;
73 }
74
75 /**
76 * @see junit.framework.TestCase#setUp()
77 */
78 protected void setUp() throws Exception {
79 // load a very simple 10x10 Grid
80 WritableGrid loadGrid = GeoImportUtil
81 .readGridRasterFromArcInfoASCII(new File(
82 "../Xulu-Data/regularGrid.arc"));
83 baseGrid = new SplittableLLProxyGrid(new RasterMetaData(loadGrid),2);
84 RasterUtil.copyInto(loadGrid, baseGrid);
85 //RasterUtil.printGrid(baseGrid, "Base grid");
86 }
87
88 /**
89 * @see junit.framework.TestCase#tearDown()
90 */
91 protected void tearDown() throws Exception {
92 }
93
94 public void basicTest() {
95 //make simply 2 Partitions without neighborhood
96 map.makeMap();
97 //check first partition
98 initVariables(map, 0);
99 assertEquals(new Rectangle(0, 0, 10, 10), globalCalcBounds);
100 assertEquals(new Rectangle(0, 0, 10, 10), globalNeighborhoodBounds);
101 assertEquals(new Rectangle(0, 0, 5, 10), partitionCalcBounds);
102 assertEquals(new Rectangle(0, 0, 5, 10), partitionNeighborhoodBounds);
103 assertEquals(new Rectangle(0, 0, 5, 10), localCalcBounds);
104 assertEquals(new Rectangle(0, 0, 5, 10), localNeighborhoodBounds);
105 //check second partition
106 initVariables(map, 1);
107 assertEquals(globalCalcBounds, new Rectangle(0, 0, 10, 10));
108 assertEquals(globalNeighborhoodBounds, new Rectangle(0, 0, 10, 10));
109 assertEquals(partitionCalcBounds, new Rectangle(5, 0, 5, 10));
110 assertEquals(partitionNeighborhoodBounds, new Rectangle(5, 0, 5, 10));
111 assertEquals(localCalcBounds, new Rectangle(0, 0, 5, 10));
112 assertEquals(localNeighborhoodBounds, new Rectangle(0, 0, 5, 10));
113 }
114
115 public void test1DHorizontal() {
116 //2 Partitions
117 map = new SplitMap1DHorizontal(baseGrid.getWidth(), baseGrid.getHeight(),
118 1, 2, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing);
119
120
121
122 map = new SplitMap1DHorizontal(baseGrid.getWidth(), baseGrid.getHeight(),
123 1, 3, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing);
124
125
126 }
127
128 public void print(){
129 for(int i=0; i < map.getCount(); i++){
130 RasterUtil.printGrid(baseGrid.getPartition(map.getPartitionCalculationBounds(i)),3,0,"Calculation Partition " + (i+1) + "/" + map.getCount());
131 }
132 for(int i=0; i < map.getCount(); i++){
133 RasterUtil.printGrid(baseGrid.getPartition(map.getPartitionNeighborhoodBounds(i)),3,0,"Neighborhood Partition " + (i+1) + "/" + map.getCount());
134 }
135 }
136
137 public void test2DIrregular(){
138 // map = new SplitMap2D(10, 10,
139 // 1, 3, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing);
140
141 map = new SplitMap2D(baseGrid.getWidth(), baseGrid.getHeight(),
142 1, 9, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing);
143 print();
144 }
145
146 /**
147 * 1DSplitMap
148 * @throws Exception
149 */
150 public void test1DVertical() throws Exception {
151 //2 Partitions
152 map = new SplitMap1DVertical(baseGrid.getWidth(), baseGrid.getHeight(),
153 0, 2, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing);
154 basicTest();
155 //make 3 Partitions
156 map = new SplitMap1DVertical(baseGrid.getWidth(), baseGrid.getHeight(),
157 0, 3, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing);
158
159 //make 2 Partitions with neighborhoodrange 2
160 map = new SplitMap1DVertical(baseGrid.getWidth(), baseGrid.getHeight(),
161 2, 2, AbstractSplitMap.NeighborhoodBoxingMode.inBoxing);
162 //intersect the partitions and see if you have the right rect
163
164 Rectangle r = map.getPartitionNeighborhoodBounds(0).intersection(
165 map.getPartitionNeighborhoodBounds(1));
166 assertEquals(new Rectangle(3, 0, 4, 10), r);
167
168 initVariables(map, 1);
169 }
170
171 /**
172 * @param map
173 */
174 private void initVariables(SplitMap map, int pos) {
175 globalCalcBounds = map.getGlobalCalculationBounds();
176 partitionCalcBounds = map.getPartitionCalculationBounds(pos);
177 partitionNeighborhoodBounds = map.getPartitionNeighborhoodBounds(pos);
178 globalNeighborhoodBounds = map.getGlobalBounds();
179 localCalcBounds = map.getLocalCalculationBounds(pos);
180 localNeighborhoodBounds = map.getLocalNeighborhoodBounds(pos);
181
182 }
183
184 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26