Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // libraryDependencies += "com.rklaehn" %% "intervalset" % "0.2.0"
- import java.time.Instant
- import scala.collection.immutable.SortedSet
- import com.rklaehn.interval.IntervalMap.{ FromBool => IntervalMap }
- import org.scalatest.FunSuite
- import spire.algebra.{ Eq, Order }
- import spire.implicits.StringOrder
- import spire.math.Interval
- import spire.optional.genericEq.generic
- final class IntervalMapSuite extends FunSuite {
- implicit def SortedSetEq[T: Eq]: Eq[SortedSet[T]] =
- generic[SortedSet[T]]
- implicit def InstantOrder: Order[Instant] =
- Order.from((a, b) => a.compareTo(b))
- test("two overlapping intervals") {
- val `00:00` = Instant.parse("2018-04-12T00:00:00Z")
- val `00:05` = Instant.parse("2018-04-12T00:05:00Z")
- val `00:10` = Instant.parse("2018-04-12T00:10:00Z")
- val `00:15` = Instant.parse("2018-04-12T00:15:00Z")
- val intervals = Seq(
- Interval(`00:00`, `00:10`) -> SortedSet("foo"),
- Interval(`00:05`, `00:15`) -> SortedSet("bar"),
- )
- val empty = IntervalMap.zero[Instant, SortedSet[String]]
- val all = intervals.map(IntervalMap(_)).foldLeft(empty)(_ | _)
- assert(all(`00:00`) == SortedSet("foo"))
- assert(all(`00:05`) == SortedSet("foo", "bar"))
- assert(all(`00:10`) == SortedSet("foo", "bar"))
- assert(all(`00:15`) == SortedSet("bar"))
- }
- }
Add Comment
Please, Sign In to add comment