Guest User

Untitled

a guest
Apr 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. // libraryDependencies += "com.rklaehn" %% "intervalset" % "0.2.0"
  2.  
  3. import java.time.Instant
  4. import scala.collection.immutable.SortedSet
  5. import com.rklaehn.interval.IntervalMap.{ FromBool => IntervalMap }
  6. import org.scalatest.FunSuite
  7. import spire.algebra.{ Eq, Order }
  8. import spire.implicits.StringOrder
  9. import spire.math.Interval
  10. import spire.optional.genericEq.generic
  11.  
  12. final class IntervalMapSuite extends FunSuite {
  13. implicit def SortedSetEq[T: Eq]: Eq[SortedSet[T]] =
  14. generic[SortedSet[T]]
  15.  
  16. implicit def InstantOrder: Order[Instant] =
  17. Order.from((a, b) => a.compareTo(b))
  18.  
  19. test("two overlapping intervals") {
  20. val `00:00` = Instant.parse("2018-04-12T00:00:00Z")
  21. val `00:05` = Instant.parse("2018-04-12T00:05:00Z")
  22. val `00:10` = Instant.parse("2018-04-12T00:10:00Z")
  23. val `00:15` = Instant.parse("2018-04-12T00:15:00Z")
  24.  
  25. val intervals = Seq(
  26. Interval(`00:00`, `00:10`) -> SortedSet("foo"),
  27. Interval(`00:05`, `00:15`) -> SortedSet("bar"),
  28. )
  29.  
  30. val empty = IntervalMap.zero[Instant, SortedSet[String]]
  31. val all = intervals.map(IntervalMap(_)).foldLeft(empty)(_ | _)
  32.  
  33. assert(all(`00:00`) == SortedSet("foo"))
  34. assert(all(`00:05`) == SortedSet("foo", "bar"))
  35. assert(all(`00:10`) == SortedSet("foo", "bar"))
  36. assert(all(`00:15`) == SortedSet("bar"))
  37. }
  38. }
Add Comment
Please, Sign In to add comment