Guest User

Untitled

a guest
Jul 16th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.68 KB | None | 0 0
  1. package test
  2.  
  3. import scalaz._
  4. import Scalaz._
  5. import test.IRange.Increment
  6.  
  7. sealed trait Limit[+Z] {
  8. def open : Boolean
  9. def bound : Option[Z]
  10. final def closed = !open
  11. }
  12.  
  13. sealed trait UpperBound[+Z] extends Limit[Z] {
  14. def ≥[ZZ >: Z : Order](p : => ZZ) : Boolean
  15. def ≤[ZZ >: Z : Order](p : => ZZ) : Boolean
  16.  
  17. final def meets[ZZ >: Z : Order](lb : LowerBound[ZZ]) = (bound |@| lb.bound) { _ == _ } getOrElse false
  18. final def ≤[ZZ >: Z : Order](lower : LowerBound[ZZ]) : Boolean = lower.bound.forall(lb => this ≤ lb)
  19. final def ≥[ZZ >: Z : Order](lower : LowerBound[ZZ]) : Boolean = lower ≤ this
  20. final def ≥[ZZ >: Z : Order](that : UpperBound[ZZ]) : Boolean = that.bound.forall(tb => this ≥ tb || (this.bound.forall(tb==) && (this.closed || that.open)))
  21. final def intersects[ZZ >: Z : Order](lb : LowerBound[ZZ]) = meets(lb) && closed && lb.closed
  22. }
  23. sealed trait LowerBound[+Z] extends Limit[Z] {
  24. def ≥[ZZ >: Z : Order](p : => ZZ) : Boolean
  25. def ≤[ZZ >: Z : Order](p : => ZZ) : Boolean
  26.  
  27. final def meets[ZZ >: Z : Order](ub : UpperBound[ZZ]) = (bound |@| ub.bound) { _ == _ } getOrElse false
  28. final def ≥[ZZ >: Z : Order](upper : UpperBound[ZZ]) : Boolean = upper.bound.forall(ub => this ≥ ub)
  29. final def ≤[ZZ >: Z : Order](upper : UpperBound[ZZ]) : Boolean = upper.bound.forall(ub => (this ≤ ub) && (!this.bound.forall(ub==) || (this.open || upper.closed)))
  30. final def ≤[ZZ >: Z : Order](that : LowerBound[ZZ]) : Boolean = that.bound.forall(tb => this ≤ tb || (this.bound.forall(tb==) && (this.closed || that.open)))
  31. final def intersects[ZZ >: Z : Order](ub : UpperBound[ZZ]) = meets(ub) && closed && ub.closed
  32. }
  33.  
  34. private case object NoLowerBound extends LowerBound[⊥] {
  35. def open = true
  36. def bound = None
  37.  
  38. def ≥[ZZ >: ⊥ : Order](p : => ZZ) : Boolean = false
  39. def ≤[ZZ >: ⊥ : Order](p : => ZZ) : Boolean = true
  40. override def toString = "(-"
  41. }
  42.  
  43. private case object NoUpperBound extends UpperBound[⊥] {
  44. def open = true
  45. def bound = None
  46.  
  47. def ≥[ZZ >: ⊥ : Order](p : => ZZ) : Boolean = true
  48. def ≤[ZZ >: ⊥ : Order](p : => ZZ) : Boolean = false
  49. override def toString = "-)"
  50. }
  51.  
  52. private case class UpperLimit[Z : Order](point : Z, open : Boolean) extends UpperBound[Z] {
  53. def bound = some(point)
  54.  
  55. def ≥[ZZ >: Z : Order](p : => ZZ) : Boolean = p ≨ point || (point == p && closed)
  56. def ≤[ZZ >: Z : Order](p : => ZZ) : Boolean = p ≩ point || (point == p && closed)
  57. override def toString = point.toString + (if (open) ")" else "]")
  58. }
  59.  
  60. object IRange {
  61. trait Increment[I] {
  62. def increment(i : I) : I
  63. }
  64. object Increment {
  65. implicit val IntIncrement = new Increment[Int] {
  66. def increment(i : Int) = i + 1
  67. }
  68. implicit val LongIncrement = new Increment[Long] {
  69. def increment(l : Long) = l + 1L
  70. }
  71. }
  72.  
  73. class RangeFactory[Z](lower : Z)(implicit order : Order[Z], inc : Increment[Z] = null) {
  74. def +:~:+(upper : Z) : IRange[Z] = ZRange(LowerLimit(lower, false), UpperLimit(upper, false))
  75. def -:~:+(upper : Z) : IRange[Z]= ZRange(LowerLimit(lower, true), UpperLimit(upper, false))
  76. def +:~:-(upper : Z) : IRange[Z]= ZRange(LowerLimit(lower, false), UpperLimit(upper, true))
  77. def -:~:-(upper : Z) : IRange[Z]= ZRange(LowerLimit(lower, true), UpperLimit(upper, true))
  78.  
  79. def +:/ : IRange[Z]= ZRange(LowerLimit(lower, false), NoUpperBound)
  80. def +:\ : IRange[Z]= ZRange(NoLowerBound, UpperLimit(lower, false))
  81. def -:/ : IRange[Z]= ZRange(LowerLimit(lower, true), NoUpperBound)
  82. def -:\ : IRange[Z]= ZRange(NoLowerBound, UpperLimit(lower, true))
  83. }
  84.  
  85. implicit def order2rangefactory[Z](lower : Z)(implicit order : Order[Z], inc : Increment[Z] = null) = new RangeFactory(lower)
  86. def point[Z](p : Z)(implicit order : Order[Z], inc : Increment[Z] = null) = p +:~:+ p
  87. def complete[Z](implicit order : Order[Z], inc : Increment[Z] = null) : IRange[Z] = ZRange(NoLowerBound, NoUpperBound)
  88.  
  89. def empty[Z](implicit order : Order[Z], inc : Increment[Z] = null) : IRange[Z] = EmptyRange
  90.  
  91. implicit def IRangeZero[A : Order] = new Zero[IRange[A]] {
  92. val zero = empty[A]
  93. }
  94.  
  95. implicit def IRangeEqual[A : Equal] : Equal[IRange[A]] = equalA
  96. }
  97.  
  98. sealed trait IRange[+Z] {
  99. def apply[ZZ >: Z : Order](z : ZZ) : Boolean
  100. def upperBound : Option[Z]
  101. def lowerBound : Option[Z]
  102. def closedAtUpper : Boolean
  103. def closedAtLower : Boolean
  104. def isEmpty : Boolean
  105. def contains[ZZ >: Z : Order](that : IRange[ZZ]) : Boolean
  106. def meetsAtPoint[ZZ >: Z : Order](that : IRange[ZZ]): Boolean
  107. def intersectsAtPoint[ZZ >: Z : Order](that : IRange[ZZ]) : Boolean
  108. def intersects[ZZ >: Z : Order](that : IRange[ZZ]) : Boolean
  109. def toStream[ZZ >: Z](implicit li : Increment[ZZ], order : Order[ZZ]) : Stream[ZZ]
  110.  
  111. final def closed = closedAtUpper && closedAtLower
  112. final def boundedBelow = lowerBound.isDefined
  113. final def boundedAbove = upperBound.isDefined
  114. final def bounded = boundedBelow && boundedAbove
  115. final def isComplete = !boundedBelow && !boundedAbove
  116. final def nonEmpty = !isEmpty
  117. final def containedBy[ZZ >: Z : Order](that : IRange[ZZ]) = that contains this
  118. final def singlePoint = ~((lowerBound |@| upperBound) { _ == _ })
  119. }
  120.  
  121. case object EmptyRange extends IRange[⊥] {
  122. def apply[ZZ >: ⊥ : Order](z : ZZ) : Boolean = false
  123. def isEmpty = true
  124. def closedAtLower = false
  125. def closedAtUpper = false
  126. def lowerBound = None
  127. def upperBound = None
  128. def apply(nothing : ⊥) = false
  129. def contains[Z >: ⊥ : Order](that : IRange[Z]) = false
  130.  
  131. def toStream[Z >: ⊥](implicit li: Increment[Z], order : Order[Z]) = Stream.empty
  132. def intersects[Z >: ⊥ : Order](that: IRange[Z]) = false
  133. def intersectsAtPoint[Z >: ⊥ : Order](that: IRange[Z]) = false
  134. def meetsAtPoint[Z >: ⊥ : Order](that: IRange[Z]) = false
  135.  
  136. }
  137.  
  138. private case class LowerLimit[Z : Order](point : Z, open : Boolean) extends LowerBound[Z] {
  139. def bound = some(point)
  140.  
  141. def ≤[ZZ >: Z : Order](p : => ZZ) = p ≩ point || (point == p && closed)
  142. def ≥[ZZ >: Z : Order](p : => ZZ) = p ≨ point || (point == p && closed)
  143. override def toString = (if (open) "(" else "[") + point.toString
  144. }
  145.  
  146. case object ZRange {
  147. implicit def ZRangeShow[A] = new Show[ZRange[A]] {
  148. def show(a: ZRange[A]) = { (a.lowerLimit.toString + ", " + a.upperLimit.toString).toList}
  149. }
  150.  
  151. }
  152.  
  153. case class ZRange[Z] private[test](private val lowerLimit : LowerBound[Z], private val upperLimit : UpperBound[Z])(implicit order : Order[Z], inc : Increment[Z] = null)
  154. extends IRange[Z] {
  155. require(lowerLimit ≤ upperLimit, lowerLimit + ", " + upperLimit + " is not a valid range: (lb is not <= ub)")
  156. private def notEmptyIfIncrement = Option(inc).forall(inc => !(lowerLimit.open && upperLimit.open && ~((lowerBound |@| upperBound) { inc.increment(_) ≥ _ }) ))
  157. require(notEmptyIfIncrement, "Invalid Range (can contain no elements) on discrete element type: " + lowerLimit + ", " + upperLimit)
  158.  
  159. def isEmpty = false
  160. def upperBound = upperLimit.bound
  161. def lowerBound = lowerLimit.bound
  162. def closedAtUpper = upperLimit.closed
  163. def closedAtLower = lowerLimit.closed
  164.  
  165. override def apply[ZZ >: Z : Order](p: ZZ) = (lowerLimit ≤ p) && (upperLimit ≥ p)
  166.  
  167. def contains[ZZ >: Z : Order](other : IRange[ZZ]) : Boolean = other match {
  168. case that : ZRange[ZZ] => (upperLimit ≥ that.upperLimit) && (lowerLimit ≤ that.lowerLimit)
  169. case _ => true //empty
  170. }
  171.  
  172. def entirelyBefore(that : ZRange[Z]) = !(that.lowerLimit ≥ upperLimit)
  173. def entirelyAfter(that : ZRange[Z]) = !(that.upperLimit ≤ lowerLimit)
  174.  
  175.  
  176. def meetsAtPoint[ZZ >: Z : Order](other : IRange[ZZ]) = other match {
  177. case that : ZRange[ZZ] => (lowerLimit meets that.upperLimit) || (upperLimit meets that.lowerLimit)
  178. case _ => false //empty
  179. }
  180. def intersectsAtPoint[ZZ >: Z : Order](other : IRange[ZZ]) = other match {
  181. case that: ZRange[ZZ] => (lowerLimit intersects that.upperLimit) || (upperLimit intersects that.lowerLimit)
  182. case _ => false //empty
  183. }
  184.  
  185. def intersects[ZZ >: Z : Order](other : IRange[ZZ]) = other match {
  186. case that : ZRange[ZZ] => this.upperLimit ≥ that.lowerLimit && this.lowerLimit ≤ that.upperLimit
  187. case _ => false //empty
  188. }
  189.  
  190. def toStream[ZZ >: Z](implicit li : Increment[ZZ], order : Order[ZZ]) : Stream[ZZ] = {
  191. def fromFirst(lb : Z) : Stream[ZZ] = {
  192. def first = {
  193. if (closedAtLower)
  194. lb
  195. else {
  196. val next = li.increment(lb)
  197. require(apply(next), "Invalid range: " + this)
  198. next
  199. }
  200. }
  201. first.iterate[Stream](z => li increment z)
  202. }
  203. (lowerBound -> upperBound) match {
  204. case (None, _) => error("Cannot Stream range unbounded below: " + this)
  205. case (Some(lb), _) => fromFirst(lb) takeWhile (this apply _)
  206. }
  207. }
  208. }
  209.  
  210. import org.scalatest._
  211. import matchers._
  212. class ZRangeSpec extends Spec with ShouldMatchers {
  213. import IRange._
  214. describe("ZRange") {
  215.  
  216. it("should not allow discrete open unit ranges") {
  217. intercept[IllegalArgumentException](1 -:~:- 2)
  218. }
  219.  
  220.  
  221. it("should honour intersects at point") {
  222. point(1) intersectsAtPoint point(1) should be(true)
  223. point(1) intersectsAtPoint point(2) should be(false)
  224. point(2) intersectsAtPoint point(1) should be(false)
  225. point(1) intersectsAtPoint (1 +:~:+ 2) should be(true)
  226. (1 +:~:+ 2) intersectsAtPoint point(1) should be(true)
  227.  
  228. point(1) intersectsAtPoint (1 +:/) should be(true)
  229. (1 +:/) intersectsAtPoint point(1) should be(true)
  230. point(1) intersectsAtPoint (1 +:\) should be(true)
  231. (1 +:\) intersectsAtPoint point(1) should be(true)
  232.  
  233. point(1) intersectsAtPoint (1 -:/) should be(false)
  234. (1 -:/) intersectsAtPoint point(1) should be(false)
  235. point(1) intersectsAtPoint (1 -:\) should be(false)
  236. (1 -:\) intersectsAtPoint point(1) should be(false)
  237.  
  238. (2 +:~:- 3) intersectsAtPoint (1 -:~:+ 2) should be(true)
  239. (1 -:~:+ 2) intersectsAtPoint (2 +:~:- 3) should be(true)
  240.  
  241. (1 +:~:- 5) intersectsAtPoint (2 -:~:- 4) should be(false)
  242. (2 -:~:- 4) intersectsAtPoint (1 +:~:- 5) should be(false)
  243. }
  244.  
  245. it("should honour meets at point") {
  246. point(1) meetsAtPoint point(1) should be(true)
  247. point(1) meetsAtPoint point(2) should be(false)
  248. point(2) meetsAtPoint point(1) should be(false)
  249. point(1) meetsAtPoint (1 +:~:+ 2) should be(true)
  250. (1 +:~:+ 2) meetsAtPoint point(1) should be(true)
  251.  
  252. point(1) meetsAtPoint (1 +:/) should be(true)
  253. (1 +:/) meetsAtPoint point(1) should be(true)
  254. point(1) meetsAtPoint (1 +:\) should be(true)
  255. (1 +:\) meetsAtPoint point(1) should be(true)
  256.  
  257. point(1) meetsAtPoint (1 -:/) should be(true)
  258. (1 -:/) meetsAtPoint point(1) should be(true)
  259. point(1) meetsAtPoint (1 -:\) should be(true)
  260. (1 -:\) meetsAtPoint point(1) should be(true)
  261.  
  262. (2 +:~:- 3) meetsAtPoint (1 -:~:+ 2) should be(true)
  263. (1 -:~:+ 2) meetsAtPoint (2 +:~:- 3) should be(true)
  264.  
  265. (1 +:~:- 5) meetsAtPoint (2 -:~:- 4) should be(false)
  266. (2 -:~:- 4) meetsAtPoint (1 +:~:- 5) should be(false)
  267. }
  268.  
  269. it("should not allow zero-length open ranges") {
  270. intercept[IllegalArgumentException](1 -:~:- 1)
  271. intercept[IllegalArgumentException](1 +:~:- 1)
  272. intercept[IllegalArgumentException](1 -:~:+ 1)
  273. }
  274.  
  275. it("should contain other ranges where appropriate") {
  276. (-2 +:~:+ 2) contains (-1 +:~:+ 1) should be(true)
  277. (-2 -:~:+ 2) contains (-1 +:~:+ 1) should be(true)
  278. (-2 +:~:- 2) contains (-1 +:~:+ 1) should be(true)
  279. (-2 -:~:- 2) contains (-1 +:~:+ 1) should be(true)
  280.  
  281. (-2 +:~:+ 2) contains (-1 +:~:- 1) should be(true)
  282. (-2 -:~:+ 2) contains (-1 +:~:- 1) should be(true)
  283. (-2 +:~:- 2) contains (-1 +:~:- 1) should be(true)
  284. (-2 -:~:- 2) contains (-1 +:~:- 1) should be(true)
  285.  
  286. (-2 +:~:+ 2) contains (-1 -:~:+ 1) should be(true)
  287. (-2 -:~:+ 2) contains (-1 -:~:+ 1) should be(true)
  288. (-2 +:~:- 2) contains (-1 -:~:+ 1) should be(true)
  289. (-2 -:~:- 2) contains (-1 -:~:+ 1) should be(true)
  290.  
  291. (-2 +:~:+ 2) contains (-1 -:~:- 1) should be(true)
  292. (-2 -:~:+ 2) contains (-1 -:~:- 1) should be(true)
  293. (-2 +:~:- 2) contains (-1 -:~:- 1) should be(true)
  294. (-2 -:~:- 2) contains (-1 -:~:- 1) should be(true)
  295.  
  296. (-1 +:~:+ 2) contains (-1 +:~:+ 1) should be(true)
  297. (-1 -:~:+ 2) contains (-1 +:~:- 1) should be(false)
  298. (-1 +:~:- 2) contains (-1 -:~:- 1) should be(true)
  299. (-2 -:~:- 2) contains (-1 +:~:+ 1) should be(true)
  300.  
  301. (-1 +:~:+ 1) contains (-1 +:~:+ 1) should be(true)
  302. (-1 -:~:+ 1) contains (-1 +:~:+ 1) should be(false)
  303. (-1 +:~:- 1) contains (-1 +:~:+ 1) should be(false)
  304. (-1 -:~:- 1) contains (-1 +:~:+ 1) should be(false)
  305.  
  306. (-1 +:~:+ 1) contains (-1 +:~:- 1) should be(true)
  307. (-1 -:~:+ 1) contains (-1 +:~:- 1) should be(false)
  308. (-1 +:~:- 1) contains (-1 +:~:- 1) should be(true)
  309. (-1 -:~:- 1) contains (-1 +:~:- 1) should be(false)
  310.  
  311. (-1 +:~:+ 1) contains (-1 -:~:+ 1) should be(true)
  312. (-1 -:~:+ 1) contains (-1 -:~:+ 1) should be(true)
  313. (-1 +:~:- 1) contains (-1 -:~:+ 1) should be(false)
  314. (-1 -:~:- 1) contains (-1 -:~:+ 1) should be(false)
  315.  
  316. (-1 +:~:+ 1) contains (-1 -:~:- 1) should be(true)
  317. (-1 -:~:+ 1) contains (-1 -:~:- 1) should be(true)
  318. (-1 +:~:- 1) contains (-1 -:~:- 1) should be(true)
  319. (-1 -:~:- 1) contains (-1 -:~:- 1) should be(true)
  320. }
  321.  
  322. it("should intersect other bounded ranges") {
  323. (-2 +:~:+ 1) intersects (-1 +:~:+ 2) should be(true)
  324. (-1 +:~:+ 2) intersects (-2 +:~:+ 1) should be(true)
  325. (-2 -:~:+ 1) intersects (-1 +:~:+ 2) should be(true)
  326. (-1 +:~:+ 2) intersects (-2 -:~:+ 1) should be(true)
  327. (-2 +:~:- 1) intersects (-1 +:~:+ 2) should be(true)
  328. (-1 +:~:+ 2) intersects (-2 +:~:- 1) should be(true)
  329. (-2 -:~:- 1) intersects (-1 +:~:+ 2) should be(true)
  330. (-1 +:~:+ 2) intersects (-2 -:~:- 1) should be(true)
  331. }
  332.  
  333. it("should not intersect with disjoint ranges") {
  334. (-2 +:~:+ -1) intersects (1 +:~:+ 2) should be(false)
  335. (-2 +:~:- -1) intersects (1 +:~:+ 2) should be(false)
  336. (-2 -:~:+ -1) intersects (1 +:~:+ 2) should be(false)
  337. (-3 -:~:- -1) intersects (1 +:~:+ 2) should be(false)
  338.  
  339. (-1 +:~:+ 0) intersects (0 +:~:+ 1) should be(true)
  340. (-1 +:~:- 0) intersects (0 +:~:+ 1) should be(false)
  341. (-1 -:~:+ 0) intersects (0 -:~:+ 1) should be(false)
  342. (-2 -:~:- 0) intersects (0 -:~:+ 1) should be(false)
  343.  
  344. (0 -:~:- 2) intersects (2 -:~:+ 4) should be(false)
  345. }
  346.  
  347. it("should contain points") {
  348. (-1 +:~:+ 1) apply -1 should be(true)
  349. (-1 +:~:+ 1) apply 0 should be(true)
  350. (-1 +:~:+ 1) apply 1 should be(true)
  351.  
  352. (-1 +:~:- 1) apply -1 should be(true)
  353. (-1 +:~:- 1) apply 0 should be(true)
  354. (-1 +:~:- 1) apply 1 should be(false)
  355.  
  356. (-1 -:~:+ 1) apply -1 should be(false)
  357. (-1 -:~:+ 1) apply 0 should be(true)
  358. (-1 -:~:+ 1) apply 1 should be(true)
  359.  
  360. (-1 -:~:- 1) apply -1 should be(false)
  361. (-1 -:~:- 1) apply 0 should be(true)
  362. (-1 -:~:- 1) apply 1 should be(false)
  363. }
  364.  
  365. it("should have a complete range") {
  366. complete[Int].isComplete should be(true)
  367. complete[Int] contains complete[Int] should be(true)
  368. complete[Int] contains (-1 +:~:+ 1) should be(true)
  369. complete[Int] contains (-1 +:~:- 1) should be(true)
  370. complete[Int] contains (-1 -:~:+ 1) should be(true)
  371. complete[Int] contains (-1 -:~:- 1) should be(true)
  372. complete[Int] apply 0 should be(true)
  373. }
  374.  
  375. it("should convert toStream") {
  376. import IRange.Increment._
  377. intercept[RuntimeException](complete[Int].toStream)
  378. intercept[RuntimeException]((0 +:\).toStream)
  379. intercept[RuntimeException]((0 -:\).toStream)
  380. (0 +:/).toStream.head should be(0)
  381. (0 -:/).toStream.head should be(1)
  382.  
  383. (0 +:~:+ 5 ).toStream.toList should equal(List(0, 1, 2, 3, 4, 5))
  384. (0 -:~:+ 5 ).toStream.toList should equal(List(1, 2, 3, 4, 5))
  385. (0 +:~:- 5 ).toStream.toList should equal(List(0, 1, 2, 3, 4))
  386. (0 -:~:- 5 ).toStream.toList should equal(List(1, 2, 3, 4))
  387.  
  388. IRange.empty[Int].toStream should equal(Stream.empty)
  389. }
  390.  
  391. it("should have a sensible empty range") {
  392. empty[Int] apply 0 should be(false)
  393.  
  394. empty[Int] contains (-1 -:~:- 1) should be(false)
  395. empty[Int] contains (-1 +:~:- 1) should be(false)
  396. empty[Int] contains (-1 -:~:+ 1) should be(false)
  397. empty[Int] contains (-1 +:~:+ 1) should be(false)
  398.  
  399. (-1 -:~:- 1) contains empty[Int] should be(true)
  400. (-1 -:~:+ 1) contains empty[Int] should be(true)
  401. (-1 +:~:- 1) contains empty[Int] should be(true)
  402. (-1 +:~:+ 1) contains empty[Int] should be(true)
  403.  
  404.  
  405. empty[Int] intersects (-1 -:~:- 1) should be(false)
  406. empty[Int] intersects (-1 +:~:- 1) should be(false)
  407. empty[Int] intersects (-1 -:~:+ 1) should be(false)
  408. empty[Int] intersects (-1 +:~:+ 1) should be(false)
  409. (-1 -:~:- 1) intersects empty[Int] should be(false)
  410. (-1 -:~:+ 1) intersects empty[Int] should be(false)
  411. (-1 +:~:- 1) intersects empty[Int] should be(false)
  412. (-1 +:~:+ 1) intersects empty[Int] should be(false)
  413.  
  414. empty[Int] meetsAtPoint (-1 -:~:- 1) should be(false)
  415. empty[Int] meetsAtPoint (-1 +:~:- 1) should be(false)
  416. empty[Int] meetsAtPoint (-1 -:~:+ 1) should be(false)
  417. empty[Int] meetsAtPoint (-1 +:~:+ 1) should be(false)
  418. (-1 -:~:- 1) meetsAtPoint empty[Int] should be(false)
  419. (-1 -:~:+ 1) meetsAtPoint empty[Int] should be(false)
  420. (-1 +:~:- 1) meetsAtPoint empty[Int] should be(false)
  421. (-1 +:~:+ 1) meetsAtPoint empty[Int] should be(false)
  422.  
  423. IRange.empty[Long].isEmpty should be(true)
  424. IRange.empty[Long].nonEmpty should be(false)
  425.  
  426. }
  427.  
  428. it("should be covariant in the element type") {
  429. def call(r : IRange[Any]) = r
  430.  
  431. val ir: IRange[Int] = 1 +:~:- 2
  432. call(ir) should be(ir)
  433.  
  434. val ar : IRange[AnyVal] = IRange.empty[Boolean]
  435. call(ar) should be(ar)
  436. }
  437.  
  438. }
  439. }
Add Comment
Please, Sign In to add comment