initial checkin
X-SVN-Rev: 876
This commit is contained in:
parent
08009dd620
commit
27a4494f9e
62
icu4j/src/com/ibm/icu/dev/test/calendar/AstroTest.java
Executable file
62
icu4j/src/com/ibm/icu/dev/test/calendar/AstroTest.java
Executable file
@ -0,0 +1,62 @@
|
||||
package com.ibm.test.calendar;
|
||||
|
||||
// AstroTest
|
||||
|
||||
import com.ibm.test.*;
|
||||
import java.util.*;
|
||||
import com.ibm.util.*;
|
||||
|
||||
import com.ibm.util.CalendarAstronomer.*;
|
||||
|
||||
// TODO: try finding next new moon after 07/28/1984 16:00 GMT
|
||||
|
||||
public class AstroTest extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new AstroTest().run(args);
|
||||
}
|
||||
|
||||
static final double PI = Math.PI;
|
||||
|
||||
static GregorianCalendar gc = new GregorianCalendar(new SimpleTimeZone(0, "UTC"));
|
||||
static CalendarAstronomer astro = new CalendarAstronomer();
|
||||
|
||||
public void TestSolarLongitude() {
|
||||
final double tests[][] = {
|
||||
{ 1980, 7, 27, 00, 00, 124.114347 },
|
||||
{ 1988, 7, 27, 00, 00, 124.187732 },
|
||||
};
|
||||
logln("");
|
||||
for (int i = 0; i < tests.length; i++) {
|
||||
gc.clear();
|
||||
gc.set((int)tests[i][0], (int)tests[i][1]-1, (int)tests[i][2], (int)tests[i][3], (int) tests[i][4]);
|
||||
|
||||
astro.setDate(gc.getTime());
|
||||
|
||||
double longitude = astro.getSunLongitude();
|
||||
|
||||
Equatorial result = astro.getSunPosition();
|
||||
}
|
||||
}
|
||||
|
||||
public void TestLunarPosition() {
|
||||
final double tests[][] = {
|
||||
{ 1979, 2, 26, 16, 00, 0, 0 },
|
||||
};
|
||||
logln("");
|
||||
|
||||
for (int i = 0; i < tests.length; i++) {
|
||||
gc.clear();
|
||||
gc.set((int)tests[i][0], (int)tests[i][1]-1, (int)tests[i][2], (int)tests[i][3], (int) tests[i][4]);
|
||||
astro.setDate(gc.getTime());
|
||||
|
||||
Equatorial result = astro.getMoonPosition();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void TestCoordinates() {
|
||||
Equatorial result = astro.eclipticToEquatorial(139.686111 * PI/ 180.0, 4.875278* PI / 180.0);
|
||||
logln("result is " + result + "; " + result.toHmsString());
|
||||
}
|
||||
|
||||
}
|
174
icu4j/src/com/ibm/icu/dev/test/calendar/CalendarTest.java
Executable file
174
icu4j/src/com/ibm/icu/dev/test/calendar/CalendarTest.java
Executable file
@ -0,0 +1,174 @@
|
||||
/*
|
||||
* @(#)$RCSfile: CalendarTest.java,v $ $Revision: 1.1 $ $Date: 2000/03/01 18:32:30 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998 - All Rights Reserved
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.ibm.test.calendar;
|
||||
|
||||
import com.ibm.test.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import com.ibm.util.*;
|
||||
|
||||
/**
|
||||
* A base class for classes that test individual Calendar subclasses.
|
||||
* Defines various useful utility methods and constants
|
||||
*/
|
||||
public class CalendarTest extends TestFmwk {
|
||||
|
||||
// Constants for use by subclasses, solely to save typing
|
||||
public final static int SUN = Calendar.SUNDAY;
|
||||
public final static int MON = Calendar.MONDAY;
|
||||
public final static int TUE = Calendar.TUESDAY;
|
||||
public final static int WED = Calendar.WEDNESDAY;
|
||||
public final static int THU = Calendar.THURSDAY;
|
||||
public final static int FRI = Calendar.FRIDAY;
|
||||
public final static int SAT = Calendar.SATURDAY;
|
||||
|
||||
public final static int ERA = Calendar.ERA;
|
||||
public final static int YEAR = Calendar.YEAR;
|
||||
public final static int MONTH = Calendar.MONTH;
|
||||
public final static int DATE = Calendar.DATE;
|
||||
public final static int HOUR = Calendar.HOUR;
|
||||
public final static int MINUTE = Calendar.MINUTE;
|
||||
public final static int SECOND = Calendar.SECOND;
|
||||
public final static int DOY = Calendar.DAY_OF_YEAR;
|
||||
public final static int WOY = Calendar.WEEK_OF_YEAR;
|
||||
public final static int WOM = Calendar.WEEK_OF_MONTH;
|
||||
public final static int DOW = Calendar.DAY_OF_WEEK;
|
||||
public final static int DOWM = Calendar.DAY_OF_WEEK_IN_MONTH;
|
||||
|
||||
public final static SimpleTimeZone UTC = new SimpleTimeZone(0, "GMT");
|
||||
|
||||
final String pattern = "E, MM/dd/yyyy G HH:mm:ss.S z";
|
||||
|
||||
/**
|
||||
* Iterates through a list of calendar <code>TestCase</code> objects and
|
||||
* makes sure that the time-to-fields and fields-to-time calculations work
|
||||
* correnctly for the values in each test case.
|
||||
*/
|
||||
public void doTestCases(TestCase[] cases, Calendar cal)
|
||||
{
|
||||
cal.setTimeZone(UTC);
|
||||
|
||||
// Get a format to use for printing dates in the calendar system we're testing
|
||||
// TODO: This is kind of ugly right now .
|
||||
DateFormat format = IBMCalendar.getDateTimeFormat(cal, DateFormat.SHORT, -1, Locale.getDefault());
|
||||
|
||||
((SimpleDateFormat)format).applyPattern(pattern);
|
||||
DateFormat testFmt = (DateFormat)format.clone();
|
||||
|
||||
// This format is used for pringing Gregorian dates. This one is easier
|
||||
DateFormat gregFormat = new SimpleDateFormat(pattern);
|
||||
gregFormat.setTimeZone(UTC);
|
||||
|
||||
// Now iterate through the test cases and see what happens
|
||||
for (int i = 0; i < cases.length; i++)
|
||||
{
|
||||
TestCase test = cases[i];
|
||||
testFmt.setCalendar(test);
|
||||
|
||||
//
|
||||
// First we want to make sure that the millis -> fields calculation works
|
||||
// test.applyTime will call setTime() on the calendar object, and
|
||||
// test.fieldsEqual will retrieve all of the field values and make sure
|
||||
// that they're the same as the ones in the testcase
|
||||
//
|
||||
test.applyTime(cal);
|
||||
if (!test.fieldsEqual(cal)) {
|
||||
errln("ERROR: millis --> fields calculation incorrect for "
|
||||
+ gregFormat.format(test.getTime()));
|
||||
logln(" expected " + testFmt.format(test.getTime()));
|
||||
logln(" got " + format.format(cal.getTime()) );
|
||||
}
|
||||
else {
|
||||
//
|
||||
// If that was OK, check the fields -> millis calculation
|
||||
// test.applyFields will set all of the calendar's fields to
|
||||
// match those in the test case.
|
||||
//
|
||||
cal.setTime(new Date(0));
|
||||
test.applyFields(cal);
|
||||
|
||||
if (!test.equals(cal)) {
|
||||
errln("ERROR: fields --> millis calculation incorrect for "
|
||||
+ testFmt.format(test.getTime()));
|
||||
logln(" expected " + test.getTime().getTime());
|
||||
logln(" got " + cal.getTime().getTime() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public final boolean ROLL = true;
|
||||
static public final boolean ADD = false;
|
||||
|
||||
/**
|
||||
* Process test cases for <code>add</code> and <code>roll</code> methods.
|
||||
* Each test case is an array of integers, as follows:
|
||||
* <ul>
|
||||
* <li>0: input year
|
||||
* <li>1: month (zero-based)
|
||||
* <li>2: day
|
||||
* <li>3: field to roll or add to
|
||||
* <li>4: amount to roll or add
|
||||
* <li>5: result year
|
||||
* <li>6: month (zero-based)
|
||||
* <li>7: day
|
||||
* </ul>
|
||||
* For example:
|
||||
* <pre>
|
||||
* // input add by output
|
||||
* // year month day field amount year month day
|
||||
* { 5759, HESHVAN, 2, MONTH, 1, 5759, KISLEV, 2 },
|
||||
* </pre>
|
||||
*
|
||||
* @param roll <code>true</code> or <code>ROLL</code> to test the <code>roll</code> method;
|
||||
* <code>false</code> or <code>ADD</code> to test the <code>add</code method
|
||||
*/
|
||||
public void doRollAdd(boolean roll, IBMCalendar cal, int[][] tests)
|
||||
{
|
||||
String name = roll ? "rolling" : "adding";
|
||||
|
||||
for (int i = 0; i < tests.length; i++) {
|
||||
int[] test = tests[i];
|
||||
|
||||
cal.clear();
|
||||
cal.set(test[0], test[1], test[2]);
|
||||
|
||||
if (roll) {
|
||||
cal.roll(test[3], test[4]);
|
||||
} else {
|
||||
cal.add(test[3], test[4]);
|
||||
}
|
||||
|
||||
if (cal.get(YEAR) != test[5] || cal.get(MONTH) != test[6]
|
||||
|| cal.get(DATE) != test[7])
|
||||
{
|
||||
errln("Error " + name + " "+ ymdToString(test[0], test[1], test[2])
|
||||
+ " field " + test[3] + " by " + test[4]
|
||||
+ ": expected " + ymdToString(test[5], test[6], test[7])
|
||||
+ ", got " + ymdToString(cal.get(YEAR), cal.get(MONTH), cal.get(DATE)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert year,month,day values to the form "year/month/day".
|
||||
* On input the month value is zero-based, but in the result string it is one-based.
|
||||
*/
|
||||
static public String ymdToString(int year, int month, int day) {
|
||||
return "" + year + "/" + (month+1) + "/" + day;
|
||||
}
|
||||
};
|
204
icu4j/src/com/ibm/icu/dev/test/calendar/HebrewTest.java
Executable file
204
icu4j/src/com/ibm/icu/dev/test/calendar/HebrewTest.java
Executable file
@ -0,0 +1,204 @@
|
||||
/**
|
||||
* @(#)$RCSFile$ $Revision: 1.1 $ $Date: 2000/03/01 18:32:31 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
|
||||
package com.ibm.test.calendar;
|
||||
|
||||
import com.ibm.test.*;
|
||||
import java.util.*;
|
||||
import java.text.*;
|
||||
import com.ibm.util.*;
|
||||
|
||||
/**
|
||||
* Tests for the <code>HebrewCalendar</code> class.
|
||||
*/
|
||||
public class HebrewTest extends CalendarTest {
|
||||
public static void main(String args[]) throws Exception {
|
||||
new HebrewTest().run(args);
|
||||
}
|
||||
|
||||
// Constants to save typing.
|
||||
public static final int TISHRI = HebrewCalendar.TISHRI;
|
||||
public static final int HESHVAN = HebrewCalendar.HESHVAN;
|
||||
public static final int KISLEV = HebrewCalendar.KISLEV;
|
||||
public static final int TEVET = HebrewCalendar.TEVET;
|
||||
public static final int SHEVAT = HebrewCalendar.SHEVAT;
|
||||
public static final int ADAR_1 = HebrewCalendar.ADAR_1;
|
||||
public static final int ADAR = HebrewCalendar.ADAR;
|
||||
public static final int NISAN = HebrewCalendar.NISAN;
|
||||
public static final int IYAR = HebrewCalendar.IYAR;
|
||||
public static final int SIVAN = HebrewCalendar.SIVAN;
|
||||
public static final int TAMUZ = HebrewCalendar.TAMUZ;
|
||||
public static final int AV = HebrewCalendar.AV;
|
||||
public static final int ELUL = HebrewCalendar.ELUL;
|
||||
|
||||
/**
|
||||
* Test the behavior of HebrewCalendar.roll
|
||||
* The only real nastiness with roll is the MONTH field, since a year can
|
||||
* have a variable number of months.
|
||||
*/
|
||||
public void TestRoll() {
|
||||
int[][] tests = new int[][] {
|
||||
// input roll by output
|
||||
// year month day field amount year month day
|
||||
|
||||
{ 5759, HESHVAN, 2, MONTH, 1, 5759, KISLEV, 2 }, // non-leap years
|
||||
{ 5759, SHEVAT, 2, MONTH, 1, 5759, ADAR, 2 },
|
||||
{ 5759, SHEVAT, 2, MONTH, 2, 5759, NISAN, 2 },
|
||||
{ 5759, SHEVAT, 2, MONTH, 12, 5759, SHEVAT, 2 },
|
||||
|
||||
{ 5757, HESHVAN, 2, MONTH, 1, 5757, KISLEV, 2 }, // leap years
|
||||
{ 5757, SHEVAT, 2, MONTH, 1, 5757, ADAR_1, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 2, 5757, ADAR, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 3, 5757, NISAN, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 12, 5757, TEVET, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 13, 5757, SHEVAT, 2 },
|
||||
|
||||
{ 5757, KISLEV, 1, DATE, 30, 5757, KISLEV, 2 }, // 29-day month
|
||||
{ 5758, KISLEV, 1, DATE, 31, 5758, KISLEV, 2 }, // 30-day month
|
||||
|
||||
// Try some other fields too
|
||||
{ 5757, TISHRI, 1, YEAR, 1, 5758, TISHRI, 1 },
|
||||
|
||||
|
||||
// Try some rolls that require other fields to be adjusted
|
||||
{ 5757, TISHRI, 30, MONTH, 1, 5757, HESHVAN, 29 },
|
||||
{ 5758, KISLEV, 30, YEAR, -1, 5757, KISLEV, 29 },
|
||||
};
|
||||
|
||||
HebrewCalendar cal = new HebrewCalendar(UTC, Locale.getDefault());
|
||||
|
||||
doRollAdd(ROLL, cal, tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behavior of HebrewCalendar.roll
|
||||
* The only real nastiness with roll is the MONTH field, since a year can
|
||||
* have a variable number of months.
|
||||
*/
|
||||
public void TestAdd() {
|
||||
int[][] tests = new int[][] {
|
||||
// input add by output
|
||||
// year month day field amount year month day
|
||||
{ 5759, HESHVAN, 2, MONTH, 1, 5759, KISLEV, 2 }, // non-leap years
|
||||
{ 5759, SHEVAT, 2, MONTH, 1, 5759, ADAR, 2 },
|
||||
{ 5759, SHEVAT, 2, MONTH, 2, 5759, NISAN, 2 },
|
||||
{ 5759, SHEVAT, 2, MONTH, 12, 5760, SHEVAT, 2 },
|
||||
|
||||
{ 5757, HESHVAN, 2, MONTH, 1, 5757, KISLEV, 2 }, // leap years
|
||||
{ 5757, SHEVAT, 2, MONTH, 1, 5757, ADAR_1, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 2, 5757, ADAR, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 3, 5757, NISAN, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 12, 5758, TEVET, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 13, 5758, SHEVAT, 2 },
|
||||
|
||||
{ 5757, KISLEV, 1, DATE, 30, 5757, TEVET, 2 }, // 29-day month
|
||||
{ 5758, KISLEV, 1, DATE, 31, 5758, TEVET, 2 }, // 30-day month
|
||||
};
|
||||
|
||||
HebrewCalendar cal = new HebrewCalendar(UTC, Locale.getDefault());
|
||||
|
||||
doRollAdd(ADD, cal, tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* A huge list of test cases to make sure that computeTime and computeFields
|
||||
* work properly for a wide range of data.
|
||||
*/
|
||||
public void TestCases() {
|
||||
doTestCases(testCases, new HebrewCalendar());
|
||||
}
|
||||
|
||||
static final TestCase[] testCases = {
|
||||
//
|
||||
// Most of these test cases were taken from the back of
|
||||
// "Calendrical Calculations", with some extras added to help
|
||||
// debug a few of the problems that cropped up in development.
|
||||
//
|
||||
// The months in this table are 1-based rather than 0-based,
|
||||
// because it's easier to edit that way.
|
||||
//
|
||||
// Julian Day Era Year Month Day WkDay Hour Min Sec
|
||||
new TestCase(1507231.5, 0, 3174, 12, 10, SUN, 0, 0, 0),
|
||||
new TestCase(1660037.5, 0, 3593, 3, 25, WED, 0, 0, 0),
|
||||
new TestCase(1746893.5, 0, 3831, 1, 3, WED, 0, 0, 0),
|
||||
new TestCase(1770641.5, 0, 3896, 1, 9, SUN, 0, 0, 0),
|
||||
new TestCase(1892731.5, 0, 4230, 4, 18, WED, 0, 0, 0),
|
||||
new TestCase(1931579.5, 0, 4336, 10, 4, MON, 0, 0, 0),
|
||||
new TestCase(1974851.5, 0, 4455, 2, 13, SAT, 0, 0, 0),
|
||||
new TestCase(2091164.5, 0, 4773, 9, 6, SUN, 0, 0, 0),
|
||||
new TestCase(2121509.5, 0, 4856, 9, 23, SUN, 0, 0, 0),
|
||||
new TestCase(2155779.5, 0, 4950, 8, 7, FRI, 0, 0, 0),
|
||||
new TestCase(2174029.5, 0, 5000, 7, 8, SAT, 0, 0, 0),
|
||||
new TestCase(2191584.5, 0, 5048, 8, 21, FRI, 0, 0, 0),
|
||||
new TestCase(2195261.5, 0, 5058, 9, 7, SUN, 0, 0, 0),
|
||||
new TestCase(2229274.5, 0, 5151, 11, 1, SUN, 0, 0, 0),
|
||||
new TestCase(2245580.5, 0, 5196, 5, 7, WED, 0, 0, 0),
|
||||
new TestCase(2266100.5, 0, 5252, 8, 3, SAT, 0, 0, 0),
|
||||
new TestCase(2288542.5, 0, 5314, 1, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2290901.5, 0, 5320, 6, 27, SAT, 0, 0, 0),
|
||||
new TestCase(2323140.5, 0, 5408, 10, 20, WED, 0, 0, 0),
|
||||
new TestCase(2334551.5, 0, 5440, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(2334581.5, 0, 5440, 2, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2334610.5, 0, 5440, 3, 1, SUN, 0, 0, 0),
|
||||
new TestCase(2334639.5, 0, 5440, 4, 1, MON, 0, 0, 0),
|
||||
new TestCase(2334668.5, 0, 5440, 5, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2334698.5, 0, 5440, 6, 1, THU, 0, 0, 0),
|
||||
new TestCase(2334728.5, 0, 5440, 7, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2334757.5, 0, 5440, 8, 1, SUN, 0, 0, 0),
|
||||
new TestCase(2334787.5, 0, 5440, 9, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2334816.5, 0, 5440, 10, 1, WED, 0, 0, 0),
|
||||
new TestCase(2334846.5, 0, 5440, 11, 1, FRI, 0, 0, 0),
|
||||
new TestCase(2334848.5, 0, 5440, 11, 3, SUN, 0, 0, 0),
|
||||
new TestCase(2334934.5, 0, 5441, 1, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2348020.5, 0, 5476, 12, 5, FRI, 0, 0, 0),
|
||||
new TestCase(2366978.5, 0, 5528, 11, 4, SUN, 0, 0, 0),
|
||||
new TestCase(2385648.5, 0, 5579, 12, 11, MON, 0, 0, 0),
|
||||
new TestCase(2392825.5, 0, 5599, 8, 12, WED, 0, 0, 0),
|
||||
new TestCase(2416223.5, 0, 5663, 8, 22, SUN, 0, 0, 0),
|
||||
new TestCase(2425848.5, 0, 5689, 12, 19, SUN, 0, 0, 0),
|
||||
new TestCase(2430266.5, 0, 5702, 1, 8, MON, 0, 0, 0),
|
||||
new TestCase(2430833.5, 0, 5703, 8, 14, MON, 0, 0, 0),
|
||||
new TestCase(2431004.5, 0, 5704, 1, 8, THU, 0, 0, 0),
|
||||
new TestCase(2448698.5, 0, 5752, 7, 12, TUE, 0, 0, 0),
|
||||
new TestCase(2450138.5, 0, 5756, 7, 5, SUN, 0, 0, 0),
|
||||
new TestCase(2465737.5, 0, 5799, 2, 12, WED, 0, 0, 0),
|
||||
new TestCase(2486076.5, 0, 5854, 12, 5, SUN, 0, 0, 0),
|
||||
|
||||
// Additional test cases for bugs found during development
|
||||
// G.YY/MM/DD Era Year Month Day WkDay Hour Min Sec
|
||||
new TestCase(1013, 9, 8, 0, 4774, 1, 1, TUE, 0, 0, 0),
|
||||
new TestCase(1239, 9, 1, 0, 5000, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(1240, 9,18, 0, 5001, 1, 1, TUE, 0, 0, 0),
|
||||
|
||||
// Test cases taken from a table of 14 "year types" in the Help file
|
||||
// of the application "Hebrew Calendar"
|
||||
new TestCase(2456187.5, 0, 5773, 1, 1, MON, 0, 0, 0),
|
||||
new TestCase(2459111.5, 0, 5781, 1, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2453647.5, 0, 5766, 1, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2462035.5, 0, 5789, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(2458756.5, 0, 5780, 1, 1, MON, 0, 0, 0),
|
||||
new TestCase(2460586.5, 0, 5785, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(2463864.5, 0, 5794, 1, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2463481.5, 0, 5793, 1, 1, MON, 0, 0, 0),
|
||||
new TestCase(2470421.5, 0, 5812, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(2460203.5, 0, 5784, 1, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2459464.5, 0, 5782, 1, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2467142.5, 0, 5803, 1, 1, MON, 0, 0, 0),
|
||||
new TestCase(2455448.5, 0, 5771, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(2487223.5, 0, 5858, 1, 1, SAT, 0, 0, 0),
|
||||
};
|
||||
|
||||
|
||||
};
|
128
icu4j/src/com/ibm/icu/dev/test/calendar/IslamicTest.java
Executable file
128
icu4j/src/com/ibm/icu/dev/test/calendar/IslamicTest.java
Executable file
@ -0,0 +1,128 @@
|
||||
/**
|
||||
* (C) Copyright IBM Corp. 1998. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.test.calendar;
|
||||
|
||||
import com.ibm.test.*;
|
||||
import java.util.*;
|
||||
import java.text.*;
|
||||
import com.ibm.util.*;
|
||||
|
||||
/**
|
||||
* Tests for the <code>IslamicCalendar</code> class.
|
||||
*/
|
||||
public class IslamicTest extends CalendarTest {
|
||||
public static void main(String args[]) throws Exception {
|
||||
new IslamicTest().run(args);
|
||||
}
|
||||
|
||||
/** Constants to save typing. */
|
||||
public static final int MUHARRAM = IslamicCalendar.MUHARRAM;
|
||||
public static final int SAFAR = IslamicCalendar.SAFAR;
|
||||
public static final int RABI_1 = IslamicCalendar.RABI_1;
|
||||
public static final int RABI_2 = IslamicCalendar.RABI_2;
|
||||
public static final int JUMADA_1 = IslamicCalendar.JUMADA_1;
|
||||
public static final int JUMADA_2 = IslamicCalendar.JUMADA_2;
|
||||
public static final int RAJAB = IslamicCalendar.RAJAB;
|
||||
public static final int SHABAN = IslamicCalendar.SHABAN;
|
||||
public static final int RAMADAN = IslamicCalendar.RAMADAN;
|
||||
public static final int SHAWWAL = IslamicCalendar.SHAWWAL;
|
||||
public static final int QIDAH = IslamicCalendar.DHU_AL_QIDAH;
|
||||
public static final int HIJJAH = IslamicCalendar.DHU_AL_HIJJAH;
|
||||
|
||||
public void TestRoll() {
|
||||
int[][] tests = new int[][] {
|
||||
// input roll by output
|
||||
// year month day field amount year month day
|
||||
|
||||
{ 0001, QIDAH, 2, MONTH, 1, 0001, HIJJAH, 2 }, // non-leap years
|
||||
{ 0001, QIDAH, 2, MONTH, 2, 0001, MUHARRAM, 2 },
|
||||
{ 0001, QIDAH, 2, MONTH, -1, 0001, SHAWWAL, 2 },
|
||||
{ 0001, MUHARRAM, 2, MONTH, 12, 0001, MUHARRAM, 2 },
|
||||
{ 0001, MUHARRAM, 2, MONTH, 13, 0001, SAFAR, 2 },
|
||||
|
||||
{ 0001, HIJJAH, 1, DATE, 30, 0001, HIJJAH, 2 }, // 29-day month
|
||||
{ 0002, HIJJAH, 1, DATE, 31, 0002, HIJJAH, 2 }, // 30-day month
|
||||
|
||||
// Try some rolls that require other fields to be adjusted
|
||||
{ 0001, MUHARRAM, 30, MONTH, 1, 0001, SAFAR, 29 },
|
||||
{ 0002, HIJJAH, 30, YEAR, -1, 0001, HIJJAH, 29 },
|
||||
};
|
||||
|
||||
IslamicCalendar cal = newCivil();
|
||||
|
||||
doRollAdd(ROLL, cal, tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* A huge list of test cases to make sure that computeTime and computeFields
|
||||
* work properly for a wide range of data in the civil calendar.
|
||||
*/
|
||||
public void TestCivilCases()
|
||||
{
|
||||
final TestCase[] tests = {
|
||||
//
|
||||
// Most of these test cases were taken from the back of
|
||||
// "Calendrical Calculations", with some extras added to help
|
||||
// debug a few of the problems that cropped up in development.
|
||||
//
|
||||
// The months in this table are 1-based rather than 0-based,
|
||||
// because it's easier to edit that way.
|
||||
// Islamic
|
||||
// Julian Day Era Year Month Day WkDay Hour Min Sec
|
||||
new TestCase(1507231.5, 0, -1245, 12, 9, SUN, 0, 0, 0),
|
||||
new TestCase(1660037.5, 0, -813, 2, 23, WED, 0, 0, 0),
|
||||
new TestCase(1746893.5, 0, -568, 4, 1, WED, 0, 0, 0),
|
||||
new TestCase(1770641.5, 0, -501, 4, 6, SUN, 0, 0, 0),
|
||||
new TestCase(1892731.5, 0, -157, 10, 17, WED, 0, 0, 0),
|
||||
new TestCase(1931579.5, 0, -47, 6, 3, MON, 0, 0, 0),
|
||||
new TestCase(1974851.5, 0, 75, 7, 13, SAT, 0, 0, 0),
|
||||
new TestCase(2091164.5, 0, 403, 10, 5, SUN, 0, 0, 0),
|
||||
new TestCase(2121509.5, 0, 489, 5, 22, SUN, 0, 0, 0),
|
||||
new TestCase(2155779.5, 0, 586, 2, 7, FRI, 0, 0, 0),
|
||||
new TestCase(2174029.5, 0, 637, 8, 7, SAT, 0, 0, 0),
|
||||
new TestCase(2191584.5, 0, 687, 2, 20, FRI, 0, 0, 0),
|
||||
new TestCase(2195261.5, 0, 697, 7, 7, SUN, 0, 0, 0),
|
||||
new TestCase(2229274.5, 0, 793, 7, 1, SUN, 0, 0, 0),
|
||||
new TestCase(2245580.5, 0, 839, 7, 6, WED, 0, 0, 0),
|
||||
new TestCase(2266100.5, 0, 897, 6, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2288542.5, 0, 960, 9, 30, SAT, 0, 0, 0),
|
||||
new TestCase(2290901.5, 0, 967, 5, 27, SAT, 0, 0, 0),
|
||||
new TestCase(2323140.5, 0, 1058, 5, 18, WED, 0, 0, 0),
|
||||
new TestCase(2334848.5, 0, 1091, 6, 2, SUN, 0, 0, 0),
|
||||
new TestCase(2348020.5, 0, 1128, 8, 4, FRI, 0, 0, 0),
|
||||
new TestCase(2366978.5, 0, 1182, 2, 3, SUN, 0, 0, 0),
|
||||
new TestCase(2385648.5, 0, 1234, 10, 10, MON, 0, 0, 0),
|
||||
new TestCase(2392825.5, 0, 1255, 1, 11, WED, 0, 0, 0),
|
||||
new TestCase(2416223.5, 0, 1321, 1, 21, SUN, 0, 0, 0),
|
||||
new TestCase(2425848.5, 0, 1348, 3, 19, SUN, 0, 0, 0),
|
||||
new TestCase(2430266.5, 0, 1360, 9, 8, MON, 0, 0, 0),
|
||||
new TestCase(2430833.5, 0, 1362, 4, 13, MON, 0, 0, 0),
|
||||
new TestCase(2431004.5, 0, 1362, 10, 7, THU, 0, 0, 0),
|
||||
new TestCase(2448698.5, 0, 1412, 9, 13, TUE, 0, 0, 0),
|
||||
new TestCase(2450138.5, 0, 1416, 10, 5, SUN, 0, 0, 0),
|
||||
new TestCase(2465737.5, 0, 1460, 10, 12, WED, 0, 0, 0),
|
||||
new TestCase(2486076.5, 0, 1518, 3, 5, SUN, 0, 0, 0),
|
||||
};
|
||||
|
||||
IslamicCalendar civilCalendar = newCivil();
|
||||
civilCalendar.setLenient(true);
|
||||
doTestCases(tests, civilCalendar);
|
||||
}
|
||||
|
||||
private static IslamicCalendar newCivil() {
|
||||
IslamicCalendar civilCalendar = new IslamicCalendar();
|
||||
civilCalendar.setCivil(true);
|
||||
return civilCalendar;
|
||||
}
|
||||
|
||||
};
|
217
icu4j/src/com/ibm/icu/dev/test/calendar/TestCase.java
Executable file
217
icu4j/src/com/ibm/icu/dev/test/calendar/TestCase.java
Executable file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* @(#)$RCSfile: TestCase.java,v $ $Revision: 1.1 $ $Date: 2000/03/01 18:32:32 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998 - All Rights Reserved
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*
|
||||
*/
|
||||
package com.ibm.test.calendar;
|
||||
|
||||
import com.ibm.test.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Date;
|
||||
import java.util.SimpleTimeZone;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* A dummy <code>Calendar</code> subclass that is useful for testing
|
||||
* new calendars. A <code>TestCase</code> object is used to hold the
|
||||
* field and millisecond values that the calendar should have at one
|
||||
* particular instant in time. The applyFields and applyTime
|
||||
* methods are used to apply these settings to the calendar object being
|
||||
* tested, and the equals and fieldsEqual methods are used to ensure
|
||||
* that the calendar has ended up in the right state.
|
||||
*/
|
||||
public class TestCase extends Calendar {
|
||||
|
||||
/**
|
||||
* Initialize a TestCase object using a julian day number and
|
||||
* the corresponding fields for the calendar being tested.
|
||||
*
|
||||
* @param era The ERA field of tested calendar on the given julian day
|
||||
* @param year The YEAR field of tested calendar on the given julian day
|
||||
* @param month The MONTH (0-based) field of tested calendar on the given julian day
|
||||
* @param day The DAY_OF_MONTH field of tested calendar on the given julian day
|
||||
* @param dayOfWeek The DAY_OF_WEEK field of tested calendar on the given julian day
|
||||
* @param hour The HOUR field of tested calendar on the given julian day
|
||||
* @param min The MINUTE field of tested calendar on the given julian day
|
||||
* @param sec The SECOND field of tested calendar on the given julian day
|
||||
*/
|
||||
public TestCase(double julian,
|
||||
int era, int year, int month, int day,
|
||||
int dayOfWeek,
|
||||
int hour, int min, int sec)
|
||||
{
|
||||
super(UTC, Locale.getDefault());
|
||||
|
||||
setTime(new Date(JULIAN_EPOCH + (long)(DAY_MS * julian)));
|
||||
|
||||
set(ERA, era);
|
||||
set(YEAR, year);
|
||||
set(MONTH, month - 1);
|
||||
set(DATE, day);
|
||||
set(DAY_OF_WEEK, dayOfWeek);
|
||||
set(HOUR, hour);
|
||||
set(MINUTE, min);
|
||||
set(SECOND, sec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a TestCase object using a Gregorian year/month/day and
|
||||
* the corresponding fields for the calendar being tested.
|
||||
*
|
||||
* @param gregYear The Gregorian year of the date to be tested
|
||||
* @param gregMonth The Gregorian month of the date to be tested
|
||||
* @param gregDay The Gregorian day of the month of the date to be tested
|
||||
*
|
||||
* @param era The ERA field of tested calendar on the given gregorian date
|
||||
* @param year The YEAR field of tested calendar on the given gregorian date
|
||||
* @param month The MONTH (0-based) field of tested calendar on the given gregorian date
|
||||
* @param day The DAY_OF_MONTH field of tested calendar on the given gregorian date
|
||||
* @param dayOfWeek The DAY_OF_WEEK field of tested calendar on the given gregorian date
|
||||
* @param hour The HOUR field of tested calendar on the given gregorian date
|
||||
* @param min The MINUTE field of tested calendar on the given gregorian date
|
||||
* @param sec The SECOND field of tested calendar on the given gregorian date
|
||||
*/
|
||||
public TestCase(int gregYear, int gregMonth, int gregDay,
|
||||
int era, int year, int month, int day,
|
||||
int dayOfWeek,
|
||||
int hour, int min, int sec)
|
||||
{
|
||||
super(UTC, Locale.getDefault());
|
||||
|
||||
GregorianCalendar greg = new GregorianCalendar(UTC, Locale.getDefault());
|
||||
greg.clear();
|
||||
greg.set(gregYear, gregMonth-1, gregDay);
|
||||
setTime(greg.getTime());
|
||||
|
||||
set(ERA, era);
|
||||
set(YEAR, year);
|
||||
set(MONTH, month - 1);
|
||||
set(DATE, day);
|
||||
set(DAY_OF_WEEK, dayOfWeek);
|
||||
set(HOUR, hour);
|
||||
set(MINUTE, min);
|
||||
set(SECOND, sec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply this test case's field values to another calendar
|
||||
* by calling its set method for each field. This is useful in combination
|
||||
* with the equal method.
|
||||
*
|
||||
* @see #equal
|
||||
*/
|
||||
public void applyFields(Calendar c) {
|
||||
c.set(ERA, fields[ERA]);
|
||||
c.set(YEAR, fields[YEAR]);
|
||||
c.set(MONTH, fields[MONTH]);
|
||||
c.set(DATE, fields[DATE]);
|
||||
c.set(HOUR, fields[HOUR]);
|
||||
c.set(MINUTE, fields[MINUTE]);
|
||||
c.set(SECOND, fields[SECOND]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply this test case's time in milliseconds to another calendar
|
||||
* by calling its setTime method. This is useful in combination
|
||||
* with fieldsEqual
|
||||
*
|
||||
* @see #fieldsEqual
|
||||
*/
|
||||
public void applyTime(Calendar c) {
|
||||
c.setTime(new Date(time));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the fields of this calendar
|
||||
* are the same as that of the other calendar. This method is useful
|
||||
* for determining whether the other calendar's computeFields method
|
||||
* works properly. For example:
|
||||
* <pre>
|
||||
* Calendar testCalendar = ...
|
||||
* TestCase case = ...
|
||||
* case.applyTime(testCalendar);
|
||||
* if (!case.fieldsEqual(testCalendar)) {
|
||||
* // Error!
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @see #applyTime
|
||||
*/
|
||||
public boolean fieldsEqual(Calendar c) {
|
||||
for (int i=0; i < Calendar.FIELD_COUNT; i++) {
|
||||
if (isSet(i) && get(i) != c.get(i)) {
|
||||
System.out.println("field " + i + ": expected " + get(i) + ", got " + c.get(i));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether time in milliseconds of this calendar
|
||||
* is the same as that of the other calendar. This method is useful
|
||||
* for determining whether the other calendar's computeTime method
|
||||
* works properly. For example:
|
||||
* <pre>
|
||||
* Calendar testCalendar = ...
|
||||
* TestCase case = ...
|
||||
* case.applyFields(testCalendar);
|
||||
* if (!case.equals(testCalendar)) {
|
||||
* // Error!
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @see #applyFields
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
return time == ((Calendar)obj).getTime().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether time of this calendar (as returned by getTime)
|
||||
* is before that of the specified calendar
|
||||
*/
|
||||
public boolean before(Object obj) {
|
||||
return time < ((Calendar)obj).getTime().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether time of this calendar (as returned by getTime)
|
||||
* is after that of the specified calendar
|
||||
*/
|
||||
public boolean after(Object obj) {
|
||||
return time > ((Calendar)obj).getTime().getTime();
|
||||
}
|
||||
|
||||
// This object is only pretending to be a Calendar; it doesn't do any real
|
||||
// calendar computatations. But we have to pretend it does, because Calendar
|
||||
// declares all of these abstract methods....
|
||||
protected void computeTime() {}
|
||||
protected void computeFields() {}
|
||||
public void roll(int field, boolean up) {}
|
||||
public void add(int field, int amt) {}
|
||||
public int getMinimum(int field) { return 0; }
|
||||
public int getMaximum(int field) { return 0; }
|
||||
public int getGreatestMinimum(int field) { return 0; }
|
||||
public int getLeastMaximum(int field) { return 0; }
|
||||
|
||||
private static final int SECOND_MS = 1000;
|
||||
private static final int MINUTE_MS = 60*SECOND_MS;
|
||||
private static final int HOUR_MS = 60*MINUTE_MS;
|
||||
private static final long DAY_MS = 24*HOUR_MS;
|
||||
private static final long JULIAN_EPOCH = -210866760000000L; // 1/1/4713 BC 12:00
|
||||
|
||||
public final static SimpleTimeZone UTC = new SimpleTimeZone(0, "GMT");
|
||||
}
|
62
icu4j/src/com/ibm/test/calendar/AstroTest.java
Executable file
62
icu4j/src/com/ibm/test/calendar/AstroTest.java
Executable file
@ -0,0 +1,62 @@
|
||||
package com.ibm.test.calendar;
|
||||
|
||||
// AstroTest
|
||||
|
||||
import com.ibm.test.*;
|
||||
import java.util.*;
|
||||
import com.ibm.util.*;
|
||||
|
||||
import com.ibm.util.CalendarAstronomer.*;
|
||||
|
||||
// TODO: try finding next new moon after 07/28/1984 16:00 GMT
|
||||
|
||||
public class AstroTest extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new AstroTest().run(args);
|
||||
}
|
||||
|
||||
static final double PI = Math.PI;
|
||||
|
||||
static GregorianCalendar gc = new GregorianCalendar(new SimpleTimeZone(0, "UTC"));
|
||||
static CalendarAstronomer astro = new CalendarAstronomer();
|
||||
|
||||
public void TestSolarLongitude() {
|
||||
final double tests[][] = {
|
||||
{ 1980, 7, 27, 00, 00, 124.114347 },
|
||||
{ 1988, 7, 27, 00, 00, 124.187732 },
|
||||
};
|
||||
logln("");
|
||||
for (int i = 0; i < tests.length; i++) {
|
||||
gc.clear();
|
||||
gc.set((int)tests[i][0], (int)tests[i][1]-1, (int)tests[i][2], (int)tests[i][3], (int) tests[i][4]);
|
||||
|
||||
astro.setDate(gc.getTime());
|
||||
|
||||
double longitude = astro.getSunLongitude();
|
||||
|
||||
Equatorial result = astro.getSunPosition();
|
||||
}
|
||||
}
|
||||
|
||||
public void TestLunarPosition() {
|
||||
final double tests[][] = {
|
||||
{ 1979, 2, 26, 16, 00, 0, 0 },
|
||||
};
|
||||
logln("");
|
||||
|
||||
for (int i = 0; i < tests.length; i++) {
|
||||
gc.clear();
|
||||
gc.set((int)tests[i][0], (int)tests[i][1]-1, (int)tests[i][2], (int)tests[i][3], (int) tests[i][4]);
|
||||
astro.setDate(gc.getTime());
|
||||
|
||||
Equatorial result = astro.getMoonPosition();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void TestCoordinates() {
|
||||
Equatorial result = astro.eclipticToEquatorial(139.686111 * PI/ 180.0, 4.875278* PI / 180.0);
|
||||
logln("result is " + result + "; " + result.toHmsString());
|
||||
}
|
||||
|
||||
}
|
174
icu4j/src/com/ibm/test/calendar/CalendarTest.java
Executable file
174
icu4j/src/com/ibm/test/calendar/CalendarTest.java
Executable file
@ -0,0 +1,174 @@
|
||||
/*
|
||||
* @(#)$RCSfile: CalendarTest.java,v $ $Revision: 1.1 $ $Date: 2000/03/01 18:32:30 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998 - All Rights Reserved
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.ibm.test.calendar;
|
||||
|
||||
import com.ibm.test.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import com.ibm.util.*;
|
||||
|
||||
/**
|
||||
* A base class for classes that test individual Calendar subclasses.
|
||||
* Defines various useful utility methods and constants
|
||||
*/
|
||||
public class CalendarTest extends TestFmwk {
|
||||
|
||||
// Constants for use by subclasses, solely to save typing
|
||||
public final static int SUN = Calendar.SUNDAY;
|
||||
public final static int MON = Calendar.MONDAY;
|
||||
public final static int TUE = Calendar.TUESDAY;
|
||||
public final static int WED = Calendar.WEDNESDAY;
|
||||
public final static int THU = Calendar.THURSDAY;
|
||||
public final static int FRI = Calendar.FRIDAY;
|
||||
public final static int SAT = Calendar.SATURDAY;
|
||||
|
||||
public final static int ERA = Calendar.ERA;
|
||||
public final static int YEAR = Calendar.YEAR;
|
||||
public final static int MONTH = Calendar.MONTH;
|
||||
public final static int DATE = Calendar.DATE;
|
||||
public final static int HOUR = Calendar.HOUR;
|
||||
public final static int MINUTE = Calendar.MINUTE;
|
||||
public final static int SECOND = Calendar.SECOND;
|
||||
public final static int DOY = Calendar.DAY_OF_YEAR;
|
||||
public final static int WOY = Calendar.WEEK_OF_YEAR;
|
||||
public final static int WOM = Calendar.WEEK_OF_MONTH;
|
||||
public final static int DOW = Calendar.DAY_OF_WEEK;
|
||||
public final static int DOWM = Calendar.DAY_OF_WEEK_IN_MONTH;
|
||||
|
||||
public final static SimpleTimeZone UTC = new SimpleTimeZone(0, "GMT");
|
||||
|
||||
final String pattern = "E, MM/dd/yyyy G HH:mm:ss.S z";
|
||||
|
||||
/**
|
||||
* Iterates through a list of calendar <code>TestCase</code> objects and
|
||||
* makes sure that the time-to-fields and fields-to-time calculations work
|
||||
* correnctly for the values in each test case.
|
||||
*/
|
||||
public void doTestCases(TestCase[] cases, Calendar cal)
|
||||
{
|
||||
cal.setTimeZone(UTC);
|
||||
|
||||
// Get a format to use for printing dates in the calendar system we're testing
|
||||
// TODO: This is kind of ugly right now .
|
||||
DateFormat format = IBMCalendar.getDateTimeFormat(cal, DateFormat.SHORT, -1, Locale.getDefault());
|
||||
|
||||
((SimpleDateFormat)format).applyPattern(pattern);
|
||||
DateFormat testFmt = (DateFormat)format.clone();
|
||||
|
||||
// This format is used for pringing Gregorian dates. This one is easier
|
||||
DateFormat gregFormat = new SimpleDateFormat(pattern);
|
||||
gregFormat.setTimeZone(UTC);
|
||||
|
||||
// Now iterate through the test cases and see what happens
|
||||
for (int i = 0; i < cases.length; i++)
|
||||
{
|
||||
TestCase test = cases[i];
|
||||
testFmt.setCalendar(test);
|
||||
|
||||
//
|
||||
// First we want to make sure that the millis -> fields calculation works
|
||||
// test.applyTime will call setTime() on the calendar object, and
|
||||
// test.fieldsEqual will retrieve all of the field values and make sure
|
||||
// that they're the same as the ones in the testcase
|
||||
//
|
||||
test.applyTime(cal);
|
||||
if (!test.fieldsEqual(cal)) {
|
||||
errln("ERROR: millis --> fields calculation incorrect for "
|
||||
+ gregFormat.format(test.getTime()));
|
||||
logln(" expected " + testFmt.format(test.getTime()));
|
||||
logln(" got " + format.format(cal.getTime()) );
|
||||
}
|
||||
else {
|
||||
//
|
||||
// If that was OK, check the fields -> millis calculation
|
||||
// test.applyFields will set all of the calendar's fields to
|
||||
// match those in the test case.
|
||||
//
|
||||
cal.setTime(new Date(0));
|
||||
test.applyFields(cal);
|
||||
|
||||
if (!test.equals(cal)) {
|
||||
errln("ERROR: fields --> millis calculation incorrect for "
|
||||
+ testFmt.format(test.getTime()));
|
||||
logln(" expected " + test.getTime().getTime());
|
||||
logln(" got " + cal.getTime().getTime() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public final boolean ROLL = true;
|
||||
static public final boolean ADD = false;
|
||||
|
||||
/**
|
||||
* Process test cases for <code>add</code> and <code>roll</code> methods.
|
||||
* Each test case is an array of integers, as follows:
|
||||
* <ul>
|
||||
* <li>0: input year
|
||||
* <li>1: month (zero-based)
|
||||
* <li>2: day
|
||||
* <li>3: field to roll or add to
|
||||
* <li>4: amount to roll or add
|
||||
* <li>5: result year
|
||||
* <li>6: month (zero-based)
|
||||
* <li>7: day
|
||||
* </ul>
|
||||
* For example:
|
||||
* <pre>
|
||||
* // input add by output
|
||||
* // year month day field amount year month day
|
||||
* { 5759, HESHVAN, 2, MONTH, 1, 5759, KISLEV, 2 },
|
||||
* </pre>
|
||||
*
|
||||
* @param roll <code>true</code> or <code>ROLL</code> to test the <code>roll</code> method;
|
||||
* <code>false</code> or <code>ADD</code> to test the <code>add</code method
|
||||
*/
|
||||
public void doRollAdd(boolean roll, IBMCalendar cal, int[][] tests)
|
||||
{
|
||||
String name = roll ? "rolling" : "adding";
|
||||
|
||||
for (int i = 0; i < tests.length; i++) {
|
||||
int[] test = tests[i];
|
||||
|
||||
cal.clear();
|
||||
cal.set(test[0], test[1], test[2]);
|
||||
|
||||
if (roll) {
|
||||
cal.roll(test[3], test[4]);
|
||||
} else {
|
||||
cal.add(test[3], test[4]);
|
||||
}
|
||||
|
||||
if (cal.get(YEAR) != test[5] || cal.get(MONTH) != test[6]
|
||||
|| cal.get(DATE) != test[7])
|
||||
{
|
||||
errln("Error " + name + " "+ ymdToString(test[0], test[1], test[2])
|
||||
+ " field " + test[3] + " by " + test[4]
|
||||
+ ": expected " + ymdToString(test[5], test[6], test[7])
|
||||
+ ", got " + ymdToString(cal.get(YEAR), cal.get(MONTH), cal.get(DATE)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert year,month,day values to the form "year/month/day".
|
||||
* On input the month value is zero-based, but in the result string it is one-based.
|
||||
*/
|
||||
static public String ymdToString(int year, int month, int day) {
|
||||
return "" + year + "/" + (month+1) + "/" + day;
|
||||
}
|
||||
};
|
19
icu4j/src/com/ibm/test/calendar/GNUmakefile
Executable file
19
icu4j/src/com/ibm/test/calendar/GNUmakefile
Executable file
@ -0,0 +1,19 @@
|
||||
#
|
||||
# @(#)$RCSfile: GNUmakefile,v $ $Revision: 1.1 $ $Date: 2000/03/01 18:32:30 $
|
||||
#
|
||||
|
||||
TOPDIR= ../../../../..
|
||||
PACKAGE= com.ibm.test.calendar
|
||||
|
||||
include $(TOPDIR)/src/build/defs.gmk
|
||||
|
||||
|
||||
FILES_java= $(TARGDIR)/TestCase.java \
|
||||
$(TARGDIR)/CalendarTest.java \
|
||||
$(TARGDIR)/AstroTest.java \
|
||||
$(TARGDIR)/HebrewTest.java \
|
||||
$(TARGDIR)/IslamicTest.java \
|
||||
|
||||
|
||||
|
||||
include $(TOPDIR)/src/build/rules.gmk
|
204
icu4j/src/com/ibm/test/calendar/HebrewTest.java
Executable file
204
icu4j/src/com/ibm/test/calendar/HebrewTest.java
Executable file
@ -0,0 +1,204 @@
|
||||
/**
|
||||
* @(#)$RCSFile$ $Revision: 1.1 $ $Date: 2000/03/01 18:32:31 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
|
||||
package com.ibm.test.calendar;
|
||||
|
||||
import com.ibm.test.*;
|
||||
import java.util.*;
|
||||
import java.text.*;
|
||||
import com.ibm.util.*;
|
||||
|
||||
/**
|
||||
* Tests for the <code>HebrewCalendar</code> class.
|
||||
*/
|
||||
public class HebrewTest extends CalendarTest {
|
||||
public static void main(String args[]) throws Exception {
|
||||
new HebrewTest().run(args);
|
||||
}
|
||||
|
||||
// Constants to save typing.
|
||||
public static final int TISHRI = HebrewCalendar.TISHRI;
|
||||
public static final int HESHVAN = HebrewCalendar.HESHVAN;
|
||||
public static final int KISLEV = HebrewCalendar.KISLEV;
|
||||
public static final int TEVET = HebrewCalendar.TEVET;
|
||||
public static final int SHEVAT = HebrewCalendar.SHEVAT;
|
||||
public static final int ADAR_1 = HebrewCalendar.ADAR_1;
|
||||
public static final int ADAR = HebrewCalendar.ADAR;
|
||||
public static final int NISAN = HebrewCalendar.NISAN;
|
||||
public static final int IYAR = HebrewCalendar.IYAR;
|
||||
public static final int SIVAN = HebrewCalendar.SIVAN;
|
||||
public static final int TAMUZ = HebrewCalendar.TAMUZ;
|
||||
public static final int AV = HebrewCalendar.AV;
|
||||
public static final int ELUL = HebrewCalendar.ELUL;
|
||||
|
||||
/**
|
||||
* Test the behavior of HebrewCalendar.roll
|
||||
* The only real nastiness with roll is the MONTH field, since a year can
|
||||
* have a variable number of months.
|
||||
*/
|
||||
public void TestRoll() {
|
||||
int[][] tests = new int[][] {
|
||||
// input roll by output
|
||||
// year month day field amount year month day
|
||||
|
||||
{ 5759, HESHVAN, 2, MONTH, 1, 5759, KISLEV, 2 }, // non-leap years
|
||||
{ 5759, SHEVAT, 2, MONTH, 1, 5759, ADAR, 2 },
|
||||
{ 5759, SHEVAT, 2, MONTH, 2, 5759, NISAN, 2 },
|
||||
{ 5759, SHEVAT, 2, MONTH, 12, 5759, SHEVAT, 2 },
|
||||
|
||||
{ 5757, HESHVAN, 2, MONTH, 1, 5757, KISLEV, 2 }, // leap years
|
||||
{ 5757, SHEVAT, 2, MONTH, 1, 5757, ADAR_1, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 2, 5757, ADAR, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 3, 5757, NISAN, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 12, 5757, TEVET, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 13, 5757, SHEVAT, 2 },
|
||||
|
||||
{ 5757, KISLEV, 1, DATE, 30, 5757, KISLEV, 2 }, // 29-day month
|
||||
{ 5758, KISLEV, 1, DATE, 31, 5758, KISLEV, 2 }, // 30-day month
|
||||
|
||||
// Try some other fields too
|
||||
{ 5757, TISHRI, 1, YEAR, 1, 5758, TISHRI, 1 },
|
||||
|
||||
|
||||
// Try some rolls that require other fields to be adjusted
|
||||
{ 5757, TISHRI, 30, MONTH, 1, 5757, HESHVAN, 29 },
|
||||
{ 5758, KISLEV, 30, YEAR, -1, 5757, KISLEV, 29 },
|
||||
};
|
||||
|
||||
HebrewCalendar cal = new HebrewCalendar(UTC, Locale.getDefault());
|
||||
|
||||
doRollAdd(ROLL, cal, tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behavior of HebrewCalendar.roll
|
||||
* The only real nastiness with roll is the MONTH field, since a year can
|
||||
* have a variable number of months.
|
||||
*/
|
||||
public void TestAdd() {
|
||||
int[][] tests = new int[][] {
|
||||
// input add by output
|
||||
// year month day field amount year month day
|
||||
{ 5759, HESHVAN, 2, MONTH, 1, 5759, KISLEV, 2 }, // non-leap years
|
||||
{ 5759, SHEVAT, 2, MONTH, 1, 5759, ADAR, 2 },
|
||||
{ 5759, SHEVAT, 2, MONTH, 2, 5759, NISAN, 2 },
|
||||
{ 5759, SHEVAT, 2, MONTH, 12, 5760, SHEVAT, 2 },
|
||||
|
||||
{ 5757, HESHVAN, 2, MONTH, 1, 5757, KISLEV, 2 }, // leap years
|
||||
{ 5757, SHEVAT, 2, MONTH, 1, 5757, ADAR_1, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 2, 5757, ADAR, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 3, 5757, NISAN, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 12, 5758, TEVET, 2 },
|
||||
{ 5757, SHEVAT, 2, MONTH, 13, 5758, SHEVAT, 2 },
|
||||
|
||||
{ 5757, KISLEV, 1, DATE, 30, 5757, TEVET, 2 }, // 29-day month
|
||||
{ 5758, KISLEV, 1, DATE, 31, 5758, TEVET, 2 }, // 30-day month
|
||||
};
|
||||
|
||||
HebrewCalendar cal = new HebrewCalendar(UTC, Locale.getDefault());
|
||||
|
||||
doRollAdd(ADD, cal, tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* A huge list of test cases to make sure that computeTime and computeFields
|
||||
* work properly for a wide range of data.
|
||||
*/
|
||||
public void TestCases() {
|
||||
doTestCases(testCases, new HebrewCalendar());
|
||||
}
|
||||
|
||||
static final TestCase[] testCases = {
|
||||
//
|
||||
// Most of these test cases were taken from the back of
|
||||
// "Calendrical Calculations", with some extras added to help
|
||||
// debug a few of the problems that cropped up in development.
|
||||
//
|
||||
// The months in this table are 1-based rather than 0-based,
|
||||
// because it's easier to edit that way.
|
||||
//
|
||||
// Julian Day Era Year Month Day WkDay Hour Min Sec
|
||||
new TestCase(1507231.5, 0, 3174, 12, 10, SUN, 0, 0, 0),
|
||||
new TestCase(1660037.5, 0, 3593, 3, 25, WED, 0, 0, 0),
|
||||
new TestCase(1746893.5, 0, 3831, 1, 3, WED, 0, 0, 0),
|
||||
new TestCase(1770641.5, 0, 3896, 1, 9, SUN, 0, 0, 0),
|
||||
new TestCase(1892731.5, 0, 4230, 4, 18, WED, 0, 0, 0),
|
||||
new TestCase(1931579.5, 0, 4336, 10, 4, MON, 0, 0, 0),
|
||||
new TestCase(1974851.5, 0, 4455, 2, 13, SAT, 0, 0, 0),
|
||||
new TestCase(2091164.5, 0, 4773, 9, 6, SUN, 0, 0, 0),
|
||||
new TestCase(2121509.5, 0, 4856, 9, 23, SUN, 0, 0, 0),
|
||||
new TestCase(2155779.5, 0, 4950, 8, 7, FRI, 0, 0, 0),
|
||||
new TestCase(2174029.5, 0, 5000, 7, 8, SAT, 0, 0, 0),
|
||||
new TestCase(2191584.5, 0, 5048, 8, 21, FRI, 0, 0, 0),
|
||||
new TestCase(2195261.5, 0, 5058, 9, 7, SUN, 0, 0, 0),
|
||||
new TestCase(2229274.5, 0, 5151, 11, 1, SUN, 0, 0, 0),
|
||||
new TestCase(2245580.5, 0, 5196, 5, 7, WED, 0, 0, 0),
|
||||
new TestCase(2266100.5, 0, 5252, 8, 3, SAT, 0, 0, 0),
|
||||
new TestCase(2288542.5, 0, 5314, 1, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2290901.5, 0, 5320, 6, 27, SAT, 0, 0, 0),
|
||||
new TestCase(2323140.5, 0, 5408, 10, 20, WED, 0, 0, 0),
|
||||
new TestCase(2334551.5, 0, 5440, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(2334581.5, 0, 5440, 2, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2334610.5, 0, 5440, 3, 1, SUN, 0, 0, 0),
|
||||
new TestCase(2334639.5, 0, 5440, 4, 1, MON, 0, 0, 0),
|
||||
new TestCase(2334668.5, 0, 5440, 5, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2334698.5, 0, 5440, 6, 1, THU, 0, 0, 0),
|
||||
new TestCase(2334728.5, 0, 5440, 7, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2334757.5, 0, 5440, 8, 1, SUN, 0, 0, 0),
|
||||
new TestCase(2334787.5, 0, 5440, 9, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2334816.5, 0, 5440, 10, 1, WED, 0, 0, 0),
|
||||
new TestCase(2334846.5, 0, 5440, 11, 1, FRI, 0, 0, 0),
|
||||
new TestCase(2334848.5, 0, 5440, 11, 3, SUN, 0, 0, 0),
|
||||
new TestCase(2334934.5, 0, 5441, 1, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2348020.5, 0, 5476, 12, 5, FRI, 0, 0, 0),
|
||||
new TestCase(2366978.5, 0, 5528, 11, 4, SUN, 0, 0, 0),
|
||||
new TestCase(2385648.5, 0, 5579, 12, 11, MON, 0, 0, 0),
|
||||
new TestCase(2392825.5, 0, 5599, 8, 12, WED, 0, 0, 0),
|
||||
new TestCase(2416223.5, 0, 5663, 8, 22, SUN, 0, 0, 0),
|
||||
new TestCase(2425848.5, 0, 5689, 12, 19, SUN, 0, 0, 0),
|
||||
new TestCase(2430266.5, 0, 5702, 1, 8, MON, 0, 0, 0),
|
||||
new TestCase(2430833.5, 0, 5703, 8, 14, MON, 0, 0, 0),
|
||||
new TestCase(2431004.5, 0, 5704, 1, 8, THU, 0, 0, 0),
|
||||
new TestCase(2448698.5, 0, 5752, 7, 12, TUE, 0, 0, 0),
|
||||
new TestCase(2450138.5, 0, 5756, 7, 5, SUN, 0, 0, 0),
|
||||
new TestCase(2465737.5, 0, 5799, 2, 12, WED, 0, 0, 0),
|
||||
new TestCase(2486076.5, 0, 5854, 12, 5, SUN, 0, 0, 0),
|
||||
|
||||
// Additional test cases for bugs found during development
|
||||
// G.YY/MM/DD Era Year Month Day WkDay Hour Min Sec
|
||||
new TestCase(1013, 9, 8, 0, 4774, 1, 1, TUE, 0, 0, 0),
|
||||
new TestCase(1239, 9, 1, 0, 5000, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(1240, 9,18, 0, 5001, 1, 1, TUE, 0, 0, 0),
|
||||
|
||||
// Test cases taken from a table of 14 "year types" in the Help file
|
||||
// of the application "Hebrew Calendar"
|
||||
new TestCase(2456187.5, 0, 5773, 1, 1, MON, 0, 0, 0),
|
||||
new TestCase(2459111.5, 0, 5781, 1, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2453647.5, 0, 5766, 1, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2462035.5, 0, 5789, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(2458756.5, 0, 5780, 1, 1, MON, 0, 0, 0),
|
||||
new TestCase(2460586.5, 0, 5785, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(2463864.5, 0, 5794, 1, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2463481.5, 0, 5793, 1, 1, MON, 0, 0, 0),
|
||||
new TestCase(2470421.5, 0, 5812, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(2460203.5, 0, 5784, 1, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2459464.5, 0, 5782, 1, 1, TUE, 0, 0, 0),
|
||||
new TestCase(2467142.5, 0, 5803, 1, 1, MON, 0, 0, 0),
|
||||
new TestCase(2455448.5, 0, 5771, 1, 1, THU, 0, 0, 0),
|
||||
new TestCase(2487223.5, 0, 5858, 1, 1, SAT, 0, 0, 0),
|
||||
};
|
||||
|
||||
|
||||
};
|
128
icu4j/src/com/ibm/test/calendar/IslamicTest.java
Executable file
128
icu4j/src/com/ibm/test/calendar/IslamicTest.java
Executable file
@ -0,0 +1,128 @@
|
||||
/**
|
||||
* (C) Copyright IBM Corp. 1998. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.test.calendar;
|
||||
|
||||
import com.ibm.test.*;
|
||||
import java.util.*;
|
||||
import java.text.*;
|
||||
import com.ibm.util.*;
|
||||
|
||||
/**
|
||||
* Tests for the <code>IslamicCalendar</code> class.
|
||||
*/
|
||||
public class IslamicTest extends CalendarTest {
|
||||
public static void main(String args[]) throws Exception {
|
||||
new IslamicTest().run(args);
|
||||
}
|
||||
|
||||
/** Constants to save typing. */
|
||||
public static final int MUHARRAM = IslamicCalendar.MUHARRAM;
|
||||
public static final int SAFAR = IslamicCalendar.SAFAR;
|
||||
public static final int RABI_1 = IslamicCalendar.RABI_1;
|
||||
public static final int RABI_2 = IslamicCalendar.RABI_2;
|
||||
public static final int JUMADA_1 = IslamicCalendar.JUMADA_1;
|
||||
public static final int JUMADA_2 = IslamicCalendar.JUMADA_2;
|
||||
public static final int RAJAB = IslamicCalendar.RAJAB;
|
||||
public static final int SHABAN = IslamicCalendar.SHABAN;
|
||||
public static final int RAMADAN = IslamicCalendar.RAMADAN;
|
||||
public static final int SHAWWAL = IslamicCalendar.SHAWWAL;
|
||||
public static final int QIDAH = IslamicCalendar.DHU_AL_QIDAH;
|
||||
public static final int HIJJAH = IslamicCalendar.DHU_AL_HIJJAH;
|
||||
|
||||
public void TestRoll() {
|
||||
int[][] tests = new int[][] {
|
||||
// input roll by output
|
||||
// year month day field amount year month day
|
||||
|
||||
{ 0001, QIDAH, 2, MONTH, 1, 0001, HIJJAH, 2 }, // non-leap years
|
||||
{ 0001, QIDAH, 2, MONTH, 2, 0001, MUHARRAM, 2 },
|
||||
{ 0001, QIDAH, 2, MONTH, -1, 0001, SHAWWAL, 2 },
|
||||
{ 0001, MUHARRAM, 2, MONTH, 12, 0001, MUHARRAM, 2 },
|
||||
{ 0001, MUHARRAM, 2, MONTH, 13, 0001, SAFAR, 2 },
|
||||
|
||||
{ 0001, HIJJAH, 1, DATE, 30, 0001, HIJJAH, 2 }, // 29-day month
|
||||
{ 0002, HIJJAH, 1, DATE, 31, 0002, HIJJAH, 2 }, // 30-day month
|
||||
|
||||
// Try some rolls that require other fields to be adjusted
|
||||
{ 0001, MUHARRAM, 30, MONTH, 1, 0001, SAFAR, 29 },
|
||||
{ 0002, HIJJAH, 30, YEAR, -1, 0001, HIJJAH, 29 },
|
||||
};
|
||||
|
||||
IslamicCalendar cal = newCivil();
|
||||
|
||||
doRollAdd(ROLL, cal, tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* A huge list of test cases to make sure that computeTime and computeFields
|
||||
* work properly for a wide range of data in the civil calendar.
|
||||
*/
|
||||
public void TestCivilCases()
|
||||
{
|
||||
final TestCase[] tests = {
|
||||
//
|
||||
// Most of these test cases were taken from the back of
|
||||
// "Calendrical Calculations", with some extras added to help
|
||||
// debug a few of the problems that cropped up in development.
|
||||
//
|
||||
// The months in this table are 1-based rather than 0-based,
|
||||
// because it's easier to edit that way.
|
||||
// Islamic
|
||||
// Julian Day Era Year Month Day WkDay Hour Min Sec
|
||||
new TestCase(1507231.5, 0, -1245, 12, 9, SUN, 0, 0, 0),
|
||||
new TestCase(1660037.5, 0, -813, 2, 23, WED, 0, 0, 0),
|
||||
new TestCase(1746893.5, 0, -568, 4, 1, WED, 0, 0, 0),
|
||||
new TestCase(1770641.5, 0, -501, 4, 6, SUN, 0, 0, 0),
|
||||
new TestCase(1892731.5, 0, -157, 10, 17, WED, 0, 0, 0),
|
||||
new TestCase(1931579.5, 0, -47, 6, 3, MON, 0, 0, 0),
|
||||
new TestCase(1974851.5, 0, 75, 7, 13, SAT, 0, 0, 0),
|
||||
new TestCase(2091164.5, 0, 403, 10, 5, SUN, 0, 0, 0),
|
||||
new TestCase(2121509.5, 0, 489, 5, 22, SUN, 0, 0, 0),
|
||||
new TestCase(2155779.5, 0, 586, 2, 7, FRI, 0, 0, 0),
|
||||
new TestCase(2174029.5, 0, 637, 8, 7, SAT, 0, 0, 0),
|
||||
new TestCase(2191584.5, 0, 687, 2, 20, FRI, 0, 0, 0),
|
||||
new TestCase(2195261.5, 0, 697, 7, 7, SUN, 0, 0, 0),
|
||||
new TestCase(2229274.5, 0, 793, 7, 1, SUN, 0, 0, 0),
|
||||
new TestCase(2245580.5, 0, 839, 7, 6, WED, 0, 0, 0),
|
||||
new TestCase(2266100.5, 0, 897, 6, 1, SAT, 0, 0, 0),
|
||||
new TestCase(2288542.5, 0, 960, 9, 30, SAT, 0, 0, 0),
|
||||
new TestCase(2290901.5, 0, 967, 5, 27, SAT, 0, 0, 0),
|
||||
new TestCase(2323140.5, 0, 1058, 5, 18, WED, 0, 0, 0),
|
||||
new TestCase(2334848.5, 0, 1091, 6, 2, SUN, 0, 0, 0),
|
||||
new TestCase(2348020.5, 0, 1128, 8, 4, FRI, 0, 0, 0),
|
||||
new TestCase(2366978.5, 0, 1182, 2, 3, SUN, 0, 0, 0),
|
||||
new TestCase(2385648.5, 0, 1234, 10, 10, MON, 0, 0, 0),
|
||||
new TestCase(2392825.5, 0, 1255, 1, 11, WED, 0, 0, 0),
|
||||
new TestCase(2416223.5, 0, 1321, 1, 21, SUN, 0, 0, 0),
|
||||
new TestCase(2425848.5, 0, 1348, 3, 19, SUN, 0, 0, 0),
|
||||
new TestCase(2430266.5, 0, 1360, 9, 8, MON, 0, 0, 0),
|
||||
new TestCase(2430833.5, 0, 1362, 4, 13, MON, 0, 0, 0),
|
||||
new TestCase(2431004.5, 0, 1362, 10, 7, THU, 0, 0, 0),
|
||||
new TestCase(2448698.5, 0, 1412, 9, 13, TUE, 0, 0, 0),
|
||||
new TestCase(2450138.5, 0, 1416, 10, 5, SUN, 0, 0, 0),
|
||||
new TestCase(2465737.5, 0, 1460, 10, 12, WED, 0, 0, 0),
|
||||
new TestCase(2486076.5, 0, 1518, 3, 5, SUN, 0, 0, 0),
|
||||
};
|
||||
|
||||
IslamicCalendar civilCalendar = newCivil();
|
||||
civilCalendar.setLenient(true);
|
||||
doTestCases(tests, civilCalendar);
|
||||
}
|
||||
|
||||
private static IslamicCalendar newCivil() {
|
||||
IslamicCalendar civilCalendar = new IslamicCalendar();
|
||||
civilCalendar.setCivil(true);
|
||||
return civilCalendar;
|
||||
}
|
||||
|
||||
};
|
217
icu4j/src/com/ibm/test/calendar/TestCase.java
Executable file
217
icu4j/src/com/ibm/test/calendar/TestCase.java
Executable file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* @(#)$RCSfile: TestCase.java,v $ $Revision: 1.1 $ $Date: 2000/03/01 18:32:32 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998 - All Rights Reserved
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*
|
||||
*/
|
||||
package com.ibm.test.calendar;
|
||||
|
||||
import com.ibm.test.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Date;
|
||||
import java.util.SimpleTimeZone;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* A dummy <code>Calendar</code> subclass that is useful for testing
|
||||
* new calendars. A <code>TestCase</code> object is used to hold the
|
||||
* field and millisecond values that the calendar should have at one
|
||||
* particular instant in time. The applyFields and applyTime
|
||||
* methods are used to apply these settings to the calendar object being
|
||||
* tested, and the equals and fieldsEqual methods are used to ensure
|
||||
* that the calendar has ended up in the right state.
|
||||
*/
|
||||
public class TestCase extends Calendar {
|
||||
|
||||
/**
|
||||
* Initialize a TestCase object using a julian day number and
|
||||
* the corresponding fields for the calendar being tested.
|
||||
*
|
||||
* @param era The ERA field of tested calendar on the given julian day
|
||||
* @param year The YEAR field of tested calendar on the given julian day
|
||||
* @param month The MONTH (0-based) field of tested calendar on the given julian day
|
||||
* @param day The DAY_OF_MONTH field of tested calendar on the given julian day
|
||||
* @param dayOfWeek The DAY_OF_WEEK field of tested calendar on the given julian day
|
||||
* @param hour The HOUR field of tested calendar on the given julian day
|
||||
* @param min The MINUTE field of tested calendar on the given julian day
|
||||
* @param sec The SECOND field of tested calendar on the given julian day
|
||||
*/
|
||||
public TestCase(double julian,
|
||||
int era, int year, int month, int day,
|
||||
int dayOfWeek,
|
||||
int hour, int min, int sec)
|
||||
{
|
||||
super(UTC, Locale.getDefault());
|
||||
|
||||
setTime(new Date(JULIAN_EPOCH + (long)(DAY_MS * julian)));
|
||||
|
||||
set(ERA, era);
|
||||
set(YEAR, year);
|
||||
set(MONTH, month - 1);
|
||||
set(DATE, day);
|
||||
set(DAY_OF_WEEK, dayOfWeek);
|
||||
set(HOUR, hour);
|
||||
set(MINUTE, min);
|
||||
set(SECOND, sec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a TestCase object using a Gregorian year/month/day and
|
||||
* the corresponding fields for the calendar being tested.
|
||||
*
|
||||
* @param gregYear The Gregorian year of the date to be tested
|
||||
* @param gregMonth The Gregorian month of the date to be tested
|
||||
* @param gregDay The Gregorian day of the month of the date to be tested
|
||||
*
|
||||
* @param era The ERA field of tested calendar on the given gregorian date
|
||||
* @param year The YEAR field of tested calendar on the given gregorian date
|
||||
* @param month The MONTH (0-based) field of tested calendar on the given gregorian date
|
||||
* @param day The DAY_OF_MONTH field of tested calendar on the given gregorian date
|
||||
* @param dayOfWeek The DAY_OF_WEEK field of tested calendar on the given gregorian date
|
||||
* @param hour The HOUR field of tested calendar on the given gregorian date
|
||||
* @param min The MINUTE field of tested calendar on the given gregorian date
|
||||
* @param sec The SECOND field of tested calendar on the given gregorian date
|
||||
*/
|
||||
public TestCase(int gregYear, int gregMonth, int gregDay,
|
||||
int era, int year, int month, int day,
|
||||
int dayOfWeek,
|
||||
int hour, int min, int sec)
|
||||
{
|
||||
super(UTC, Locale.getDefault());
|
||||
|
||||
GregorianCalendar greg = new GregorianCalendar(UTC, Locale.getDefault());
|
||||
greg.clear();
|
||||
greg.set(gregYear, gregMonth-1, gregDay);
|
||||
setTime(greg.getTime());
|
||||
|
||||
set(ERA, era);
|
||||
set(YEAR, year);
|
||||
set(MONTH, month - 1);
|
||||
set(DATE, day);
|
||||
set(DAY_OF_WEEK, dayOfWeek);
|
||||
set(HOUR, hour);
|
||||
set(MINUTE, min);
|
||||
set(SECOND, sec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply this test case's field values to another calendar
|
||||
* by calling its set method for each field. This is useful in combination
|
||||
* with the equal method.
|
||||
*
|
||||
* @see #equal
|
||||
*/
|
||||
public void applyFields(Calendar c) {
|
||||
c.set(ERA, fields[ERA]);
|
||||
c.set(YEAR, fields[YEAR]);
|
||||
c.set(MONTH, fields[MONTH]);
|
||||
c.set(DATE, fields[DATE]);
|
||||
c.set(HOUR, fields[HOUR]);
|
||||
c.set(MINUTE, fields[MINUTE]);
|
||||
c.set(SECOND, fields[SECOND]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply this test case's time in milliseconds to another calendar
|
||||
* by calling its setTime method. This is useful in combination
|
||||
* with fieldsEqual
|
||||
*
|
||||
* @see #fieldsEqual
|
||||
*/
|
||||
public void applyTime(Calendar c) {
|
||||
c.setTime(new Date(time));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the fields of this calendar
|
||||
* are the same as that of the other calendar. This method is useful
|
||||
* for determining whether the other calendar's computeFields method
|
||||
* works properly. For example:
|
||||
* <pre>
|
||||
* Calendar testCalendar = ...
|
||||
* TestCase case = ...
|
||||
* case.applyTime(testCalendar);
|
||||
* if (!case.fieldsEqual(testCalendar)) {
|
||||
* // Error!
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @see #applyTime
|
||||
*/
|
||||
public boolean fieldsEqual(Calendar c) {
|
||||
for (int i=0; i < Calendar.FIELD_COUNT; i++) {
|
||||
if (isSet(i) && get(i) != c.get(i)) {
|
||||
System.out.println("field " + i + ": expected " + get(i) + ", got " + c.get(i));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether time in milliseconds of this calendar
|
||||
* is the same as that of the other calendar. This method is useful
|
||||
* for determining whether the other calendar's computeTime method
|
||||
* works properly. For example:
|
||||
* <pre>
|
||||
* Calendar testCalendar = ...
|
||||
* TestCase case = ...
|
||||
* case.applyFields(testCalendar);
|
||||
* if (!case.equals(testCalendar)) {
|
||||
* // Error!
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @see #applyFields
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
return time == ((Calendar)obj).getTime().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether time of this calendar (as returned by getTime)
|
||||
* is before that of the specified calendar
|
||||
*/
|
||||
public boolean before(Object obj) {
|
||||
return time < ((Calendar)obj).getTime().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether time of this calendar (as returned by getTime)
|
||||
* is after that of the specified calendar
|
||||
*/
|
||||
public boolean after(Object obj) {
|
||||
return time > ((Calendar)obj).getTime().getTime();
|
||||
}
|
||||
|
||||
// This object is only pretending to be a Calendar; it doesn't do any real
|
||||
// calendar computatations. But we have to pretend it does, because Calendar
|
||||
// declares all of these abstract methods....
|
||||
protected void computeTime() {}
|
||||
protected void computeFields() {}
|
||||
public void roll(int field, boolean up) {}
|
||||
public void add(int field, int amt) {}
|
||||
public int getMinimum(int field) { return 0; }
|
||||
public int getMaximum(int field) { return 0; }
|
||||
public int getGreatestMinimum(int field) { return 0; }
|
||||
public int getLeastMaximum(int field) { return 0; }
|
||||
|
||||
private static final int SECOND_MS = 1000;
|
||||
private static final int MINUTE_MS = 60*SECOND_MS;
|
||||
private static final int HOUR_MS = 60*MINUTE_MS;
|
||||
private static final long DAY_MS = 24*HOUR_MS;
|
||||
private static final long JULIAN_EPOCH = -210866760000000L; // 1/1/4713 BC 12:00
|
||||
|
||||
public final static SimpleTimeZone UTC = new SimpleTimeZone(0, "GMT");
|
||||
}
|
18
icu4j/src/com/ibm/test/calendar/makefile
Executable file
18
icu4j/src/com/ibm/test/calendar/makefile
Executable file
@ -0,0 +1,18 @@
|
||||
#
|
||||
# @(#)$RCSfile: makefile,v $ $Revision: 1.1 $ $Date: 2000/03/01 18:32:32 $
|
||||
#
|
||||
|
||||
TOPDIR= ../../../../..
|
||||
PACKAGE= com.ibm.test.calendar
|
||||
|
||||
!include $(TOPDIR)/src/build/defs.mak
|
||||
|
||||
|
||||
FILES_java= $(TARGDIR)/TestCase.java \
|
||||
$(TARGDIR)/CalendarTest.java \
|
||||
$(TARGDIR)/AstroTest.java \
|
||||
$(TARGDIR)/HebrewTest.java \
|
||||
$(TARGDIR)/IslamicTest.java \
|
||||
|
||||
|
||||
!include $(TOPDIR)/src/build/rules.mak
|
Loading…
Reference in New Issue
Block a user