FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Test leap years by pnemonic78 · Pull Request #272 · KosherJava/zmanim · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ public int getMoladChalakim() {
* the month. As with other cases in this class, this is 1-based, not zero-based.
* @return the number of days in the month in the given year
*/
private static int getLastDayOfGregorianMonth(int year, int month) {
// @VisibleForTesting
protected static int getLastDayOfGregorianMonth(int year, int month) {
return YearMonth.of(year, month).lengthOfMonth();
}

Expand Down Expand Up @@ -1280,12 +1281,8 @@ public Object clone() {
return clone;
}

/**
* Overrides {@link Object#hashCode()}.
* @see Object#hashCode()
*/
@Override
public int hashCode() {
return Integer.hashCode(gregorianAbsDate);
}
@Override
public int hashCode() {
return gregorianAbsDate;
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

package com.kosherjava.zmanim.hebrewcalendar;

import static org.junit.Assert.assertEquals;

import org.junit.*;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;

/**
* Validate the days in a Hebrew month (in various types of years) are correct.
*/
Expand Down Expand Up @@ -111,4 +117,15 @@ private void assertShalemLeap(int year) {
Assert.assertTrue(jewishDate.isJewishLeapYear( ));
}

@Test
public void earlyGregorian() {
LocalDate localDate = LocalDate.of(1582, Month.OCTOBER, 15);
JewishDate jewishDate = new JewishDate(localDate);

assertEquals(DayOfWeek.FRIDAY, localDate.getDayOfWeek());
assertEquals(5343, jewishDate.getJewishYear());
assertEquals(JewishDate.TISHREI, jewishDate.getJewishMonth());
assertEquals(19, jewishDate.getJewishDayOfMonth());
}

} // End of UT_DaysInJewishMonth class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

package com.kosherjava.zmanim.hebrewcalendar;

import static org.junit.Assert.assertEquals;

import org.junit.*;

import java.time.Month;

/**
* Verify correct calculations of when a Hebrew leap year occurs.
*/
Expand Down Expand Up @@ -63,4 +67,39 @@ private void shouldNotBeLeapYear(int year) {
Assert.assertFalse(jewishDate.isJewishLeapYear( ));
}

@Test
public void icu() {
for (int y = 0; y < 10000; y++) {
assertEquals(isLeapYearICU(y), JewishDate.isJewishLeapYear(y));
}
}

/** android.icu.util.HebrewCalendar */
public static boolean isLeapYearICU(int year) {
int x = (year * 12 + 17) % 19;
return x >= ((x < 0) ? -7 : 12);
}

@Test
public void leapYears(){
final int MONTH_FEBRUARY = Month.FEBRUARY.getValue();
for (int y = 0; y < 10000; y++) {
assertEquals(isLeapYearWiki(y), JewishDate.getLastDayOfGregorianMonth(y, MONTH_FEBRUARY) == 29);
}
}

/** https://en.wikipedia.org/wiki/Leap_year#Algorithm */
private static boolean isLeapYearWiki(int year) {
if (year % 4 != 0) {
return false;
}
if (year % 100 != 0) {
return true;
}
if (year % 400 != 0) {
return false;
}
return true;
}

} // End of UT_JewishLeapYear class
Loading

Back | FazBrowse Home | New Git URL