val overlaps = list.filter(t => this.overlaps(t))
+ if (overlaps.isEmpty)
+ return List()
+
def build(acc: List[Timeslot], listPart: List[Timeslot]): List[Timeslot] = {
listPart match {
val last = overlaps.reverse.head
val start = if (head.startsAfter(this)) List(Timeslot(this.from, head.from)) else List()
- val end = if (last.endsBefore(this)) List(Timeslot(this.from, last.from)) else List()
+ val end = if (last.endsBefore(this)) List(Timeslot(last.to, this.to)) else List()
start ++ build(List(), overlaps) ++ end
}
var result = t.nonOverlappingTimeslots(list)
assertEquals(2, result.size)
-
+
+ t = Timeslot(new Date(9), new Date(20))
+ result = t.nonOverlappingTimeslots(list)
+ assertEquals(2, result.size)
+
+ t = Timeslot(new Date(9), new Date(20))
+ result = t.nonOverlappingTimeslots(list)
+ assertEquals(2, result.size)
+
+ t = Timeslot(new Date(0), new Date(20))
+ result = t.nonOverlappingTimeslots(list)
+ assertEquals(4, result.size)
+ assertEquals(Timeslot(new Date(0), new Date(1)), result.head)
+ assertEquals(Timeslot(new Date(3), new Date(6)), result.tail.head)
+
+ t = Timeslot(new Date(13), new Date(20))
+ result = t.nonOverlappingTimeslots(list)
+ assertEquals(1, result.size)
+ assertEquals(Timeslot(new Date(15), new Date(20)), result.head)
+
+ result = t.nonOverlappingTimeslots(List())
+ assertEquals(0, result.size)
}
}
\ No newline at end of file