Search in sources :

Example 6 with TimeOfDay

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));
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with TimeOfDay

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);
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 8 with TimeOfDay

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);
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 9 with TimeOfDay

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());
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 10 with TimeOfDay

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);
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Aggregations

TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)25 Test (org.junit.Test)23 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)17 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)16 Interval (org.joda.time.Interval)15 LocalDateTime (org.joda.time.LocalDateTime)11 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)8 ArrayList (java.util.ArrayList)2 Timeframe (de.avanux.smartapplianceenabler.schedule.Timeframe)1