2 **********************************************************************
3 * Copyright (c) 2011-2012, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * Created: April 8 - 2011
9 **********************************************************************
12 package com.ibm.icu.dev.test.util;
14 import java.util.List;
17 import com.ibm.icu.dev.test.TestFmwk;
18 import com.ibm.icu.util.Region;
19 import com.ibm.icu.util.Region.RegionType;
23 * @summary General test of Regions
26 public class RegionTest extends TestFmwk {
28 public static void main(String[] args) throws Exception {
29 new RegionTest().run(args);
32 String[][] knownRegions = {
33 // Code , Numeric , Parent, Type, Containing Continent
34 { "001", "001", null , "WORLD", null },
35 { "002", "002", "001", "CONTINENT", null },
36 { "003", "003", null, "GROUPING", null },
37 { "005", "005", "019", "SUBCONTINENT", "019" },
38 { "009", "009", "001", "CONTINENT", null},
39 { "011", "011", "002", "SUBCONTINENT", "002" },
40 { "013", "013", "019", "SUBCONTINENT", "019" },
41 { "014", "014", "002", "SUBCONTINENT", "002" },
42 { "015", "015", "002", "SUBCONTINENT", "002" },
43 { "017", "017", "002", "SUBCONTINENT", "002" },
44 { "018", "018", "002", "SUBCONTINENT", "002" },
45 { "019", "019", "001", "CONTINENT", null },
46 { "021", "021", "019", "SUBCONTINENT", "019" },
47 { "029", "029", "019", "SUBCONTINENT", "019" },
48 { "030", "030", "142", "SUBCONTINENT", "142" },
49 { "034", "034", "142", "SUBCONTINENT", "142" },
50 { "035", "035", "142", "SUBCONTINENT", "142" },
51 { "039", "039", "150", "SUBCONTINENT", "150"},
52 { "053", "053", "009", "SUBCONTINENT", "009" },
53 { "054", "054", "009", "SUBCONTINENT", "009" },
54 { "057", "057", "009", "SUBCONTINENT", "009" },
55 { "061", "061", "009", "SUBCONTINENT", "009" },
56 { "142", "142", "001", "CONTINENT", null },
57 { "143", "143", "142", "SUBCONTINENT", "142" },
58 { "145", "145", "142", "SUBCONTINENT", "142" },
59 { "150", "150", "001", "CONTINENT", null },
60 { "151", "151", "150", "SUBCONTINENT", "150" },
61 { "154", "154", "150", "SUBCONTINENT", "150" },
62 { "155", "155", "150", "SUBCONTINENT", "150" },
63 { "419", "419", null, "GROUPING" , null},
64 { "AC" , "-1" , "QO" , "TERRITORY", "009" },
65 { "AD" , "020", "039", "TERRITORY", "150" },
66 { "AE" , "784", "145", "TERRITORY", "142" },
67 { "AF" , "004", "034", "TERRITORY", "142" },
68 { "AG" , "028", "029", "TERRITORY", "019" },
69 { "AI" , "660", "029", "TERRITORY", "019" },
70 { "AL" , "008", "039", "TERRITORY", "150" },
71 { "AM" , "051", "145", "TERRITORY", "142" },
72 { "AN" , "530", null, "DEPRECATED", null },
73 { "AO" , "024", "017", "TERRITORY", "002" },
74 { "AQ" , "010", "QO" , "TERRITORY", "009" },
75 { "AR" , "032", "005", "TERRITORY", "019" },
76 { "AS" , "016", "061", "TERRITORY", "009" },
77 { "AT" , "040", "155", "TERRITORY", "150" },
78 { "AU" , "036", "053", "TERRITORY", "009" },
79 { "AW" , "533", "029", "TERRITORY", "019" },
80 { "AX" , "248", "154", "TERRITORY", "150" },
81 { "AZ" , "031", "145", "TERRITORY", "142" },
82 { "BA" , "070", "039", "TERRITORY", "150" },
83 { "BB" , "052", "029", "TERRITORY", "019" },
84 { "BD" , "050", "034", "TERRITORY", "142" },
85 { "BE" , "056", "155", "TERRITORY", "150" },
86 { "BF" , "854", "011", "TERRITORY", "002" },
87 { "BG" , "100", "151", "TERRITORY", "150" },
88 { "BH" , "048", "145", "TERRITORY", "142" },
89 { "BI" , "108", "014", "TERRITORY", "002" },
90 { "BJ" , "204", "011", "TERRITORY", "002" },
91 { "BL" , "652", "029", "TERRITORY", "019" },
92 { "BM" , "060", "021", "TERRITORY", "019" },
93 { "BN" , "096", "035", "TERRITORY", "142" },
94 { "BO" , "068", "005", "TERRITORY", "019" },
95 { "BQ" , "535", "029", "TERRITORY", "019" },
96 { "BR" , "076", "005", "TERRITORY", "019" },
97 { "BS" , "044", "029", "TERRITORY", "019" },
98 { "BT" , "064", "034", "TERRITORY", "142" },
99 { "BU" , "104", "035", "TERRITORY", "142" },
100 { "BV" , "074", "QO" , "TERRITORY", "009" },
101 { "BW" , "072", "018", "TERRITORY", "002" },
102 { "BY" , "112", "151", "TERRITORY", "150" },
103 { "BZ" , "084", "013", "TERRITORY", "019" },
104 { "CA" , "124", "021", "TERRITORY", "019" },
105 { "CC" , "166", "QO" , "TERRITORY", "009" },
106 { "CD" , "180", "017", "TERRITORY", "002" },
107 { "CF" , "140", "017", "TERRITORY", "002" },
108 { "CG" , "178", "017", "TERRITORY", "002" },
109 { "CH" , "756", "155", "TERRITORY", "150" },
110 { "CI" , "384", "011", "TERRITORY", "002" },
111 { "CK" , "184", "061", "TERRITORY", "009" },
112 { "CL" , "152", "005", "TERRITORY", "019" },
113 { "CM" , "120", "017", "TERRITORY", "002" },
114 { "CN" , "156", "030", "TERRITORY", "142" },
115 { "CO" , "170", "005", "TERRITORY", "019" },
116 { "CP" , "-1" , "QO" , "TERRITORY", "009" },
117 { "CR" , "188", "013", "TERRITORY", "019" },
118 { "CU" , "192", "029", "TERRITORY", "019" },
119 { "CV" , "132", "011", "TERRITORY", "002" },
120 { "CW" , "531", "029", "TERRITORY", "019" },
121 { "CX" , "162", "QO" , "TERRITORY", "009" },
122 { "CY" , "196", "145", "TERRITORY", "142" },
123 { "CZ" , "203", "151", "TERRITORY", "150" },
124 { "DD" , "276", "155", "TERRITORY", "150" },
125 { "DE" , "276", "155", "TERRITORY", "150" },
126 { "DG" , "-1" , "QO" , "TERRITORY", "009" },
127 { "DJ" , "262", "014", "TERRITORY", "002" },
128 { "DK" , "208", "154", "TERRITORY", "150" },
129 { "DM" , "212", "029", "TERRITORY", "019" },
130 { "DO" , "214", "029", "TERRITORY", "019" },
131 { "DZ" , "012", "015", "TERRITORY", "002" },
132 { "EA" , "-1" , "015", "TERRITORY", "002" },
133 { "EC" , "218", "005", "TERRITORY", "019" },
134 { "EE" , "233", "154", "TERRITORY", "150" },
135 { "EG" , "818", "015", "TERRITORY", "002" },
136 { "EH" , "732", "015", "TERRITORY", "002" },
137 { "ER" , "232", "014", "TERRITORY", "002" },
138 { "ES" , "724", "039", "TERRITORY", "150" },
139 { "ET" , "231", "014", "TERRITORY", "002" },
140 { "EU" , "967", null, "GROUPING", null },
141 { "FI" , "246", "154", "TERRITORY", "150" },
142 { "FJ" , "242", "054", "TERRITORY", "009" },
143 { "FK" , "238", "005", "TERRITORY", "019" },
144 { "FM" , "583", "057", "TERRITORY", "009" },
145 { "FO" , "234", "154", "TERRITORY", "150" },
146 { "FR" , "250", "155", "TERRITORY", "150" },
147 { "FX" , "250", "155", "TERRITORY", "150" },
148 { "GA" , "266", "017", "TERRITORY", "002" },
149 { "GB" , "826", "154", "TERRITORY", "150" },
150 { "GD" , "308", "029", "TERRITORY", "019" },
151 { "GE" , "268", "145", "TERRITORY", "142" },
152 { "GF" , "254", "005", "TERRITORY", "019" },
153 { "GG" , "831", "154", "TERRITORY", "150" },
154 { "GH" , "288", "011", "TERRITORY", "002" },
155 { "GI" , "292", "039", "TERRITORY", "150" },
156 { "GL" , "304", "021", "TERRITORY", "019" },
157 { "GM" , "270", "011", "TERRITORY", "002" },
158 { "GN" , "324", "011", "TERRITORY", "002" },
159 { "GP" , "312", "029", "TERRITORY", "019" },
160 { "GQ" , "226", "017", "TERRITORY", "002" },
161 { "GR" , "300", "039", "TERRITORY", "150" },
162 { "GS" , "239", "QO" , "TERRITORY", "009" },
163 { "GT" , "320", "013", "TERRITORY", "019" },
164 { "GU" , "316", "057", "TERRITORY", "009" },
165 { "GW" , "624", "011", "TERRITORY", "002" },
166 { "GY" , "328", "005", "TERRITORY", "019" },
167 { "HK" , "344", "030", "TERRITORY", "142" },
168 { "HM" , "334", "QO" , "TERRITORY", "009" },
169 { "HN" , "340", "013", "TERRITORY", "019" },
170 { "HR" , "191", "039", "TERRITORY", "150" },
171 { "HT" , "332", "029", "TERRITORY", "019" },
172 { "HU" , "348", "151", "TERRITORY", "150" },
173 { "IC" , "-1" , "015", "TERRITORY", "002" },
174 { "ID" , "360", "035", "TERRITORY", "142" },
175 { "IE" , "372", "154", "TERRITORY", "150" },
176 { "IL" , "376", "145", "TERRITORY", "142" },
177 { "IM" , "833", "154", "TERRITORY", "150" },
178 { "IN" , "356", "034", "TERRITORY", "142" },
179 { "IO" , "086", "QO" , "TERRITORY", "009" },
180 { "IQ" , "368", "145", "TERRITORY", "142" },
181 { "IR" , "364", "034", "TERRITORY", "142" },
182 { "IS" , "352", "154", "TERRITORY", "150" },
183 { "IT" , "380", "039", "TERRITORY", "150" },
184 { "JE" , "832", "154", "TERRITORY", "150" },
185 { "JM" , "388", "029", "TERRITORY", "019" },
186 { "JO" , "400", "145", "TERRITORY", "142" },
187 { "JP" , "392", "030", "TERRITORY", "142" },
188 { "KE" , "404", "014", "TERRITORY", "002" },
189 { "KG" , "417", "143", "TERRITORY", "142" },
190 { "KH" , "116", "035", "TERRITORY", "142" },
191 { "KI" , "296", "057", "TERRITORY", "009" },
192 { "KM" , "174", "014", "TERRITORY", "002" },
193 { "KN" , "659", "029", "TERRITORY", "019" },
194 { "KP" , "408", "030", "TERRITORY", "142" },
195 { "KR" , "410", "030", "TERRITORY", "142" },
196 { "KW" , "414", "145", "TERRITORY", "142" },
197 { "KY" , "136", "029", "TERRITORY", "019" },
198 { "KZ" , "398", "143", "TERRITORY", "142" },
199 { "LA" , "418", "035", "TERRITORY", "142" },
200 { "LB" , "422", "145", "TERRITORY", "142" },
201 { "LC" , "662", "029", "TERRITORY", "019" },
202 { "LI" , "438", "155", "TERRITORY", "150" },
203 { "LK" , "144", "034", "TERRITORY", "142" },
204 { "LR" , "430", "011", "TERRITORY", "002" },
205 { "LS" , "426", "018", "TERRITORY", "002" },
206 { "LT" , "440", "154", "TERRITORY", "150" },
207 { "LU" , "442", "155", "TERRITORY", "150" },
208 { "LV" , "428", "154", "TERRITORY", "150" },
209 { "LY" , "434", "015", "TERRITORY", "002" },
210 { "MA" , "504", "015", "TERRITORY", "002" },
211 { "MC" , "492", "155", "TERRITORY", "150" },
212 { "MD" , "498", "151", "TERRITORY", "150" },
213 { "ME" , "499", "039", "TERRITORY", "150" },
214 { "MF" , "663", "029", "TERRITORY", "019" },
215 { "MG" , "450", "014", "TERRITORY", "002" },
216 { "MH" , "584", "057", "TERRITORY", "009" },
217 { "MK" , "807", "039", "TERRITORY", "150" },
218 { "ML" , "466", "011", "TERRITORY", "002" },
219 { "MM" , "104", "035", "TERRITORY", "142" },
220 { "MN" , "496", "030", "TERRITORY", "142" },
221 { "MO" , "446", "030", "TERRITORY", "142" },
222 { "MP" , "580", "057", "TERRITORY", "009" },
223 { "MQ" , "474", "029", "TERRITORY", "019" },
224 { "MR" , "478", "011", "TERRITORY", "002" },
225 { "MS" , "500", "029", "TERRITORY", "019" },
226 { "MT" , "470", "039", "TERRITORY", "150" },
227 { "MU" , "480", "014", "TERRITORY", "002" },
228 { "MV" , "462", "034", "TERRITORY", "142" },
229 { "MW" , "454", "014", "TERRITORY", "002" },
230 { "MX" , "484", "013", "TERRITORY", "019"},
231 { "MY" , "458", "035", "TERRITORY", "142" },
232 { "MZ" , "508", "014", "TERRITORY", "002" },
233 { "NA" , "516", "018", "TERRITORY", "002" },
234 { "NC" , "540", "054", "TERRITORY", "009" },
235 { "NE" , "562", "011", "TERRITORY", "002" },
236 { "NF" , "574", "053", "TERRITORY", "009" },
237 { "NG" , "566", "011", "TERRITORY", "002" },
238 { "NI" , "558", "013", "TERRITORY", "019" },
239 { "NL" , "528", "155", "TERRITORY", "150" },
240 { "NO" , "578", "154", "TERRITORY", "150" },
241 { "NP" , "524", "034", "TERRITORY", "142" },
242 { "NR" , "520", "057", "TERRITORY", "009" },
243 { "NT" , "536", null , "DEPRECATED", null },
244 { "NU" , "570", "061", "TERRITORY", "009" },
245 { "NZ" , "554", "053", "TERRITORY", "009" },
246 { "OM" , "512", "145", "TERRITORY", "142" },
247 { "PA" , "591", "013", "TERRITORY", "019" },
248 { "PE" , "604", "005", "TERRITORY", "019" },
249 { "PF" , "258", "061", "TERRITORY", "009" },
250 { "PG" , "598", "054", "TERRITORY", "009" },
251 { "PH" , "608", "035", "TERRITORY", "142" },
252 { "PK" , "586", "034", "TERRITORY", "142" },
253 { "PL" , "616", "151", "TERRITORY", "150" },
254 { "PM" , "666", "021", "TERRITORY", "019" },
255 { "PN" , "612", "061", "TERRITORY", "009" },
256 { "PR" , "630", "029", "TERRITORY", "019" },
257 { "PS" , "275", "145", "TERRITORY", "142" },
258 { "PT" , "620", "039", "TERRITORY", "150" },
259 { "PW" , "585", "057", "TERRITORY", "009" },
260 { "PY" , "600", "005", "TERRITORY", "019" },
261 { "QA" , "634", "145", "TERRITORY", "142" },
262 { "QO" , "961", "009", "SUBCONTINENT", "009" },
263 { "QU" , "967", null, "GROUPING", null },
264 { "RE" , "638", "014", "TERRITORY", "002" },
265 { "RO" , "642", "151", "TERRITORY", "150" },
266 { "RS" , "688", "039", "TERRITORY", "150" },
267 { "RU" , "643", "151", "TERRITORY", "150" },
268 { "RW" , "646", "014", "TERRITORY", "002" },
269 { "SA" , "682", "145", "TERRITORY", "142" },
270 { "SB" , "090", "054", "TERRITORY", "009" },
271 { "SC" , "690", "014", "TERRITORY", "002" },
272 { "SD" , "729", "015", "TERRITORY", "002" },
273 { "SE" , "752", "154", "TERRITORY", "150" },
274 { "SG" , "702", "035", "TERRITORY", "142" },
275 { "SH" , "654", "011", "TERRITORY", "002" },
276 { "SI" , "705", "039", "TERRITORY", "150" },
277 { "SJ" , "744", "154", "TERRITORY", "150" },
278 { "SK" , "703", "151", "TERRITORY", "150" },
279 { "SL" , "694", "011", "TERRITORY", "002" },
280 { "SM" , "674", "039", "TERRITORY", "150" },
281 { "SN" , "686", "011", "TERRITORY", "002" },
282 { "SO" , "706", "014", "TERRITORY", "002" },
283 { "SR" , "740", "005", "TERRITORY", "019" },
284 { "SS" , "728", "015", "TERRITORY", "002" },
285 { "ST" , "678", "017", "TERRITORY", "002" },
286 { "SU" , "810", null , "DEPRECATED" , null},
287 { "SV" , "222", "013", "TERRITORY", "019" },
288 { "SX" , "534", "029", "TERRITORY", "019" },
289 { "SY" , "760", "145", "TERRITORY", "142" },
290 { "SZ" , "748", "018", "TERRITORY", "002" },
291 { "TA" , "-1" , "QO", "TERRITORY", "009" },
292 { "TC" , "796", "029", "TERRITORY", "019" },
293 { "TD" , "148", "017", "TERRITORY", "002" },
294 { "TF" , "260", "QO" , "TERRITORY", "009" },
295 { "TG" , "768", "011", "TERRITORY", "002" },
296 { "TH" , "764", "035", "TERRITORY", "142" },
297 { "TJ" , "762", "143", "TERRITORY", "142" },
298 { "TK" , "772", "061", "TERRITORY", "009" },
299 { "TL" , "626", "035", "TERRITORY", "142" },
300 { "TM" , "795", "143", "TERRITORY", "142" },
301 { "TN" , "788", "015", "TERRITORY", "002" },
302 { "TO" , "776", "061", "TERRITORY", "009" },
303 { "TP" , "626", "035", "TERRITORY", "142" },
304 { "TR" , "792", "145", "TERRITORY", "142" },
305 { "TT" , "780", "029", "TERRITORY", "019" },
306 { "TV" , "798", "061", "TERRITORY", "009" },
307 { "TW" , "158", "030", "TERRITORY", "142" },
308 { "TZ" , "834", "014", "TERRITORY", "002" },
309 { "UA" , "804", "151", "TERRITORY", "150" },
310 { "UG" , "800", "014", "TERRITORY", "002" },
311 { "UM" , "581", "QO" , "TERRITORY", "009" },
312 { "US" , "840", "021", "TERRITORY", "019" },
313 { "UY" , "858", "005", "TERRITORY", "019" },
314 { "UZ" , "860", "143", "TERRITORY", "142" },
315 { "VA" , "336", "039", "TERRITORY", "150" },
316 { "VC" , "670", "029", "TERRITORY", "019" },
317 { "VE" , "862", "005", "TERRITORY", "019" },
318 { "VG" , "092", "029", "TERRITORY", "019" },
319 { "VI" , "850", "029", "TERRITORY", "019" },
320 { "VN" , "704", "035", "TERRITORY", "142" },
321 { "VU" , "548", "054", "TERRITORY", "009" },
322 { "WF" , "876", "061", "TERRITORY", "009" },
323 { "WS" , "882", "061", "TERRITORY", "009" },
324 { "YD" , "887", "145", "TERRITORY", "142" },
325 { "YE" , "887", "145", "TERRITORY", "142" },
326 { "YT" , "175", "014", "TERRITORY", "002" },
327 { "ZA" , "710", "018", "TERRITORY", "002" },
328 { "ZM" , "894", "014", "TERRITORY", "002" },
329 { "ZR" , "180", "017", "TERRITORY", "002" },
330 { "ZW" , "716", "014", "TERRITORY", "002" },
331 { "ZZ" , "999", null , "UNKNOWN", null }
335 * Test for known regions.
337 public void TestKnownRegions() {
339 for (String [] rd : knownRegions ) {
341 Region r = Region.getInstance(rd[0]);
342 int n = r.getNumericCode();
343 int e = Integer.valueOf(rd[1]).intValue();
345 errln("Numeric code mismatch for region " + r.toString() + ". Expected: " + e + " Got:" + n);
347 if (r.getType() != Region.RegionType.valueOf(rd[3])) {
348 errln("Expected region " + r.toString() + " to be of type " + rd[3] + ". Got:" + r.getType().toString());
350 int nc = Integer.valueOf(rd[1]).intValue();
352 Region ncRegion = Region.getInstance(nc);
353 if ( !ncRegion.equals(r) && nc != 891 ) { // 891 is special case - CS and YU both deprecated codes for region 891
354 errln("Creating region " + r.toString() + " by its numeric code returned a different region. Got: " + ncRegion.toString());
357 } catch (IllegalArgumentException ex ) {
358 errln("Known region " + rd[0] + " was not recognized.");
363 public void TestGetInstanceString() {
364 String[][] testData = {
365 // Input ID, Expected ID, Expected Type
366 { "DE", "DE", "TERRITORY" }, // Normal region
367 { "QU", "EU", "GROUPING" }, // Alias to a grouping
368 { "DD", "DE", "TERRITORY" }, // Alias to a deprecated region (East Germany) with single preferred value
369 { "276", "DE", "TERRITORY" }, // Numeric code for Germany
370 { "278", "DE", "TERRITORY" }, // Numeric code for East Germany (Deprecated)
371 { "SU", "SU", "DEPRECATED" }, // Alias to a deprecated region with multiple preferred values
372 { "AN", "AN", "DEPRECATED" }, // Deprecated region with multiple preferred values
373 { "SVK", "SK", "TERRITORY" } // 3-letter code - Slovakia
377 Region.getInstance(null);
378 errln("Calling Region.get(null) should have thrown a NullPointerException, but didn't.");
379 } catch ( NullPointerException ex ) {
380 // Do nothing - we're supposed to get here.
384 Region.getInstance("BOGUS");
385 errln("Calling Region.get(BOGUS) should have thrown a IllegalArgumentException, but didn't.");
386 } catch ( IllegalArgumentException ex ) {
387 // Do nothing - we're supposed to get here.
390 for (String [] data : testData) {
391 String inputID = data[0];
392 String expectedID = data[1];
393 Region.RegionType expectedType = Region.RegionType.valueOf(data[2]);
394 Region r = Region.getInstance(inputID);
395 if ( !expectedID.equals(r.toString())) {
396 errln("Unexpected region ID for Region.getInstance(\"" + inputID + "\"); Expected: " + expectedID + " Got: " + r.toString());
398 if ( !expectedType.equals(r.getType())) {
399 errln("Unexpected region type for Region.getInstance(\"" + inputID + "\"); Expected: " + expectedType + " Got: " + r.getType());
404 public void TestGetInstanceInt() {
405 String[][] testData = {
406 // Input ID, Expected ID, Expected Type
407 { "276", "DE", "TERRITORY" }, // Numeric code for Germany
408 { "278", "DE", "TERRITORY" }, // Numeric code for East Germany (Deprecated)
409 { "419", "419", "GROUPING" }, // Latin America
410 { "736", "SD", "TERRITORY" }, // Sudan (pre-2011) - changed numeric code after South Sudan split off
411 { "729", "SD", "TERRITORY" }, // Sudan (post-2011) - changed numeric code after South Sudan split off
415 Region.getInstance(-123);
416 errln("Calling Region.get(-123) should have thrown a IllegalArgumentException, but didn't.");
417 } catch ( IllegalArgumentException ex ) {
418 // Do nothing - we're supposed to get here.
420 for (String [] data : testData) {
421 String inputID = data[0];
422 String expectedID = data[1];
423 Region.RegionType expectedType = Region.RegionType.valueOf(data[2]);
424 Region r = Region.getInstance(Integer.valueOf(inputID));
425 if ( !expectedID.equals(r.toString())) {
426 errln("Unexpected region ID for Region.getInstance(" + inputID + "); Expected: " + expectedID + " Got: " + r.toString());
428 if ( !expectedType.equals(r.getType())) {
429 errln("Unexpected region type for Region.getInstance(" + inputID + "); Expected: " + expectedType + " Got: " + r.getType());
435 public void TestGetContainedRegions() {
436 for (String [] rd : knownRegions ) {
438 Region r = Region.getInstance(rd[0]);
439 if (r.getType() == Region.RegionType.GROUPING) {
442 Set<Region> containedRegions = r.getContainedRegions();
443 for (Region cr : containedRegions ) {
444 if ( cr.getContainingRegion() != r) {
445 errln("Region: " + r.toString() + " contains region: " + cr.toString() + ". Expected containing region of this region to be the original region, but got: " +
446 ( cr.getContainingRegion() == null ? "NULL" : cr.getContainingRegion().toString()));
449 } catch (IllegalArgumentException ex ) {
450 errln("Known region " + rd[0] + " was not recognized.");
455 public void TestGetContainedRegionsWithType() {
456 for (String [] rd : knownRegions ) {
458 Region r = Region.getInstance(rd[0]);
459 if ( r.getType() != Region.RegionType.CONTINENT ) {
462 Set<Region> containedRegions = r.getContainedRegions(Region.RegionType.TERRITORY);
463 for (Region cr : containedRegions ) {
464 if ( cr.getContainingRegion(Region.RegionType.CONTINENT) != r) {
465 errln("Continent: " + r.toString() + " contains territory: " + cr.toString() + ". Expected containing continent of this region to be the original continent, but got: " +
466 ( cr.getContainingRegion() == null ? "NULL" : cr.getContainingRegion().toString()));
469 } catch (IllegalArgumentException ex ) {
470 errln("Known region " + rd[0] + " was not recognized.");
475 public void TestGetContainingRegionWithType() {
476 for (String [] rd : knownRegions ) {
478 Region r = Region.getInstance(rd[0]);
479 Region c = r.getContainingRegion(Region.RegionType.CONTINENT);
482 errln("Containing continent for " + r.toString() + " should have been NULL. Got: " + c.toString());
485 Region p = Region.getInstance(rd[4]);
487 errln("Expected containing continent of region " + r.toString() + " to be " + p.toString() + ". Got: " + ( c == null ? "NULL" : c.toString()) );
490 } catch (IllegalArgumentException ex ) {
491 errln("Known region " + rd[0] + " was not recognized.");
496 public void TestGetContainingRegion() {
497 for (String [] rd : knownRegions ) {
499 Region r = Region.getInstance(rd[0]);
500 Region c = r.getContainingRegion();
503 errln("Containing region for " + r.toString() + " should have been NULL. Got: " + c.toString());
506 Region p = Region.getInstance(rd[2]);
508 errln("Expected containing region of region " + r.toString() + " to be " + p.toString() + ". Got: " + ( c == null ? "NULL" : c.toString()) );
511 } catch (IllegalArgumentException ex ) {
512 errln("Known region " + rd[0] + " was not recognized.");
517 public void TestGetPreferredValues() {
518 String[][] testData = {
519 // Input ID, Expected Preferred Values...
520 { "AN", "CW", "SX", "BQ" }, // Netherlands Antilles
521 { "CS", "RS", "ME" }, // Serbia & Montenegro
522 { "FQ", "AQ", "TF" }, // French Southern and Antarctic Territories
523 { "NT", "IQ", "SA" }, // Neutral Zone
524 { "PC", "FM", "MH", "MP", "PW" }, // Pacific Islands Trust Territory
525 { "SU", "RU", "AM", "AZ", "BY", "EE", "GE", "KZ", "KG", "LV", "LT", "MD", "TJ", "TM", "UA", "UZ" } // Soviet Union
528 for (String [] data : testData) {
529 String inputID = data[0];
531 Region r = Region.getInstance(inputID);
532 List<Region> preferredValues = r.getPreferredValues();
533 for ( int i = 1 ; i < data.length ; i++ ) {
535 Region pvr = Region.getInstance(data[i]);
536 if ( !preferredValues.contains(pvr)) {
537 errln("Region.getPreferredValues() for region:" + inputID + "should have contained: " + pvr.toString() + "but it didn't.");
539 } catch (IllegalArgumentException ex ) {
540 errln("Known region " + data[i] + " was not recognized.");
543 } catch (IllegalArgumentException ex ) {
544 errln("Known region " + inputID + " was not recognized.");
549 public void TestContains() {
550 for (String [] rd : knownRegions ) {
552 Region r = Region.getInstance(rd[0]);
553 Region c = r.getContainingRegion();
554 while ( c != null ) {
555 if ( !c.contains(r)) {
556 errln("Region " + c.toString() + "should have contained: " + r.toString() + "but it didn't.");
558 c = c.getContainingRegion();
560 } catch (IllegalArgumentException ex ) {
561 errln("Known region " + rd[0] + " was not recognized.");
566 public void TestAvailableTerritories() {
567 // Test to make sure that the set of territories contained in World and the set of all available
568 // territories are one and the same.
569 Set<Region> availableTerritories = Region.getAvailable(RegionType.TERRITORY);
570 Region world = Region.getInstance("001");
571 Set<Region> containedInWorld = world.getContainedRegions(RegionType.TERRITORY);
572 if ( !availableTerritories.equals(containedInWorld) ) {
573 errln("Available territories and all territories contained in world should be the same set.\n" +
574 "Available = " + availableTerritories.toString() + "\n" +
575 "Contained in World = " + containedInWorld.toString());