package com.collective.celos;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.junit.Assert;
import org.junit.Test;

public class MinutelyScheduleTest {

    @Test
    public void minutelyScheduleEmpty() {
        Schedule sch = makeMinutelySchedule();
        ScheduledTime t = new ScheduledTime("2013-11-25T20:00Z");
        Set<ScheduledTime> minutes = sch.getScheduledTimes(t, t);
        Assert.assertEquals(0, minutes.size());
    }

    @Test
    public void minutelyScheduleOneMinute() {
        Schedule sch = makeMinutelySchedule();
        ScheduledTime t1 = new ScheduledTime("2013-11-25T20:00Z");
        ScheduledTime t2 = new ScheduledTime("2013-11-25T20:01Z");
        Set<ScheduledTime> minutes = sch.getScheduledTimes(t1, t2);
        Assert.assertEquals(new TreeSet<ScheduledTime>(Arrays.asList(t1)), minutes);
    }
    
    @Test
    public void minutelyScheduleOneMinuteWithSeconds() {
        Schedule sch = makeMinutelySchedule();
        ScheduledTime t1 = new ScheduledTime("2013-11-25T20:01:05Z");
        ScheduledTime t2 = new ScheduledTime("2013-11-25T20:02:00Z");
        Set<ScheduledTime> minutes = sch.getScheduledTimes(t1, t2);
        Assert.assertEquals(0, minutes.size());
    }

    @Test
    public void minutelyScheduleSomeMinutes() {
        Schedule sch = makeMinutelySchedule();
        ScheduledTime t1 = new ScheduledTime("2013-11-25T20:05:12.00182Z");
        ScheduledTime t2 = new ScheduledTime("2013-11-25T20:08:56.2182Z");
        Set<ScheduledTime> minutes = sch.getScheduledTimes(t1, t2);
        List<ScheduledTime> expectedMinutes =
                Arrays.asList(new ScheduledTime("2013-11-25T20:06Z"),
                              new ScheduledTime("2013-11-25T20:07Z"),
                              new ScheduledTime("2013-11-25T20:08Z"));
        Assert.assertEquals(new TreeSet<ScheduledTime>(expectedMinutes), minutes);
    }
    
    @Test
    public void minutelyScheduleSomeMinutesWithStartingFullMinute() {
        Schedule sch = makeMinutelySchedule();
        ScheduledTime t1 = new ScheduledTime("2013-11-25T20:00Z");
        ScheduledTime t2 = new ScheduledTime("2013-11-25T20:03:56.2182Z");
        Set<ScheduledTime> minutes = sch.getScheduledTimes(t1, t2);
        List<ScheduledTime> expectedMinutes =
                Arrays.asList(new ScheduledTime("2013-11-25T20:00Z"),
                              new ScheduledTime("2013-11-25T20:01Z"),
                              new ScheduledTime("2013-11-25T20:02Z"),
                              new ScheduledTime("2013-11-25T20:03Z"));
        Assert.assertEquals(new TreeSet<ScheduledTime>(expectedMinutes), minutes);
    }

    private MinutelySchedule makeMinutelySchedule() {
        return new MinutelySchedule(Util.newObjectNode());
    }
    
}

@@ -255,24 +255,91 @@
 leEmpty() %7B%0A
+        // Start time equals end time%0A        // -%3E empty schedule%0A
         Sche
@@ -365,32 +365,32 @@
 telySchedule();%0A
-
         Schedule
@@ -608,32 +608,154 @@
 leOneMinute() %7B%0A
+        // Start time is full minute, end time one minute later%0A        // -%3E start time is the single minute in schedule%0A
         Schedule
@@ -1146,24 +1146,150 @@
 Seconds() %7B%0A
+        // Start time is non-full minute with some seconds,%0A        // end time one minute later%0A        // -%3E empty schedule%0A
         Sche
@@ -1640,24 +1640,190 @@
 Minutes() %7B%0A
+        // Start time is non-full minute%0A        // End time is a couple of minutes later%0A        // -%3E schedule contains all full minutes after start and before end%0A
         Sche
@@ -2429,32 +2429,32 @@
 %0A    %0A    @Test%0A
-
     public void 
@@ -2499,32 +2499,210 @@
 gFullMinute() %7B%0A
+        // Start time is full minute%0A        // End time is a couple of minutes later%0A        // -%3E schedule contains all full minutes after (and including) start and before end%0A
         Schedule

Document tests.