use of android.icu.util.CopticCalendar in project j2objc by google.
the class CopticTest method TestAddSet.
@Test
public void TestAddSet() {
class TestAddSetItem {
private int startYear;
// 0-based
private int startMonth;
// 1-based
private int startDay;
private int fieldToChange;
private int fieldDelta;
private int endYear;
private int endMonth;
private int endDay;
TestAddSetItem(int sYr, int sMo, int sDa, int field, int delta, int eYr, int eMo, int eDa) {
startYear = sYr;
startMonth = sMo;
startDay = sDa;
fieldToChange = field;
fieldDelta = delta;
endYear = eYr;
endMonth = eMo;
endDay = eDa;
}
public int getStartYear() {
return startYear;
}
public int getStartMonth() {
return startMonth;
}
public int getStartDay() {
return startDay;
}
public int getField() {
return fieldToChange;
}
public int getDelta() {
return fieldDelta;
}
public int getEndYear() {
return endYear;
}
public int getEndMonth() {
return endMonth;
}
public int getEndDay() {
return endDay;
}
}
final TestAddSetItem[] tests = { new TestAddSetItem(1724, 12, 1, Calendar.MONTH, +1, 1725, 0, 1), new TestAddSetItem(1724, 12, 1, Calendar.MONTH, +9, 1725, 8, 1), // 1723 is a leap year
new TestAddSetItem(1723, 12, 2, Calendar.MONTH, +1, 1724, 0, 2), new TestAddSetItem(1723, 12, 2, Calendar.MONTH, +9, 1724, 8, 2), new TestAddSetItem(1725, 0, 1, Calendar.MONTH, -1, 1724, 12, 1), new TestAddSetItem(1725, 0, 1, Calendar.MONTH, -6, 1724, 7, 1), new TestAddSetItem(1724, 12, 1, Calendar.DATE, +8, 1725, 0, 4), // 1723 is a leap year
new TestAddSetItem(1723, 12, 1, Calendar.DATE, +8, 1724, 0, 3), new TestAddSetItem(1724, 0, 1, Calendar.DATE, -1, 1723, 12, 6) };
CopticCalendar testCalendar = new CopticCalendar();
for (int i = 0; i < tests.length; i++) {
TestAddSetItem item = tests[i];
testCalendar.set(item.getStartYear(), item.getStartMonth(), item.getStartDay(), 9, 0);
testCalendar.add(item.getField(), item.getDelta());
int endYear = testCalendar.get(Calendar.YEAR);
int endMonth = testCalendar.get(Calendar.MONTH);
int endDay = testCalendar.get(Calendar.DATE);
if (endYear != item.getEndYear() || endMonth != item.getEndMonth() || endDay != item.getEndDay()) {
errln("CToJD FAILS: field " + item.getField() + " delta " + item.getDelta() + " expected yr " + item.getEndYear() + " mo " + item.getEndMonth() + " da " + item.getEndDay() + " got yr " + endYear + " mo " + endMonth + " da " + endDay);
}
}
}
use of android.icu.util.CopticCalendar in project j2objc by google.
the class CopticTest method TestCases.
/* Test dates from:
* "The Amharic Letters of Emperor Theodore of Ethiopia to Queen Victoria and
* Her Special Envoy", David Appleyard, Girma Selasse Asfaw, Oxford University Press,
* June 1 1979, ISBN: 0856726605, Longwood Pr Ltd
*
* Coptic Gregorian JD
* 20/02/1579 29/10/1862 2401443
* 29/10/1581 05/07/1865 2402423
* 22/05/1582 29/01/1866 2402631
* 10/08/1582 17/04/1866 2402709
* 28/04/1583 05/01/1867 2402972
* 05/05/1584 13/01/1868 2403345
*
* --------------------------------------------------
*
* From the Calendrica applet: http://emr.cs.iit.edu/home/reingold/calendar-book/Calendrica.html
*
* Coptic Gregorian JD
* 07/05/-284 01/01/0000 1721060
* 08/05/-283 01/01/0001 1721426
* 06/13/-1 29/08/0283 1824664
*
* 01/01/0000 30/08/0283 1824665
* 01/01/0001 29/08/0284 1825030
* 01/01/0002 29/08/0285 1825395
* 01/01/0003 29/08/0286 1825760
* 01/01/0004 30/08/0287 1826126
* 05/13/0000 28/08/0284 1825029
* 05/13/0001 28/08/0285 1825394
* 05/13/0002 28/08/0286 1825759
* 05/13/0003 28/08/0287 1826124
* 06/13/0003 29/08/0287 1826125 first coptic leap year
* 05/13/0004 28/08/0288 1826490
*
* 06/02/1299 13/10/1582 2299159
* 07/02/1299 14/10/1582 2299160 Julian 04/10/1582
* 08/02/1299 15/10/1582 2299161
* 09/02/1299 16/10/1582 2299162
*
* 23/04/1616 01/01/1900 2415021
* 23/04/1721 01/01/2005 2453372
* 05/13/2000 12/09/2284 2555529
*/
/**
* 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.
*/
@Test
public void TestCases() {
final TestCase[] tests = { // Gregorian: 20/10/1862
new TestCase(2401442.5, 1, 1579, 2, 20, WED, 0, 0, 0), // Gregorian: 05/07/1865
new TestCase(2402422.5, 1, 1581, 10, 29, WED, 0, 0, 0), // Gregorian: 29/01/1866
new TestCase(2402630.5, 1, 1582, 5, 22, MON, 0, 0, 0), // Gregorian: 17/04/1866
new TestCase(2402708.5, 1, 1582, 8, 10, TUE, 0, 0, 0), // Gregorian: 05/01/1867
new TestCase(2402971.5, 1, 1583, 4, 28, SAT, 0, 0, 0), // Gregorian: 13/01/1868
new TestCase(2403344.5, 1, 1584, 5, 5, MON, 0, 0, 0), // Gregorian: 01/01/0000
new TestCase(1721059.5, 0, 285, 5, 7, SAT, 0, 0, 0), // Gregorian: 01/01/0001
new TestCase(1721425.5, 0, 284, 5, 8, MON, 0, 0, 0), // Gregorian: 29/08/0283
new TestCase(1824663.5, 0, 2, 13, 6, WED, 0, 0, 0), // Gregorian: 30/08/0283
new TestCase(1824664.5, 0, 1, 1, 1, THU, 0, 0, 0), // Gregorian: 29/08/0284
new TestCase(1825029.5, 1, 1, 1, 1, FRI, 0, 0, 0), // Gregorian: 29/08/0285
new TestCase(1825394.5, 1, 2, 1, 1, SAT, 0, 0, 0), // Gregorian: 29/08/0286
new TestCase(1825759.5, 1, 3, 1, 1, SUN, 0, 0, 0), // Gregorian: 30/08/0287
new TestCase(1826125.5, 1, 4, 1, 1, TUE, 0, 0, 0), // Gregorian: 28/08/0284
new TestCase(1825028.5, 0, 1, 13, 5, THU, 0, 0, 0), // Gregorian: 28/08/0285
new TestCase(1825393.5, 1, 1, 13, 5, FRI, 0, 0, 0), // Gregorian: 28/08/0286
new TestCase(1825758.5, 1, 2, 13, 5, SAT, 0, 0, 0), // Gregorian: 28/08/0287
new TestCase(1826123.5, 1, 3, 13, 5, SUN, 0, 0, 0), // Gregorian: 29/08/0287
new TestCase(1826124.5, 1, 3, 13, 6, MON, 0, 0, 0), // Gregorian: 28/08/0288
new TestCase(1826489.5, 1, 4, 13, 5, TUE, 0, 0, 0), // Gregorian: 13/10/1582
new TestCase(2299158.5, 1, 1299, 2, 6, WED, 0, 0, 0), // Gregorian: 14/10/1582
new TestCase(2299159.5, 1, 1299, 2, 7, THU, 0, 0, 0), // Gregorian: 15/10/1582
new TestCase(2299160.5, 1, 1299, 2, 8, FRI, 0, 0, 0), // Gregorian: 16/10/1582
new TestCase(2299161.5, 1, 1299, 2, 9, SAT, 0, 0, 0), // Gregorian: 01/01/1900
new TestCase(2415020.5, 1, 1616, 4, 23, MON, 0, 0, 0), // Gregorian: 01/01/2005
new TestCase(2453371.5, 1, 1721, 4, 23, SAT, 0, 0, 0), // Gregorian: 12/09/2284
new TestCase(2555528.5, 1, 2000, 13, 5, FRI, 0, 0, 0) };
CopticCalendar testCalendar = new CopticCalendar();
testCalendar.setLenient(true);
doTestCases(tests, testCalendar);
}
use of android.icu.util.CopticCalendar in project j2objc by google.
the class CopticTest method TestCopticToJD.
// basic sanity check that the conversion algorithm round-trips
@Test
public void TestCopticToJD() {
CopticCalendar cal = new CopticCalendar();
cal.clear();
for (int y = -2; y < 3; ++y) {
for (int m = 0; m < 12; ++m) {
// don't understand rules for 13th month
for (int d = 1; d < 25; d += 3) {
// play it safe on days per month
int jd = CopticCalendar.copticToJD(y, m, d);
cal.set(Calendar.JULIAN_DAY, jd);
int eyear = cal.get(Calendar.EXTENDED_YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
if (!(y == eyear && m == month && d == day)) {
errln("y: " + y + " m: " + m + " d: " + d + " --> jd: " + jd + " --> y: " + eyear + " m: " + month + " d: " + day);
}
}
}
}
}
Aggregations