Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
adds failing test that detects #803
  • Loading branch information
forrestguice committed Jun 9, 2024
1 parent 4f3bb56 commit 4f2fd78
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

import com.forrestguice.suntimeswidget.SuntimesUtils;
import com.forrestguice.suntimeswidget.UnlistedTest;
import com.forrestguice.suntimeswidget.calculator.SuntimesMoonData;
import com.forrestguice.suntimeswidget.calculator.core.Location;
import com.forrestguice.suntimeswidget.calculator.core.SuntimesCalculator;
import com.forrestguice.suntimeswidget.settings.SolarEvents;
import com.forrestguice.suntimeswidget.settings.WidgetTimezones;

Expand Down Expand Up @@ -90,6 +92,76 @@ public void test_updateAlarmTime_sunEvent()
}
}

public static final Location location0 = new Location("Helsinki", "60", "25", "0");

@Test
public void test_updateAlarmTime_moonPhaseEvents()
{
SuntimesMoonData data = AlarmNotifications.getData_moonEvent(context, location0);
data.setTodayIs(getCalendar(2024, Calendar.JUNE, 1, 18, 8));
data.calculate();

Calendar newMoon = data.moonPhaseCalendar(SuntimesCalculator.MoonPhase.NEW);
Calendar firstQuarter = data.moonPhaseCalendar(SuntimesCalculator.MoonPhase.FIRST_QUARTER);
Calendar fullMoon = data.moonPhaseCalendar(SuntimesCalculator.MoonPhase.FULL);
Calendar thirdQuarter = data.moonPhaseCalendar(SuntimesCalculator.MoonPhase.THIRD_QUARTER);

SuntimesCalculator.MoonPhase[] phases = new SuntimesCalculator.MoonPhase[] { SuntimesCalculator.MoonPhase.NEW, SuntimesCalculator.MoonPhase.FIRST_QUARTER, SuntimesCalculator.MoonPhase.FULL, SuntimesCalculator.MoonPhase.THIRD_QUARTER };
Calendar[] calendars = new Calendar[] { newMoon, firstQuarter, fullMoon, thirdQuarter };

for (int i=0; i<phases.length; i++)
{
Calendar calendar = calendars[i];
calendar.add(Calendar.SECOND, 1);
int month = calendar.get(Calendar.MONTH);
int nextMonth = (month + 1);
test_updateAlarmTime_moonPhaseEvent(nextMonth, SolarEvents.valueOf(phases[i]), calendar, phases[i].name());
}
}

@Test
public void test_updateAlarmTime_moonPhaseEvents_fullMoon()
{
Calendar now = getCalendar(2024, Calendar.JUNE, 21, 18, 8);
test_updateAlarmTime_moonPhaseEvent(Calendar.JULY, SolarEvents.FULLMOON, now, "Full Moon");
}
@Test
public void test_updateAlarmTime_moonPhaseEvents_firstQuarter()
{
Calendar now = getCalendar(2024, Calendar.JUNE, 13, 22, 19);
test_updateAlarmTime_moonPhaseEvent(Calendar.JULY, SolarEvents.FIRSTQUARTER, now, "First Quarter");

now = getCalendar(2024, Calendar.JULY, 13, 15, 49);
test_updateAlarmTime_moonPhaseEvent(Calendar.AUGUST, SolarEvents.FIRSTQUARTER, now, "First Quarter");
}
@Test
public void test_updateAlarmTime_moonPhaseEvents_thirdQuarter()
{
Calendar now = getCalendar(2024, Calendar.MAY, 30, 14, 54);
test_updateAlarmTime_moonPhaseEvent(Calendar.JUNE, SolarEvents.THIRDQUARTER, now, "Third Quarter");

now = getCalendar(2024, Calendar.JUNE, 28, 14, 54);
test_updateAlarmTime_moonPhaseEvent(Calendar.JULY, SolarEvents.THIRDQUARTER, now, "Third Quarter");
}
@Test
public void test_updateAlarmTime_moonPhaseEvent_newMoon()
{
Calendar now = getCalendar(2024, Calendar.JUNE, 6, 11, 16);
test_updateAlarmTime_moonPhaseEvent(Calendar.JULY, SolarEvents.NEWMOON, now, "New Moon");
}
public void test_updateAlarmTime_moonPhaseEvent(int expectedMonth, SolarEvents eventID, Calendar now, String tag)
{
int c = 0, n = 24;
while (c < n)
{
Calendar event = AlarmNotifications.updateAlarmTime_moonPhaseEvent(context, eventID, location0, 0, true, null, now);
Log.i("TEST", tag + " " + c + " :: " + utils.calendarDateTimeDisplayString(context, now, true, false) + " :: " + utils.calendarDateTimeDisplayString(context, event, true, true).toString() + " [" + event.getTimeZone().getID() + "] " + (event.getTimeZone().inDaylightTime(event.getTime()) ? "[dst]" : "") );
assertEquals(expectedMonth, event.get(Calendar.MONTH));
now.add(Calendar.HOUR, 1);
c++;
}
}

@Test
public void test_updateAlarmTime_clockTime_ltst()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@ public static Calendar moonEventCalendar(SolarEvents event, SuntimesMoonData dat
}

@Nullable
private static Calendar updateAlarmTime_moonPhaseEvent(Context context, @NonNull SolarEvents event, @NonNull Location location, long offset, boolean repeating, @NonNull ArrayList<Integer> repeatingDays, @NonNull Calendar now)
protected static Calendar updateAlarmTime_moonPhaseEvent(Context context, @NonNull SolarEvents event, @NonNull Location location, long offset, boolean repeating, @NonNull ArrayList<Integer> repeatingDays, @NonNull Calendar now)
{
t_updateAlarmTime_runningLoop = true;
SuntimesCalculator.MoonPhase phase = event.toMoonPhase();
Expand All @@ -2341,6 +2341,7 @@ private static Calendar updateAlarmTime_moonPhaseEvent(Context context, @NonNull
Calendar alarmTime = Calendar.getInstance();

Calendar day = Calendar.getInstance();
day.setTimeInMillis(now.getTimeInMillis());
moonData.setTodayIs(day);
moonData.calculate();

Expand Down Expand Up @@ -2564,7 +2565,7 @@ private static SuntimesRiseSetData getData_sunEvent(Context context, @NonNull So
sunData.setTodayIs(Calendar.getInstance());
return sunData;
}
private static SuntimesMoonData getData_moonEvent(Context context, @NonNull Location location)
protected static SuntimesMoonData getData_moonEvent(Context context, @NonNull Location location)
{
SuntimesMoonData moonData = new SuntimesMoonData(context, 0);
moonData.setLocation(location);
Expand Down

0 comments on commit 4f2fd78

Please sign in to comment.