com.sageserpent.americium.Unbounded.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of americium_3 Show documentation
Show all versions of americium_3 Show documentation
Generation of test data for parameterised testing
The newest version!
package com.sageserpent.americium
import scala.language.implicitConversions
import scala.math.Ordered
object Unbounded {
implicit def convertToOrdered[X: Ordering](
unbounded: Unbounded[X]
): Ordered[Unbounded[X]] =
(another: Unbounded[X]) =>
(unbounded, another) match {
case (Finite(thisUnlifted), Finite(anotherUnlifted)) =>
Ordering[X].compare(thisUnlifted, anotherUnlifted)
case (PositiveInfinity(), PositiveInfinity()) => 0
case (NegativeInfinity(), NegativeInfinity()) => 0
case (_, PositiveInfinity()) => -1
case (NegativeInfinity(), _) => -1
case (PositiveInfinity(), _) => 1
case (_, NegativeInfinity()) => 1
}
}
sealed trait Unbounded[X]
case class Finite[X](unlifted: X) extends Unbounded[X]
case class NegativeInfinity[X]() extends Unbounded[X]
case class PositiveInfinity[X]() extends Unbounded[X]