From 0fc105ba52565f1317ea3d1e167d3c3c69ce8f0f Mon Sep 17 00:00:00 2001 From: "M. Waisberg" Date: Mon, 20 Jun 2022 19:07:10 +0300 Subject: [PATCH] calendar constants --- .../hebrewcalendar/HebrewDateFormatter.java | 6 +- .../zmanim/hebrewcalendar/JewishDate.java | 71 ++++++------ .../UT_DaysInGregorianMonth.java | 31 +++--- .../hebrewcalendar/UT_DaysInJewishMonth.java | 15 +-- .../UT_GregorianDateNavigation.java | 104 +++++++++--------- .../UT_JewishDateNavigation.java | 6 +- .../hebrewcalendar/UT_JewishLeapYear.java | 5 +- .../hebrewcalendar/UT_YerushalmiTest.java | 26 ++--- .../hebrewcalendar/YomiCalculatorTest.java | 17 +-- 9 files changed, 132 insertions(+), 149 deletions(-) diff --git a/src/main/java/com/kosherjava/zmanim/hebrewcalendar/HebrewDateFormatter.java b/src/main/java/com/kosherjava/zmanim/hebrewcalendar/HebrewDateFormatter.java index ad813239..e99bf9fe 100644 --- a/src/main/java/com/kosherjava/zmanim/hebrewcalendar/HebrewDateFormatter.java +++ b/src/main/java/com/kosherjava/zmanim/hebrewcalendar/HebrewDateFormatter.java @@ -758,15 +758,15 @@ public String formatMonth(JewishDate jewishDate) { final int month = jewishDate.getJewishMonth(); if (isHebrewFormat()) { if (jewishDate.isJewishLeapYear() && month == JewishDate.ADAR) { - return hebrewMonths[13] + (useGershGershayim ? GERESH : ""); // return Adar I, not Adar in a leap year + return hebrewMonths[JewishDate.ADAR_II] + (useGershGershayim ? GERESH : ""); // return Adar I, not Adar in a leap year } else if (jewishDate.isJewishLeapYear() && month == JewishDate.ADAR_II) { - return hebrewMonths[12] + (useGershGershayim ? GERESH : ""); + return hebrewMonths[JewishDate.ADAR] + (useGershGershayim ? GERESH : ""); } else { return hebrewMonths[month - 1]; } } else { if (jewishDate.isJewishLeapYear() && month == JewishDate.ADAR) { - return transliteratedMonths[13]; // return Adar I, not Adar in a leap year + return transliteratedMonths[JewishDate.ADAR_II]; // return Adar I, not Adar in a leap year } else { return transliteratedMonths[month - 1]; } diff --git a/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java b/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java index 85042bad..dc9e6afa 100644 --- a/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java +++ b/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java @@ -153,7 +153,7 @@ public class JewishDate implements Comparable, Cloneable { /** The number of chalakim (1080) in an hour.*/ private static final int CHALAKIM_PER_HOUR = 1080; /** The number of chalakim (25,920) in a 24 hour day .*/ - private static final int CHALAKIM_PER_DAY = 25920; // 24 * 1080 + private static final long CHALAKIM_PER_DAY = 25920; // 24 * 1080 /** The number of chalakim in an average Jewish month. A month has 29 days, 12 hours and 793 * chalakim (44 minutes and 3.3 seconds) for a total of 765,433 chalakim*/ private static final long CHALAKIM_PER_MONTH = 765433; // (29 * 24 + 12) * 1080 + 793 @@ -336,23 +336,23 @@ boolean isGregorianLeapYear(int year) { * Returns the number of days in a given month in a given month and year. * * @param month - * the month. As with other cases in this class, this is 1-based, not zero-based. + * the month. * @param year * the year (only impacts February) * @return the number of days in the month in the given year */ private static int getLastDayOfGregorianMonth(int month, int year) { switch (month) { - case 2: + case Calendar.FEBRUARY: if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { return 29; } else { return 28; } - case 4: - case 6: - case 9: - case 11: + case Calendar.APRIL: + case Calendar.JUNE: + case Calendar.SEPTEMBER: + case Calendar.NOVEMBER: return 30; default: return 31; @@ -365,11 +365,11 @@ private static int getLastDayOfGregorianMonth(int month, int year) { */ private void absDateToDate(int absDate) { int year = absDate / 366; // Search forward year by year from approximate year - while (absDate >= gregorianDateToAbsDate(year + 1, 1, 1)) { + while (absDate >= gregorianDateToAbsDate(year + 1, Calendar.JANUARY, 1)) { year++; } - int month = 1; // Search forward month by month from January + int month = Calendar.JANUARY; // Search forward month by month from January while (absDate > gregorianDateToAbsDate(year, month, getLastDayOfGregorianMonth(month, year))) { month++; } @@ -401,14 +401,15 @@ public int getAbsDate() { */ private static int gregorianDateToAbsDate(int year, int month, int dayOfMonth) { int absDate = dayOfMonth; - for (int m = month - 1; m > 0; m--) { + for (int m = Calendar.JANUARY; m < month; m++) { absDate += getLastDayOfGregorianMonth(m, year); // days in prior months of the year } + int yearPrevious = year - 1; return (absDate // days this year - + 365 * (year - 1) // days in previous years ignoring leap days - + (year - 1) / 4 // Julian leap days before this year - - (year - 1) / 100 // minus prior century years - + (year - 1) / 400); // plus prior years divisible by 400 + + 365 * yearPrevious // days in previous years ignoring leap days + + yearPrevious / 4 // Julian leap days before this year + - yearPrevious / 100 // minus prior century years + + yearPrevious / 400); // plus prior years divisible by 400 } /** @@ -460,8 +461,8 @@ private static int getLastMonthOfJewishYear(int year) { */ public static int getJewishCalendarElapsedDays(int year) { long chalakimSince = getChalakimSinceMoladTohu(year, TISHREI); - int moladDay = (int) (chalakimSince / (long) CHALAKIM_PER_DAY); - int moladParts = (int) (chalakimSince - moladDay * (long) CHALAKIM_PER_DAY); + int moladDay = (int) (chalakimSince / CHALAKIM_PER_DAY); + int moladParts = (int) (chalakimSince - moladDay * CHALAKIM_PER_DAY); // delay Rosh Hashana for the 4 dechiyos return addDechiyos(year, moladDay, moladParts); } @@ -670,7 +671,7 @@ private static void validateGregorianDate(int year, int month, int dayOfMonth) { * {@link GregorianCalendar}, where {@link Calendar#JANUARY} has a value of 0. */ private static void validateGregorianMonth(int month) { - if (month > 11 || month < 0) { + if (month > Calendar.DECEMBER || month < Calendar.JANUARY) { throw new IllegalArgumentException("The Gregorian month has to be between 0 - 11. " + month + " is invalid."); } @@ -908,8 +909,8 @@ private static int moladToAbsDate(long chalakim) { public JewishDate(long molad) { absDateToDate(moladToAbsDate(molad)); // long chalakimSince = getChalakimSinceMoladTohu(year, TISHREI);// tishrei - int conjunctionDay = (int) (molad / (long) CHALAKIM_PER_DAY); - int conjunctionParts = (int) (molad - conjunctionDay * (long) CHALAKIM_PER_DAY); + long conjunctionDay = molad / CHALAKIM_PER_DAY; + int conjunctionParts = (int) (molad - conjunctionDay * CHALAKIM_PER_DAY); setMoladTime(conjunctionParts); } @@ -1042,13 +1043,10 @@ public void setDate(Calendar calendar) { throw new IllegalArgumentException("Calendars with a BC era are not supported. The year " + calendar.get(Calendar.YEAR) + " BC is invalid."); } - gregorianMonth = calendar.get(Calendar.MONTH) + 1; - gregorianDayOfMonth = calendar.get(Calendar.DATE); - gregorianYear = calendar.get(Calendar.YEAR); - gregorianAbsDate = gregorianDateToAbsDate(gregorianYear, gregorianMonth, gregorianDayOfMonth); // init the date - absDateToJewishDate(); - - dayOfWeek = Math.abs(gregorianAbsDate % 7) + 1; // set day of week + int month = calendar.get(Calendar.MONTH); + int dayOfMonth = calendar.get(Calendar.DATE); + int year = calendar.get(Calendar.YEAR); + setInternalGregorianDate(year, month, dayOfMonth); } /** @@ -1095,7 +1093,7 @@ public void setDate(LocalDate localDate) { */ public void setGregorianDate(int year, int month, int dayOfMonth) { validateGregorianDate(year, month, dayOfMonth); - setInternalGregorianDate(year, month + 1, dayOfMonth); + setInternalGregorianDate(year, month, dayOfMonth); } /** @@ -1110,15 +1108,16 @@ public void setGregorianDate(int year, int month, int dayOfMonth) { */ private void setInternalGregorianDate(int year, int month, int dayOfMonth) { // make sure date is a valid date for the given month, if not, set to last day of month - if (dayOfMonth > getLastDayOfGregorianMonth(month, year)) { - dayOfMonth = getLastDayOfGregorianMonth(month, year); + int lastDayOfMonth = getLastDayOfGregorianMonth(month, year); + if (dayOfMonth > lastDayOfMonth) { + dayOfMonth = lastDayOfMonth; } // init month, date, year gregorianMonth = month; gregorianDayOfMonth = dayOfMonth; gregorianYear = year; - gregorianAbsDate = gregorianDateToAbsDate(gregorianYear, gregorianMonth, gregorianDayOfMonth); // init date + gregorianAbsDate = gregorianDateToAbsDate(year, month, dayOfMonth); // init date absDateToJewishDate(); dayOfWeek = Math.abs(gregorianAbsDate % 7) + 1; // set day of week @@ -1267,9 +1266,9 @@ public void forward(int field, int amount) { if (gregorianDayOfMonth == getLastDayOfGregorianMonth(gregorianMonth, gregorianYear)) { gregorianDayOfMonth = 1; // if last day of year - if (gregorianMonth == 12) { + if (gregorianMonth == Calendar.DECEMBER) { gregorianYear++; - gregorianMonth = 1; + gregorianMonth = Calendar.JANUARY; } else { gregorianMonth++; } @@ -1357,8 +1356,8 @@ private void forwardJewishMonth(int amount) { public void back() { // Change Gregorian date if (gregorianDayOfMonth == 1) { // if first day of month - if (gregorianMonth == 1) { // if first day of year - gregorianMonth = 12; + if (gregorianMonth == Calendar.JANUARY) { // if first day of year + gregorianMonth = Calendar.DECEMBER; gregorianYear--; } else { gregorianMonth--; @@ -1421,7 +1420,7 @@ public int compareTo(JewishDate jewishDate) { * @return the Gregorian month (between 0-11). Like the java.util.Calendar, months are 0 based. */ public int getGregorianMonth() { - return gregorianMonth - 1; + return gregorianMonth; } /** @@ -1491,7 +1490,7 @@ public int getDayOfWeek() { */ public void setGregorianMonth(int month) { validateGregorianMonth(month); - setInternalGregorianDate(gregorianYear, month + 1, gregorianDayOfMonth); + setInternalGregorianDate(gregorianYear, month, gregorianDayOfMonth); } /** diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInGregorianMonth.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInGregorianMonth.java index 4dd5ac87..a6f96c06 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInGregorianMonth.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInGregorianMonth.java @@ -4,6 +4,8 @@ package com.kosherjava.zmanim.hebrewcalendar; +import static org.junit.Assert.assertEquals; + import org.junit.*; import java.util.Calendar; @@ -18,7 +20,6 @@ public class UT_DaysInGregorianMonth { @Test public void testDaysInMonth() { - JewishDate hebrewDate = new JewishDate(); Calendar cal = Calendar.getInstance(); @@ -33,7 +34,6 @@ public void testDaysInMonth() { @Test public void testDaysInMonthLeapYear() { - JewishDate hebrewDate = new JewishDate(); Calendar cal = Calendar.getInstance(); @@ -47,7 +47,6 @@ public void testDaysInMonthLeapYear() { @Test public void testDaysInMonth100Year() { - JewishDate hebrewDate = new JewishDate(); Calendar cal = Calendar.getInstance(); @@ -61,7 +60,6 @@ public void testDaysInMonth100Year() { @Test public void testDaysInMonth400Year() { - JewishDate hebrewDate = new JewishDate(); Calendar cal = Calendar.getInstance(); @@ -77,19 +75,18 @@ private void assertDaysInMonth( boolean febIsLeap, JewishDate hebrewDate ) { - - Assert.assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(1)); - Assert.assertEquals(febIsLeap ? 29 : 28, hebrewDate.getLastDayOfGregorianMonth(2)); - Assert.assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(3)); - Assert.assertEquals(30, hebrewDate.getLastDayOfGregorianMonth(4)); - Assert.assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(5)); - Assert.assertEquals(30, hebrewDate.getLastDayOfGregorianMonth(6)); - Assert.assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(7)); - Assert.assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(8)); - Assert.assertEquals(30, hebrewDate.getLastDayOfGregorianMonth(9)); - Assert.assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(10)); - Assert.assertEquals(30, hebrewDate.getLastDayOfGregorianMonth(11)); - Assert.assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(12)); + assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(Calendar.JANUARY)); + assertEquals(febIsLeap ? 29 : 28, hebrewDate.getLastDayOfGregorianMonth(Calendar.FEBRUARY)); + assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(Calendar.MARCH)); + assertEquals(30, hebrewDate.getLastDayOfGregorianMonth(Calendar.APRIL)); + assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(Calendar.MAY)); + assertEquals(30, hebrewDate.getLastDayOfGregorianMonth(Calendar.JUNE)); + assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(Calendar.JULY)); + assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(Calendar.AUGUST)); + assertEquals(30, hebrewDate.getLastDayOfGregorianMonth(Calendar.SEPTEMBER)); + assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(Calendar.OCTOBER)); + assertEquals(30, hebrewDate.getLastDayOfGregorianMonth(Calendar.NOVEMBER)); + assertEquals(31, hebrewDate.getLastDayOfGregorianMonth(Calendar.DECEMBER)); } diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInJewishMonth.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInJewishMonth.java index 2e549b98..bc37c2b5 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInJewishMonth.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInJewishMonth.java @@ -14,7 +14,6 @@ public class UT_DaysInJewishMonth { @Test public void daysInMonthsInHaserYear() { - assertHaser(5773); assertHaser(5777); assertHaser(5781); @@ -26,7 +25,6 @@ public void daysInMonthsInHaserYear() { @Test public void daysInMonthsInQesidrahYear() { - assertQesidrah(5769); assertQesidrah(5772); assertQesidrah(5778); @@ -40,7 +38,6 @@ public void daysInMonthsInQesidrahYear() { @Test public void daysInMonthsInShalemYear() { - assertShalem(5770); assertShalem(5780); assertShalem(5783); @@ -80,8 +77,8 @@ private void assertQesidrah(int year) { JewishDate jewishDate = new JewishDate(); jewishDate.setJewishYear(year); - Assert.assertFalse(jewishDate.isCheshvanLong( )); - Assert.assertFalse(jewishDate.isKislevShort( )); + Assert.assertFalse(jewishDate.isCheshvanLong()); + Assert.assertFalse(jewishDate.isKislevShort()); } @@ -90,7 +87,7 @@ private void assertQesidrahLeap(int year) { jewishDate.setJewishYear(year); assertQesidrah(year); - Assert.assertTrue(jewishDate.isJewishLeapYear( )); + Assert.assertTrue(jewishDate.isJewishLeapYear()); } @@ -98,8 +95,8 @@ private void assertShalem(int year) { JewishDate jewishDate = new JewishDate(); jewishDate.setJewishYear(year); - Assert.assertTrue(jewishDate.isCheshvanLong( )); - Assert.assertFalse(jewishDate.isKislevShort( )); + Assert.assertTrue(jewishDate.isCheshvanLong()); + Assert.assertFalse(jewishDate.isKislevShort()); } @@ -108,7 +105,7 @@ private void assertShalemLeap(int year) { jewishDate.setJewishYear(year); assertShalem(year); - Assert.assertTrue(jewishDate.isJewishLeapYear( )); + Assert.assertTrue(jewishDate.isJewishLeapYear()); } } // End of UT_DaysInJewishMonth class diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_GregorianDateNavigation.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_GregorianDateNavigation.java index 6feb7e38..30c71c38 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_GregorianDateNavigation.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_GregorianDateNavigation.java @@ -16,7 +16,6 @@ public class UT_GregorianDateNavigation { @Test public void gregorianForwardMonthToMonth() { - Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2011); cal.set(Calendar.MONTH, Calendar.JANUARY); @@ -24,109 +23,109 @@ public void gregorianForwardMonthToMonth() { JewishDate hebrewDate = new JewishDate(cal); Assert.assertEquals(5771, hebrewDate.getJewishYear()); - Assert.assertEquals(11, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.SHEVAT, hebrewDate.getJewishMonth()); Assert.assertEquals(26, hebrewDate.getJewishDayOfMonth()); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(1, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.FEBRUARY, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(11, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.SHEVAT, hebrewDate.getJewishMonth()); Assert.assertEquals(27, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.FEBRUARY); cal.set(Calendar.DATE, 28); hebrewDate.setDate(cal); - Assert.assertEquals(1, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.FEBRUARY, hebrewDate.getGregorianMonth()); Assert.assertEquals(28, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(12, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.ADAR, hebrewDate.getJewishMonth()); Assert.assertEquals(24, hebrewDate.getJewishDayOfMonth()); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(2, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.MARCH, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(12, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.ADAR, hebrewDate.getJewishMonth()); Assert.assertEquals(25, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DATE, 31); hebrewDate.setDate(cal); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(3, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.APRIL, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(13, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.ADAR_II, hebrewDate.getJewishMonth()); Assert.assertEquals(26, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.APRIL); cal.set(Calendar.DATE, 30); hebrewDate.setDate(cal); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(4, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.MAY, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(1, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.NISSAN, hebrewDate.getJewishMonth()); Assert.assertEquals(27, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.MAY); cal.set(Calendar.DATE, 31); hebrewDate.setDate(cal); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(5, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.JUNE, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(2, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.IYAR, hebrewDate.getJewishMonth()); Assert.assertEquals(28, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.JUNE); cal.set(Calendar.DATE, 30); hebrewDate.setDate(cal); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(6, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.JULY, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(3, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.SIVAN, hebrewDate.getJewishMonth()); Assert.assertEquals(29, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.JULY); cal.set(Calendar.DATE, 31); hebrewDate.setDate(cal); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(7, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.AUGUST, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(5, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.AV, hebrewDate.getJewishMonth()); Assert.assertEquals(1, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.AUGUST); cal.set(Calendar.DATE, 31); hebrewDate.setDate(cal); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(8, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.SEPTEMBER, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(6, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.ELUL, hebrewDate.getJewishMonth()); Assert.assertEquals(2, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.SEPTEMBER); cal.set(Calendar.DATE, 30); hebrewDate.setDate(cal); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(9, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.OCTOBER, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(7, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.TISHREI, hebrewDate.getJewishMonth()); Assert.assertEquals(3, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.OCTOBER); cal.set(Calendar.DATE, 31); hebrewDate.setDate(cal); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(10, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.NOVEMBER, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); Assert.assertEquals(5772, hebrewDate.getJewishYear()); - Assert.assertEquals(8, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.CHESHVAN, hebrewDate.getJewishMonth()); Assert.assertEquals(4, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.NOVEMBER); cal.set(Calendar.DATE, 30); hebrewDate.setDate(cal); hebrewDate.forward(Calendar.DATE, 1); - Assert.assertEquals(11, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.DECEMBER, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(9, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.KISLEV, hebrewDate.getJewishMonth()); Assert.assertEquals(5, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.MONTH, Calendar.DECEMBER); @@ -134,16 +133,15 @@ public void gregorianForwardMonthToMonth() { hebrewDate.setDate(cal); hebrewDate.forward(Calendar.DATE, 1); Assert.assertEquals(2012, hebrewDate.getGregorianYear()); - Assert.assertEquals(0, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.JANUARY, hebrewDate.getGregorianMonth()); Assert.assertEquals(1, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(10, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.TEVES, hebrewDate.getJewishMonth()); Assert.assertEquals(6, hebrewDate.getJewishDayOfMonth()); } @Test public void gregorianBackwardMonthToMonth() { - Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2011); cal.set(Calendar.MONTH, Calendar.JANUARY); @@ -152,9 +150,9 @@ public void gregorianBackwardMonthToMonth() { JewishDate hebrewDate = new JewishDate(cal); hebrewDate.back(); Assert.assertEquals(2010, hebrewDate.getGregorianYear()); - Assert.assertEquals(11, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.DECEMBER, hebrewDate.getGregorianMonth()); Assert.assertEquals(31, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(10, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.TEVES, hebrewDate.getJewishMonth()); Assert.assertEquals(24, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); @@ -162,100 +160,100 @@ public void gregorianBackwardMonthToMonth() { cal.set(Calendar.YEAR, 2010); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(10, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.NOVEMBER, hebrewDate.getGregorianMonth()); Assert.assertEquals(30, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(9, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.KISLEV, hebrewDate.getJewishMonth()); Assert.assertEquals(23, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.NOVEMBER); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(9, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.OCTOBER, hebrewDate.getGregorianMonth()); Assert.assertEquals(31, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(8, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.CHESHVAN, hebrewDate.getJewishMonth()); Assert.assertEquals(23, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.OCTOBER); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(8, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.SEPTEMBER, hebrewDate.getGregorianMonth()); Assert.assertEquals(30, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(7, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.TISHREI, hebrewDate.getJewishMonth()); Assert.assertEquals(22, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.SEPTEMBER); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(7, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.AUGUST, hebrewDate.getGregorianMonth()); Assert.assertEquals(31, hebrewDate.getGregorianDayOfMonth()); Assert.assertEquals(5770, hebrewDate.getJewishYear()); - Assert.assertEquals(6, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.ELUL, hebrewDate.getJewishMonth()); Assert.assertEquals(21, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.AUGUST); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(6, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.JULY, hebrewDate.getGregorianMonth()); Assert.assertEquals(31, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(5, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.AV, hebrewDate.getJewishMonth()); Assert.assertEquals(20, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.JULY); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(5, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.JUNE, hebrewDate.getGregorianMonth()); Assert.assertEquals(30, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(4, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.TAMMUZ, hebrewDate.getJewishMonth()); Assert.assertEquals(18, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.JUNE); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(4, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.MAY, hebrewDate.getGregorianMonth()); Assert.assertEquals(31, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(3, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.SIVAN, hebrewDate.getJewishMonth()); Assert.assertEquals(18, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.MAY); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(3, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.APRIL, hebrewDate.getGregorianMonth()); Assert.assertEquals(30, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(2, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.IYAR, hebrewDate.getJewishMonth()); Assert.assertEquals(16, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.APRIL); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(2, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.MARCH, hebrewDate.getGregorianMonth()); Assert.assertEquals(31, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(1, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.NISSAN, hebrewDate.getJewishMonth()); Assert.assertEquals(16, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.MARCH); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(1, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.FEBRUARY, hebrewDate.getGregorianMonth()); Assert.assertEquals(28, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(12, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.ADAR, hebrewDate.getJewishMonth()); Assert.assertEquals(14, hebrewDate.getJewishDayOfMonth()); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, Calendar.FEBRUARY); hebrewDate.setDate(cal); hebrewDate.back(); - Assert.assertEquals(0, hebrewDate.getGregorianMonth()); + Assert.assertEquals(Calendar.JANUARY, hebrewDate.getGregorianMonth()); Assert.assertEquals(31, hebrewDate.getGregorianDayOfMonth()); - Assert.assertEquals(11, hebrewDate.getJewishMonth()); + Assert.assertEquals(JewishDate.SHEVAT, hebrewDate.getJewishMonth()); Assert.assertEquals(16, hebrewDate.getJewishDayOfMonth()); } diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishDateNavigation.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishDateNavigation.java index 2a0d6e66..976e9377 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishDateNavigation.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishDateNavigation.java @@ -17,24 +17,22 @@ public class UT_JewishDateNavigation { @Test public void jewishForwardMonthToMonth() { - JewishDate jewishDate = new JewishDate(); jewishDate.setJewishDate(5771, 1, 1); Assert.assertEquals(5, jewishDate.getGregorianDayOfMonth()); - Assert.assertEquals(3, jewishDate.getGregorianMonth()); + Assert.assertEquals(Calendar.APRIL, jewishDate.getGregorianMonth()); Assert.assertEquals(2011, jewishDate.getGregorianYear()); } @Test public void computeRoshHashana5771() { - // At one point, this test was failing as the JewishDate class spun through a never-ending loop... JewishDate jewishDate = new JewishDate(); jewishDate.setJewishDate(5771, 7, 1); Assert.assertEquals(9, jewishDate.getGregorianDayOfMonth()); - Assert.assertEquals(8, jewishDate.getGregorianMonth()); + Assert.assertEquals(Calendar.SEPTEMBER, jewishDate.getGregorianMonth()); Assert.assertEquals(2010, jewishDate.getGregorianYear()); } diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishLeapYear.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishLeapYear.java index 96c582e3..f6907d17 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishLeapYear.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishLeapYear.java @@ -15,7 +15,6 @@ public class UT_JewishLeapYear { @Test public void isLeapYear() { - shouldBeLeapYear(5160); shouldNotBeLeapYear(5536); @@ -52,7 +51,7 @@ private void shouldBeLeapYear(int year) { JewishDate jewishDate = new JewishDate(); jewishDate.setJewishYear(year); - Assert.assertTrue(jewishDate.isJewishLeapYear( )); + Assert.assertTrue(jewishDate.isJewishLeapYear()); } @@ -60,7 +59,7 @@ private void shouldNotBeLeapYear(int year) { JewishDate jewishDate = new JewishDate(); jewishDate.setJewishYear(year); - Assert.assertFalse(jewishDate.isJewishLeapYear( )); + Assert.assertFalse(jewishDate.isJewishLeapYear()); } } // End of UT_JewishLeapYear class diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_YerushalmiTest.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_YerushalmiTest.java index ebf9f70c..d6ce2ec2 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_YerushalmiTest.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_YerushalmiTest.java @@ -1,50 +1,44 @@ package com.kosherjava.zmanim.hebrewcalendar; -import java.util.Calendar; +import static org.junit.Assert.*; import org.junit.*; -import junit.framework.TestCase; public class UT_YerushalmiTest { private static HebrewDateFormatter hdf = new HebrewDateFormatter(); static { - hdf.setHebrewFormat(true); + hdf.setHebrewFormat(true); } @Test public void testCorrectDaf1() { - JewishCalendar jewishCalendar = new JewishCalendar(5777,6,10); - Assert.assertEquals(8, jewishCalendar.getDafYomiYerushalmi().getDaf()); - Assert.assertEquals(29, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); + assertEquals(8, jewishCalendar.getDafYomiYerushalmi().getDaf()); + assertEquals(29, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiYerushalmi())); } @Test public void testCorrectDaf2() { - - JewishCalendar jewishCalendar = new JewishCalendar(5744,9,1); - Assert.assertEquals(26, jewishCalendar.getDafYomiYerushalmi().getDaf()); - Assert.assertEquals(32, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); + assertEquals(26, jewishCalendar.getDafYomiYerushalmi().getDaf()); + assertEquals(32, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiYerushalmi())); } @Test public void testCorrectDaf3() { - JewishCalendar jewishCalendar = new JewishCalendar(5782,3,1); - Assert.assertEquals(15, jewishCalendar.getDafYomiYerushalmi().getDaf()); - Assert.assertEquals(33, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); + assertEquals(15, jewishCalendar.getDafYomiYerushalmi().getDaf()); + assertEquals(33, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiYerushalmi())); } @Test public void testCorrectSpecialDate() { - JewishCalendar jewishCalendar = new JewishCalendar(5775,7,10); - Assert.assertEquals(0, jewishCalendar.getDafYomiYerushalmi().getDaf()); - Assert.assertEquals(39, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); + assertEquals(0, jewishCalendar.getDafYomiYerushalmi().getDaf()); + assertEquals(39, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiYerushalmi())); } diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/YomiCalculatorTest.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/YomiCalculatorTest.java index 79df128d..0a05dedc 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/YomiCalculatorTest.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/YomiCalculatorTest.java @@ -1,20 +1,21 @@ package com.kosherjava.zmanim.hebrewcalendar; -import org.junit.Assert; +import static org.junit.Assert.assertEquals; + import org.junit.Test; public class YomiCalculatorTest { private static HebrewDateFormatter hdf = new HebrewDateFormatter(); static { - hdf.setHebrewFormat(true); + hdf.setHebrewFormat(true); } @Test public void testCorrectDaf1() { JewishCalendar jewishCalendar = new JewishCalendar(5685, JewishDate.KISLEV, 12); Daf daf = YomiCalculator.getDafYomiBavli(jewishCalendar); - Assert.assertEquals(5, daf.getMasechtaNumber()); - Assert.assertEquals(2, daf.getDaf()); + assertEquals(5, daf.getMasechtaNumber()); + assertEquals(2, daf.getDaf()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiBavli())); } @@ -22,8 +23,8 @@ public void testCorrectDaf1() { public void testCorrectDaf2() { JewishCalendar jewishCalendar = new JewishCalendar(5736, JewishDate.ELUL, 26); Daf daf = YomiCalculator.getDafYomiBavli(jewishCalendar); - Assert.assertEquals(4, daf.getMasechtaNumber()); - Assert.assertEquals(14, daf.getDaf()); + assertEquals(4, daf.getMasechtaNumber()); + assertEquals(14, daf.getDaf()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiBavli())); } @@ -31,8 +32,8 @@ public void testCorrectDaf2() { public void testCorrectDaf3() { JewishCalendar jewishCalendar = new JewishCalendar(5777, JewishDate.ELUL, 10); Daf daf = YomiCalculator.getDafYomiBavli(jewishCalendar); - Assert.assertEquals(23, daf.getMasechtaNumber()); - Assert.assertEquals(47, daf.getDaf()); + assertEquals(23, daf.getMasechtaNumber()); + assertEquals(47, daf.getDaf()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiBavli())); } }