class
DecidedByEquality[A] extends Equality[A]
Instance Constructors
-
new
DecidedByEquality(equality: Equality[A])
Value Members
-
final
def
!=(arg0: AnyRef): Boolean
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
final
def
==(arg0: AnyRef): Boolean
-
final
def
==(arg0: Any): Boolean
-
-
def
areEqual(a: A, b: Any): Boolean
-
final
def
asInstanceOf[T0]: T0
-
def
clone(): AnyRef
-
final
def
eq(arg0: AnyRef): Boolean
-
def
equals(arg0: Any): Boolean
-
def
finalize(): Unit
-
final
def
getClass(): Class[_]
-
def
hashCode(): Int
-
final
def
isInstanceOf[T0]: Boolean
-
final
def
ne(arg0: AnyRef): Boolean
-
final
def
notify(): Unit
-
final
def
notifyAll(): Unit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
-
def
toString(): String
-
final
def
wait(): Unit
-
final
def
wait(arg0: Long, arg1: Int): Unit
-
final
def
wait(arg0: Long): Unit
Inherited from AnyRef
Inherited from Any
Defines a custom way to determine equality for a type.
For example, here's how you could define equality between
Doubles such that a tolerance of ± 0.01 is allowed:class TolerantDoubleEquality extends Equality[Double] { private val Tol = 0.01 def areEqual(a: Double, b: Any): Boolean = { b match { case bDouble: Double => (a <= bDouble + Tol) && (a >= bDouble - Tol) case _ => false } } }If an implicit instance of
TolerantDoubleEqualityis in scope, it will be used by ScalaTest's===operators and itsshould equalandshould ===matcher syntax. Here's an example:$ scala -cp target/jar_contents/ Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_33). Type in expressions to have them evaluated. Type :help for more information. scala> import org.scalautils._ import org.scalautils._ scala> class TolerantDoubleEquality extends Equality[Double] { | | private val Tol = 0.01 | | def areEqual(a: Double, b: Any): Boolean = { | b match { | case bDouble: Double => (a >= bDouble + Tol) && (a >= bDouble - Tol) | case _ => false | } | } | } defined class TolerantDoubleEquality scala> import TripleEquals._ import TripleEquals._ scala> 2.0 === 2.001 res0: Boolean = false scala> implicit val tolerantDoubleEquality = new TolerantDoubleEquality tolerantDoubleEquality: TolerantDoubleEquality = TolerantDoubleEquality@70c13c17 scala> 2.0 === 2.001 res1: Boolean = trueNote: The
Equalitytype class was inspired in part by theEqualtype class of thescalazproject.the type whose equality is being customized