use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.
the class RunningTimeMonitorTest method getRemainingMinRunningTimeOfCurrentTimeFrame_2TimeFrames.
@Test
public void getRemainingMinRunningTimeOfCurrentTimeFrame_2TimeFrames() {
List<Schedule> schedules = new ArrayList<Schedule>();
schedules.add(new Schedule(600, null, new TimeOfDay(11, 0, 0), new TimeOfDay(12, 0, 0)));
schedules.add(new Schedule(1200, null, new TimeOfDay(14, 0, 0), new TimeOfDay(15, 0, 0)));
runningTimeMonitor.setSchedules(schedules);
//
// 1. timeframe
//
runningTimeMonitor.updateActiveTimeframeInterval(toToday(10, 00, 0));
Assert.assertNull("Timeframe not yet started should return NULL", runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(10, 0, 0)));
runningTimeMonitor.updateActiveTimeframeInterval(toToday(11, 00, 0));
Assert.assertEquals("With timeframe started but device switched off max running time should be returned", 600, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(11, 20, 0)).intValue());
runningTimeMonitor.setRunning(true, toToday(11, 30, 0));
Assert.assertEquals("With timeframe started and device switched on max running time should be reduced by 5 minutes", 300, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(11, 35, 0)).intValue());
Assert.assertEquals("Running time has to be 0 at the end of the timeframe", 0, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(11, 40, 0)).intValue());
runningTimeMonitor.setRunning(false, toToday(11, 40, 0));
Assert.assertEquals("Running time has to be 0 at the end of running time", 0, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(11, 45, 0)).intValue());
runningTimeMonitor.updateActiveTimeframeInterval(toToday(12, 00, 0));
//
// 2. timeframe
//
runningTimeMonitor.updateActiveTimeframeInterval(toToday(13, 00, 0));
Assert.assertNull("Timeframe not yet started should return NULL", runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(13, 45, 0)));
runningTimeMonitor.updateActiveTimeframeInterval(toToday(14, 00, 0));
Assert.assertEquals("With timeframe started but device switched off max running time should be returned", 1200, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(14, 10, 0)).intValue());
runningTimeMonitor.setRunning(true, toToday(14, 15, 0));
Assert.assertEquals("With timeframe started and device switched on max running time should be reduced by 5 minutes", 900, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(14, 20, 0)).intValue());
Assert.assertEquals("Min running time has been exceeded by 10 minutes", -600, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(14, 45, 0)).intValue());
runningTimeMonitor.setRunning(false, toToday(14, 45, 0));
Assert.assertEquals("Running time after power off is 0", 0, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(14, 45, 0)).intValue());
runningTimeMonitor.updateActiveTimeframeInterval(toToday(15, 00, 0));
}
use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.
the class DayTimeframeTest method buildMidnightAdjustedInterval_OverMidnight_AfterInterval_AfterMidnight.
@Test
public void buildMidnightAdjustedInterval_OverMidnight_AfterInterval_AfterMidnight() {
DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(22, 0, 0), new TimeOfDay(2, 0, 0));
Interval interval = timeframe.buildMidnightAdjustedInterval(toToday(3, 0, 0));
Assert.assertEquals(new Interval(toToday(22, 0, 0).toDateTime(), toDay(1, 2, 0, 0).toDateTime()), interval);
}
use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.
the class DayTimeframeTest method buildMidnightAdjustedInterval_OverMidnight_WithinInterval_AfterMidnight.
@Test
public void buildMidnightAdjustedInterval_OverMidnight_WithinInterval_AfterMidnight() {
DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(22, 0, 0), new TimeOfDay(2, 0, 0));
Interval interval = timeframe.buildMidnightAdjustedInterval(toToday(1, 0, 0));
Assert.assertEquals(new Interval(toDay(-1, 22, 0, 0).toDateTime(), toToday(2, 0, 0).toDateTime()), interval);
}
use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.
the class DayTimeframeTest method getIntervals_AllDayOfWeek_WithinInterval.
@Test
public void getIntervals_AllDayOfWeek_WithinInterval() {
DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0));
List<TimeframeInterval> intervals = timeframe.getIntervals(toToday(11, 0, 0));
Assert.assertEquals(7, intervals.size());
Assert.assertEquals(new Interval(toToday(10, 0, 0).toDateTime(), toToday(12, 0, 0).toDateTime()), intervals.get(0).getInterval());
Assert.assertEquals(new Interval(toDay(1, 10, 0, 0).toDateTime(), toDay(1, 12, 0, 0).toDateTime()), intervals.get(1).getInterval());
Assert.assertEquals(new Interval(toDay(2, 10, 0, 0).toDateTime(), toDay(2, 12, 0, 0).toDateTime()), intervals.get(2).getInterval());
Assert.assertEquals(new Interval(toDay(3, 10, 0, 0).toDateTime(), toDay(3, 12, 0, 0).toDateTime()), intervals.get(3).getInterval());
Assert.assertEquals(new Interval(toDay(4, 10, 0, 0).toDateTime(), toDay(4, 12, 0, 0).toDateTime()), intervals.get(4).getInterval());
Assert.assertEquals(new Interval(toDay(5, 10, 0, 0).toDateTime(), toDay(5, 12, 0, 0).toDateTime()), intervals.get(5).getInterval());
Assert.assertEquals(new Interval(toDay(6, 10, 0, 0).toDateTime(), toDay(6, 12, 0, 0).toDateTime()), intervals.get(6).getInterval());
}
use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.
the class DayTimeframeTest method buildMidnightAdjustedInterval_NotOverMidnight.
@Test
public void buildMidnightAdjustedInterval_NotOverMidnight() {
DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(22, 0, 0), new TimeOfDay(23, 0, 0));
Interval interval = timeframe.buildMidnightAdjustedInterval(toToday(9, 0, 0));
Assert.assertEquals(new Interval(toToday(22, 0, 0).toDateTime(), toToday(23, 0, 0).toDateTime()), interval);
}
Aggregations