]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/tests/core/src/com/ibm/icu/dev/test/calendar/EthiopicTest.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / tests / core / src / com / ibm / icu / dev / test / calendar / EthiopicTest.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 2005-2010, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 package com.ibm.icu.dev.test.calendar;\r
8 \r
9 import java.util.Date;\r
10 import java.util.Locale;\r
11 \r
12 import com.ibm.icu.impl.LocaleUtility;\r
13 import com.ibm.icu.text.DateFormat;\r
14 import com.ibm.icu.text.SimpleDateFormat;\r
15 import com.ibm.icu.util.Calendar;\r
16 import com.ibm.icu.util.EthiopicCalendar;\r
17 import com.ibm.icu.util.GregorianCalendar;\r
18 import com.ibm.icu.util.TimeZone;\r
19 import com.ibm.icu.util.ULocale;\r
20 \r
21 /**\r
22  * Tests for the <code>EthiopicCalendar</code> class.\r
23  */\r
24 public class EthiopicTest extends CalendarTest \r
25 {\r
26     public static void main(String args[]) throws Exception {\r
27         new EthiopicTest().run(args);\r
28     }\r
29 \r
30     /** Constants to save typing. */\r
31     public static final int MESKEREM = EthiopicCalendar.MESKEREM;\r
32     public static final int TEKEMT   = EthiopicCalendar.TEKEMT;\r
33     public static final int HEDAR    = EthiopicCalendar.HEDAR;\r
34     public static final int TAHSAS   = EthiopicCalendar.TAHSAS;\r
35     public static final int TER      = EthiopicCalendar.TER;\r
36     public static final int YEKATIT  = EthiopicCalendar.YEKATIT;\r
37     public static final int MEGABIT  = EthiopicCalendar.MEGABIT;\r
38     public static final int MIAZIA   = EthiopicCalendar.MIAZIA;\r
39     public static final int GENBOT   = EthiopicCalendar.GENBOT;\r
40     public static final int SENE     = EthiopicCalendar.SENE;\r
41     public static final int HAMLE    = EthiopicCalendar.HAMLE;\r
42     public static final int NEHASSE  = EthiopicCalendar.NEHASSE;\r
43     public static final int PAGUMEN  = EthiopicCalendar.PAGUMEN;\r
44 \r
45     /* DY[20050507]  I don't know what this is for yet: \r
46        public void TestRoll() {\r
47        int[][] tests = new int[][] {\r
48        //       input                roll by          output\r
49        //  year  month     day     field amount    year  month     day\r
50     \r
51        {   0001, QIDAH,     2,     MONTH,   1,     0001, HIJJAH,    2 },   // non-leap years\r
52        {   0001, QIDAH,     2,     MONTH,   2,     0001, MUHARRAM,  2 },\r
53        {   0001, QIDAH,     2,     MONTH,  -1,     0001, SHAWWAL,   2 },\r
54        {   0001, MUHARRAM,  2,     MONTH,  12,     0001, MUHARRAM,  2 },\r
55        {   0001, MUHARRAM,  2,     MONTH,  13,     0001, SAFAR,     2 },\r
56 \r
57        {   0001, HIJJAH,    1,     DATE,   30,     0001, HIJJAH,    2 },   // 29-day month\r
58        {   0002, HIJJAH,    1,     DATE,   31,     0002, HIJJAH,    2 },   // 30-day month\r
59 \r
60        // Try some rolls that require other fields to be adjusted\r
61        {   0001, MUHARRAM, 30,     MONTH,   1,     0001, SAFAR,    29 },\r
62        {   0002, HIJJAH,   30,     YEAR,   -1,     0001, HIJJAH,   29 },\r
63        };\r
64        \r
65        EthiopicCalendar cal = newCivil();\r
66 \r
67        doRollAdd(ROLL, cal, tests);\r
68        }\r
69     */\r
70 \r
71     /* Test dates from:\r
72      * "The Amharic Letters of Emperor Theodore of Ethiopia to Queen Victoria and\r
73      * Her Special Envoy", David Appleyard, Girma Selasse Asfaw, Oxford University Press, \r
74      * June 1 1979, ISBN: 0856726605, Longwood Pr Ltd\r
75      *  \r
76      * Ethiopic       Gregorian    JD\r
77      * 20/02/1855     29/10/1862  2401443\r
78      * 29/10/1857     05/07/1865  2402423\r
79      * 22/05/1858     29/01/1866  2402631\r
80      * 10/08/1858     17/04/1866  2402709\r
81      * 28/04/1859     05/01/1867  2402972\r
82      * 05/05/1860     13/01/1868  2403345\r
83      * \r
84      * --------------------------------------------------\r
85      * \r
86      * From the Calendrica applet:  http://emr.cs.iit.edu/home/reingold/calendar-book/Calendrica.html\r
87      * \r
88      * Ethiopic       Gregorian    JD\r
89      * 07/05/-8       01/01/0000  1721060\r
90      * 08/05/-7       01/01/0001  1721426\r
91      * 06/13/-1       27/08/0007  1723855\r
92      * \r
93      * 01/01/0000     28/08/0007  1723856\r
94      * 01/01/0001     27/08/0008  1724221\r
95      * 01/01/0002     27/08/0009  1724586\r
96      * 01/01/0003     27/08/0010  1724951\r
97      * 01/01/0004     28/08/0011  1724537\r
98      * 05/13/0000     26/08/0008  1724220\r
99      * 05/13/0001     26/08/0009  1724585\r
100      * 05/13/0002     26/08/0010  1724950\r
101      * 05/13/0003     26/08/0011  1725315\r
102      * 06/13/0003     27/08/0011  1725316  first ethiopian leap year\r
103      * 05/13/0004     26/08/0012  1725561\r
104      * \r
105      * 06/02/1575     13/10/1582  2299159\r
106      * 07/02/1575     14/10/1582  2299160  Julian 04/10/1582\r
107      * 08/02/1575     15/10/1582  2299161\r
108      * 09/02/1575     16/10/1582  2299162\r
109      * \r
110      * 23/04/1892     01/01/1900  2415021\r
111      * 23/04/1997     01/01/2005  2453372\r
112      * 05/13/2000     10/09/2008  2454720\r
113      */\r
114     \r
115     /** A huge list of test cases to make sure that computeTime and computeFields\r
116      * work properly for a wide range of data in the civil calendar.\r
117      */\r
118     public void TestCases()\r
119     {\r
120         final TestCase[] tests = {\r
121             //\r
122             // The months in this table are 1-based rather than 0-based,\r
123             // because it's easier to edit that way.\r
124             //                      Ethiopic\r
125             //          Julian Day  Era  Year  Month Day  WkDay Hour Min Sec\r
126             //\r
127             // Dates from "Emporer Theodore..."\r
128 \r
129             new TestCase(2401442.5,  1,  1855,    2,  20,  WED,   0,  0,  0), // Gregorian: 29/10/1862\r
130             new TestCase(2402422.5,  1,  1857,   10,  29,  WED,   0,  0,  0), // Gregorian: 05/07/1865\r
131             new TestCase(2402630.5,  1,  1858,    5,  22,  MON,   0,  0,  0), // Gregorian: 29/01/1866\r
132             new TestCase(2402708.5,  1,  1858,    8,  10,  TUE,   0,  0,  0), // Gregorian: 17/04/1866\r
133             new TestCase(2402971.5,  1,  1859,    4,  28,  SAT,   0,  0,  0), // Gregorian: 05/01/1867\r
134             new TestCase(2403344.5,  1,  1860,    5,   5,  MON,   0,  0,  0), // Gregorian: 13/01/1868\r
135                         \r
136             // Miscellaneous:\r
137             /* Skip these tests until JD bug fixed in the Gregorian calendar:\r
138              * http://www.jtcsv.com/cgibin/icu-bugs/incoming?id=4406;page=2;user=guest\r
139              */\r
140             new TestCase(1721059.5,  0,  5492,    5,   7,  SAT,   0,  0,  0), // Gregorian: 01/01/0000\r
141             new TestCase(1721425.5,  0,  5493,    5,   8,  MON,   0,  0,  0), // Gregorian: 01/01/0001\r
142             new TestCase(1723854.5,  0,  5499,   13,   6,  MON,   0,  0,  0), // Gregorian: 27/08/0007\r
143 \r
144             new TestCase(1723855.5,  0,  5500,    1,   1,  TUE,   0,  0,  0), // Gregorian: 28/08/0007\r
145             new TestCase(1724220.5,  1,     1,    1,   1,  WED,   0,  0,  0), // Gregorian: 27/08/0008\r
146             new TestCase(1724585.5,  1,     2,    1,   1,  THU,   0,  0,  0), // Gregorian: 27/08/0009\r
147             new TestCase(1724950.5,  1,     3,    1,   1,  FRI,   0,  0,  0), // Gregorian: 27/08/0010\r
148 \r
149             // new TestCase(1724536.5,  1,     4,    1,   1,  SUN,   0,  0,  0), // Gregorian: 28/08/0011\r
150             new TestCase(1725316.5,  1,     4,    1,   1,  SUN,   0,  0,  0), // Gregorian: 28/08/0011 - dlf\r
151             new TestCase(1724219.5,  0,  5500,   13,   5,  TUE,   0,  0,  0), // Gregorian: 26/08/0008\r
152             new TestCase(1724584.5,  1,     1,   13,   5,  WED,   0,  0,  0), // Gregorian: 26/08/0009\r
153             new TestCase(1724949.5,  1,     2,   13,   5,  THU,   0,  0,  0), // Gregorian: 26/08/0010\r
154             new TestCase(1725314.5,  1,     3,   13,   5,  FRI,   0,  0,  0), // Gregorian: 26/08/0011\r
155             new TestCase(1725315.5,  1,     3,   13,   6,  SAT,   0,  0,  0), // Gregorian: 27/08/0011 - first ethiopic leap year\r
156             // new TestCase(1725560.5,  1,     4,   13,   5,  SUN,   0,  0,  0), // Gregorian: 26/08/0012 - dlf\r
157             new TestCase(1725680.5,  1,     4,   13,   5,  SUN,   0,  0,  0), // Gregorian: 26/08/0012\r
158             new TestCase(2299158.5,  1,  1575,    2,   6,  WED,   0,  0,  0), // Gregorian: 13/10/1582  \r
159             new TestCase(2299159.5,  1,  1575,    2,   7,  THU,   0,  0,  0), // Gregorian: 14/10/1582  Julian 04/10/1582\r
160 \r
161             new TestCase(2299160.5,  1,  1575,    2,   8,  FRI,   0,  0,  0), // Gregorian: 15/10/1582\r
162             new TestCase(2299161.5,  1,  1575,    2,   9,  SAT,   0,  0,  0), // Gregorian: 16/10/1582\r
163 \r
164             new TestCase(2415020.5,  1,  1892,    4,  23,  MON,   0,  0,  0), // Gregorian: 01/01/1900\r
165             new TestCase(2453371.5,  1,  1997,    4,  23,  SAT,   0,  0,  0), // Gregorian: 01/01/2005\r
166             new TestCase(2454719.5,  1,  2000,   13,   5,  WED,   0,  0,  0), // Gregorian: 10/09/2008\r
167         };\r
168 \r
169         final TestCase[] testsAmeteAlem = {\r
170                 //\r
171                 // The months in this table are 1-based rather than 0-based,\r
172                 // because it's easier to edit that way.\r
173                 //                      Ethiopic\r
174                 //          Julian Day  Era  Year  Month Day  WkDay Hour Min Sec\r
175                 //\r
176                 // Dates from "Emporer Theodore..."\r
177 \r
178                 new TestCase(2401442.5,  0,  7355,    2,  20,  WED,   0,  0,  0), // Gregorian: 29/10/1862\r
179                 new TestCase(2402422.5,  0,  7357,   10,  29,  WED,   0,  0,  0), // Gregorian: 05/07/1865\r
180                 new TestCase(2402630.5,  0,  7358,    5,  22,  MON,   0,  0,  0), // Gregorian: 29/01/1866\r
181                 new TestCase(2402708.5,  0,  7358,    8,  10,  TUE,   0,  0,  0), // Gregorian: 17/04/1866\r
182                 new TestCase(2402971.5,  0,  7359,    4,  28,  SAT,   0,  0,  0), // Gregorian: 05/01/1867\r
183                 new TestCase(2403344.5,  0,  7360,    5,   5,  MON,   0,  0,  0), // Gregorian: 13/01/1868\r
184                             \r
185                 // Miscellaneous:\r
186                 /* Skip these tests until JD bug fixed in the Gregorian calendar:\r
187                  * http://www.jtcsv.com/cgibin/icu-bugs/incoming?id=4406;page=2;user=guest\r
188                  */\r
189                 new TestCase(1721059.5,  0,  5492,    5,   7,  SAT,   0,  0,  0), // Gregorian: 01/01/0000\r
190                 new TestCase(1721425.5,  0,  5493,    5,   8,  MON,   0,  0,  0), // Gregorian: 01/01/0001\r
191                 new TestCase(1723854.5,  0,  5499,   13,   6,  MON,   0,  0,  0), // Gregorian: 27/08/0007\r
192 \r
193                 new TestCase(1723855.5,  0,  5500,    1,   1,  TUE,   0,  0,  0), // Gregorian: 28/08/0007\r
194                 new TestCase(1724220.5,  0,  5501,    1,   1,  WED,   0,  0,  0), // Gregorian: 27/08/0008\r
195                 new TestCase(1724585.5,  0,  5502,    1,   1,  THU,   0,  0,  0), // Gregorian: 27/08/0009\r
196                 new TestCase(1724950.5,  0,  5503,    1,   1,  FRI,   0,  0,  0), // Gregorian: 27/08/0010\r
197 \r
198                 // new TestCase(1724536.5,  0,  5504,    1,   1,  SUN,   0,  0,  0), // Gregorian: 28/08/0011\r
199                 new TestCase(1725316.5,  0,  5504,    1,   1,  SUN,   0,  0,  0), // Gregorian: 28/08/0011 - dlf\r
200                 new TestCase(1724219.5,  0,  5500,   13,   5,  TUE,   0,  0,  0), // Gregorian: 26/08/0008\r
201                 new TestCase(1724584.5,  0,  5501,   13,   5,  WED,   0,  0,  0), // Gregorian: 26/08/0009\r
202                 new TestCase(1724949.5,  0,  5502,   13,   5,  THU,   0,  0,  0), // Gregorian: 26/08/0010\r
203                 new TestCase(1725314.5,  0,  5503,   13,   5,  FRI,   0,  0,  0), // Gregorian: 26/08/0011\r
204                 new TestCase(1725315.5,  0,  5503,   13,   6,  SAT,   0,  0,  0), // Gregorian: 27/08/0011 - first ethiopic leap year\r
205                 // new TestCase(1725560.5,  0,  5504,   13,   5,  SUN,   0,  0,  0), // Gregorian: 26/08/0012 - dlf\r
206                 new TestCase(1725680.5,  0,  5504,   13,   5,  SUN,   0,  0,  0), // Gregorian: 26/08/0012\r
207                 new TestCase(2299158.5,  0,  7075,    2,   6,  WED,   0,  0,  0), // Gregorian: 13/10/1582  \r
208                 new TestCase(2299159.5,  0,  7075,    2,   7,  THU,   0,  0,  0), // Gregorian: 14/10/1582  Julian 04/10/1582\r
209 \r
210                 new TestCase(2299160.5,  0,  7075,    2,   8,  FRI,   0,  0,  0), // Gregorian: 15/10/1582\r
211                 new TestCase(2299161.5,  0,  7075,    2,   9,  SAT,   0,  0,  0), // Gregorian: 16/10/1582\r
212 \r
213                 new TestCase(2415020.5,  0,  7392,    4,  23,  MON,   0,  0,  0), // Gregorian: 01/01/1900\r
214                 new TestCase(2453371.5,  0,  7497,    4,  23,  SAT,   0,  0,  0), // Gregorian: 01/01/2005\r
215                 new TestCase(2454719.5,  0,  7500,   13,   5,  WED,   0,  0,  0), // Gregorian: 10/09/2008\r
216             };\r
217 \r
218         EthiopicCalendar testCalendar = new EthiopicCalendar();\r
219         testCalendar.setLenient(true);\r
220         doTestCases(tests, testCalendar);\r
221 \r
222         // Testing Amete Alem mode\r
223 \r
224         EthiopicCalendar testCalendarAmeteAlem = new EthiopicCalendar();\r
225         testCalendarAmeteAlem.setAmeteAlemEra(true);\r
226         testCalendarAmeteAlem.setLenient(true);\r
227         doTestCases(testsAmeteAlem, testCalendarAmeteAlem);\r
228     }\r
229 \r
230     // basic check to see that we print out eras ok\r
231     // eventually should modify to use locale strings and formatter appropriate to coptic calendar\r
232     public void TestEraStart() {\r
233         SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd, yyyy GG");\r
234         fmt.setCalendar(new EthiopicCalendar());\r
235 \r
236         EthiopicCalendar cal = new EthiopicCalendar(1, 0, 1);\r
237         assertEquals("Ethiopic Date", "Wed Jan 01, 0001 AD", fmt.format(cal));\r
238 \r
239         cal.set(Calendar.ERA, 0);\r
240         cal.set(Calendar.YEAR, 5500);\r
241         assertEquals("Ethiopic Date", "Tue Jan 01, 5500 BC", fmt.format(cal));\r
242 \r
243         // The gregorian calendar gets off by two days when\r
244         // the date gets low, unless the gregorian changeover is set to \r
245         // very early.  The funny thing is, it's ok for dates in the year\r
246         // 283, but not in the year 7, and it claims to be ok until the year 4.\r
247         // should track down when the dates start to differ...\r
248         \r
249         GregorianCalendar gc = new GregorianCalendar();\r
250         gc.setGregorianChange(new Date(Long.MIN_VALUE)); // act like proleptic Gregorian\r
251         gc.setTime(cal.getTime());\r
252         fmt.setCalendar(new GregorianCalendar());\r
253         assertEquals("Gregorian Date", "Tue Aug 28, 0007 AD", fmt.format(gc));\r
254     }\r
255 \r
256     public void TestBasic() {\r
257         EthiopicCalendar cal = new EthiopicCalendar();\r
258         cal.clear();\r
259         cal.set(1000, 0, 30);\r
260         logln("1000/0/30-> " +\r
261               cal.get(YEAR) + "/" +\r
262               cal.get(MONTH) + "/" + \r
263               cal.get(DATE));\r
264         cal.clear();\r
265         cal.set(1, 0, 30);\r
266         logln("1/0/30 -> " +\r
267               cal.get(YEAR) + "/" +\r
268               cal.get(MONTH) + "/" + \r
269               cal.get(DATE));\r
270     }\r
271     \r
272     public void TestJD(){\r
273         int jd = EthiopicCalendar.EthiopicToJD(1567,8,9);\r
274         EthiopicCalendar cal = new EthiopicCalendar();\r
275         cal.clear();\r
276         cal.set(Calendar.JULIAN_DAY, jd);\r
277         if (cal.get(Calendar.EXTENDED_YEAR) == 1567 &&\r
278             cal.get(Calendar.MONTH) == 8 &&\r
279             cal.get(Calendar.DAY_OF_MONTH) == 9){\r
280             logln("EthiopicCalendar.getDateFromJD tested");\r
281         } else {\r
282             errln("EthiopicCalendar.getDateFromJD failed");\r
283         }\r
284     }\r
285 \r
286     /**\r
287      * Test limits of the Coptic calendar\r
288      */\r
289     public void TestLimits() {\r
290         Calendar cal = Calendar.getInstance();\r
291         cal.set(2007, Calendar.JANUARY, 1);\r
292         EthiopicCalendar ethiopic = new EthiopicCalendar();\r
293         doLimitsTest(ethiopic, null, cal.getTime());\r
294         doTheoreticalLimitsTest(ethiopic, true);\r
295     }\r
296 \r
297     \r
298     public void TestCoverage() {\r
299 \r
300         {\r
301             // new EthiopicCalendar(TimeZone)\r
302             EthiopicCalendar cal = new EthiopicCalendar(TimeZone.getDefault()); \r
303             if(cal == null){\r
304                 errln("could not create EthiopicCalendar with TimeZone");\r
305             }\r
306         }\r
307 \r
308         {\r
309             // new EthiopicCalendar(ULocale)\r
310             EthiopicCalendar cal = new EthiopicCalendar(ULocale.getDefault());\r
311             if(cal == null){\r
312                 errln("could not create EthiopicCalendar with ULocale");\r
313             }\r
314         }\r
315         \r
316         {\r
317             // new EthiopicCalendar(Locale)\r
318             EthiopicCalendar cal = new EthiopicCalendar(Locale.getDefault());\r
319             if(cal == null){\r
320                 errln("could not create EthiopicCalendar with Locale");\r
321             }\r
322         }\r
323 \r
324         {\r
325             // new EthiopicCalendar(TimeZone, Locale)\r
326             EthiopicCalendar cal = new EthiopicCalendar(TimeZone.getDefault(), Locale.getDefault());\r
327             if(cal == null){\r
328                 errln("could not create EthiopicCalendar with TimeZone,Locale");\r
329             }\r
330         }\r
331 \r
332         {\r
333             // new EthiopicCalendar(TimeZone, ULocale)\r
334             EthiopicCalendar cal = new EthiopicCalendar(TimeZone.getDefault(), ULocale.getDefault());\r
335             if(cal == null){\r
336                 errln("could not create EthiopicCalendar with TimeZone,ULocale");\r
337             }\r
338         }\r
339         \r
340         {\r
341             // new EthiopicCalendar(Date)\r
342             EthiopicCalendar cal = new EthiopicCalendar(new Date());\r
343             if(cal == null){\r
344                 errln("could not create EthiopicCalendar with Date");\r
345             }\r
346         }\r
347 \r
348         {\r
349             // new EthiopicCalendar(int year, int month, int date)\r
350             EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1);\r
351             if(cal == null){\r
352                 errln("could not create EthiopicCalendar with year,month,date");\r
353             }\r
354         }\r
355 \r
356         {\r
357             // new EthiopicCalendar(int year, int month, int date, int hour, int minute, int second)\r
358             EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1, 1, 1, 1);\r
359             if(cal == null){\r
360                 errln("could not create EthiopicCalendar with year,month,date,hour,minute,second");\r
361             }\r
362         }\r
363 \r
364         {\r
365             // setCivil/isCivil\r
366             // operations on non-civil calendar\r
367             EthiopicCalendar cal = newAmeteAlemEraCalendar();\r
368             cal.setAmeteAlemEra(false);\r
369             if (cal.isAmeteAlemEra()) {\r
370                 errln("EthiopicCalendar calendar is old system");\r
371             }\r
372 \r
373             Date now = new Date();\r
374             cal.setTime(now);\r
375 \r
376             Date then = cal.getTime();\r
377             if (!now.equals(then)) {\r
378                 errln("get/set time failed with non-civil EthiopicCalendar calendar");\r
379             }\r
380 \r
381             logln(then.toString());\r
382 \r
383             cal.add(Calendar.MONTH, 1);\r
384             cal.add(Calendar.DAY_OF_MONTH, 1);\r
385             cal.add(Calendar.YEAR, 1);\r
386 \r
387             logln(cal.getTime().toString());\r
388         }\r
389     \r
390         {\r
391             // data\r
392             EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1);\r
393             Date time = cal.getTime();\r
394 \r
395             String[] calendarLocales = {\r
396                 "am_ET", "gez_ET", "ti_ET"\r
397             };\r
398 \r
399             String[] formatLocales = {\r
400                 "en", "am", "gez", "ti"\r
401             };\r
402             for (int i = 0; i < calendarLocales.length; ++i) {\r
403                 String calLocName = calendarLocales[i];\r
404                 Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);\r
405                 cal = new EthiopicCalendar(calLocale);\r
406 \r
407                 for (int j = 0; j < formatLocales.length; ++j) {\r
408                     String locName = formatLocales[j];\r
409                     Locale formatLocale = LocaleUtility.getLocaleFromName(locName);\r
410                     DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale);\r
411                     logln(calLocName + "/" + locName + " --> " + format.format(time));\r
412                 }\r
413             }\r
414         }\r
415     }\r
416     \r
417     private static EthiopicCalendar newAmeteAlemEraCalendar() {\r
418         EthiopicCalendar alemawiCalendar = new EthiopicCalendar();\r
419         alemawiCalendar.setAmeteAlemEra(true);\r
420         return alemawiCalendar;\r
421     }\r
422 \r
423     public void TestAddSet() {\r
424         class TestAddSetItem {\r
425             private int startYear;\r
426             private int startMonth; // 0-based\r
427             private int startDay; // 1-based\r
428             private int fieldToChange;\r
429             private int fieldDelta;\r
430             private int endYear;\r
431             private int endMonth;\r
432             private int endDay;\r
433             TestAddSetItem(int sYr, int sMo, int sDa, int field, int delta, int eYr, int eMo, int eDa) {\r
434                 startYear = sYr;\r
435                 startMonth = sMo;\r
436                 startDay = sDa;\r
437                 fieldToChange = field;\r
438                 fieldDelta = delta;\r
439                 endYear = eYr;\r
440                 endMonth = eMo;\r
441                 endDay = eDa;\r
442             }\r
443             public int getStartYear()  { return startYear; }\r
444             public int getStartMonth() { return startMonth; }\r
445             public int getStartDay()   { return startDay; }\r
446             public int getField()      { return fieldToChange; }\r
447             public int getDelta()      { return fieldDelta; }\r
448             public int getEndYear()    { return endYear; }\r
449             public int getEndMonth()   { return endMonth; }\r
450             public int getEndDay()     { return endDay; }\r
451         }\r
452         final TestAddSetItem[] tests = {\r
453             new TestAddSetItem( 2000, 12, 1, Calendar.MONTH, +1, 2001,  0, 1 ),\r
454             new TestAddSetItem( 2000, 12, 1, Calendar.MONTH, +9, 2001,  8, 1 ),\r
455             new TestAddSetItem( 1999, 12, 2, Calendar.MONTH, +1, 2000,  0, 2 ), // 1999 is a leap year\r
456             new TestAddSetItem( 1999, 12, 2, Calendar.MONTH, +9, 2000,  8, 2 ),\r
457             new TestAddSetItem( 2001,  0, 1, Calendar.MONTH, -1, 2000, 12, 1 ),\r
458             new TestAddSetItem( 2001,  0, 1, Calendar.MONTH, -6, 2000,  7, 1 ),\r
459             new TestAddSetItem( 2000, 12, 1, Calendar.DATE,  +8, 2001,  0, 4 ),\r
460             new TestAddSetItem( 1999, 12, 1, Calendar.DATE,  +8, 2000,  0, 3 ), // 1999 is a leap year\r
461             new TestAddSetItem( 2000,  0, 1, Calendar.DATE,  -1, 1999, 12, 6 ),\r
462         };\r
463         EthiopicCalendar testCalendar = new EthiopicCalendar();\r
464         for ( int i = 0; i < tests.length; i++ ) {\r
465             TestAddSetItem item = tests[i];\r
466             testCalendar.set( item.getStartYear(), item.getStartMonth(), item.getStartDay(), 9, 0 );\r
467             testCalendar.add( item.getField(), item.getDelta() );\r
468             int endYear = testCalendar.get(Calendar.YEAR);\r
469             int endMonth = testCalendar.get(Calendar.MONTH);\r
470             int endDay = testCalendar.get(Calendar.DATE);\r
471             if ( endYear != item.getEndYear() || endMonth != item.getEndMonth() || endDay != item.getEndDay() ) {\r
472                 errln("EToJD FAILS: field " + item.getField() + " delta " + item.getDelta() + \r
473                             " expected yr " + item.getEndYear() + " mo " + item.getEndMonth() +  " da " + item.getEndDay() +\r
474                             " got yr " + endYear + " mo " + endMonth +  " da " + endDay);\r
475             }\r
476         }\r
477     }\r
478 }\r