import cloud.molberg.mgutility.BrightnessSchedule; import java.util.Calendar; public final class BrightnessScheduleTest { private static long at(int hour, int minute) { return at(2026, 9, 6, hour, minute); } private static long at(int year, int month, int day, int hour, int minute) { Calendar c = Calendar.getInstance(); c.set(year, month - 1, day, hour, minute, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis(); } private static void check(boolean condition, String message) { if (!condition) throw new AssertionError(message); } public static void main(String[] args) { // Outside both transition windows: should land on the most recently completed anchor. check(BrightnessSchedule.compute(at(12, 0), 7 * 60, 21 * 60, 10, 100, 0, 50) == 100, "midday is fully peak"); check(BrightnessSchedule.compute(at(3, 0), 7 * 60, 21 * 60, 10, 100, 0, 50) == 0, "deep night is fully dark"); // The configured anchor is fully reached; the preceding minutes fade into it. check(BrightnessSchedule.compute(at(7, 0), 7 * 60, 21 * 60, 10, 100, 0, 5) == 100, "peak anchor is fully bright"); int midMorning = BrightnessSchedule.compute(at(6, 55), 7 * 60, 21 * 60, 10, 100, 0, 5); check(midMorning > 0 && midMorning < 100, "morning peak is interpolated: " + midMorning); int midAfternoon = BrightnessSchedule.compute(at(20, 55), 7 * 60, 21 * 60, 10, 100, 0, 100); check(midAfternoon > 0 && midAfternoon < 100, "evening dark is interpolated: " + midAfternoon); // Midnight wrap-around: at 23:55 the schedule should still be in dark territory. check(BrightnessSchedule.compute(at(23, 55), 7 * 60, 21 * 60, 10, 100, 0, 100) == 0, "late night is fully dark after wrap"); // Custom peak/dark percentages propagate. check(BrightnessSchedule.compute(at(12, 0), 7 * 60, 21 * 60, 10, 80, 20, 50) == 80, "custom peak percent applied"); // Zero transition still snaps at the anchor without throwing. int snapPeak = BrightnessSchedule.compute(at(7, 0), 7 * 60, 21 * 60, 1, 100, 0, 5); check(snapPeak == 100, "anchor is fully peak at peak time: " + snapPeak); int snapDark = BrightnessSchedule.compute(at(21, 0), 7 * 60, 21 * 60, 1, 100, 0, 100); check(snapDark == 0, "anchor is fully dark at dark time: " + snapDark); // Anchor after midnight with dark before peak should still work (custom config). check(BrightnessSchedule.compute(at(10, 0), 1 * 60, 11 * 60, 10, 100, 0, 50) == 100, "custom peak/dark with both daytime hours works"); check(BrightnessSchedule.compute(at(14, 0), 1 * 60, 11 * 60, 10, 100, 0, 50) == 0, "custom peak/dark with both daytime hours is dark outside"); // Format helper round-trips minutes-of-day. check("07:30".equals(BrightnessSchedule.formatMinutes(7 * 60 + 30)), "format peak"); check("00:00".equals(BrightnessSchedule.formatMinutes(0)), "format midnight"); System.out.println("BrightnessScheduleTest: OK"); } }