Scalactic User Guide

Custom equality

Default equality

Constrained equality

Tolerance

Normalization

The Explicitly DSL

Or and Every

Requirements

Snapshots

TimesOnInt

Default equality

Scalactic defines a default Equality that treats arrays specially. Its areEqual method works by first calling .deep on any passed array, then calling == on the resulting left-hand object, passing in the resulting right-hand object. If a more specific implicit Equality is not available for the left-hand type in an === or !== expression, default equality will be used.

Here are some examples showing the special treatment of arrays:

scala> import org.scalactic._
import org.scalactic._

scala> import TripleEquals._
import TripleEquals._

scala> Array(1, 2, 3) == Array(1, 2, 3)
res0: Boolean = false

scala> Array(1, 2, 3) === Array(1, 2, 3)
res1: Boolean = true

scala> Array(1, 2, 3) == List(1, 2, 3)
<console>:14: warning: comparing values of types Array[Int] and List[Int] using `==' will always yield false
              Array(1, 2, 3) == List(1, 2, 3)
                             ^
res2: Boolean = false

scala> Array(1, 2, 3) === List(1, 2, 3)
res3: Boolean = true

scala> List(1, 2, 3) == Array(1, 2, 3)
res4: Boolean = false

scala> List(1, 2, 3) === Array(1, 2, 3)
res5: Boolean = true

You can obtain a default equality via the default method of the Equality companion object, or from the defaultEquality method defined in TripleEqualsSupport.

Next, learn about Constrained equality.

Scalactic is brought to you by Bill Venners, with contributions from several other folks. It is sponsored by Artima, Inc.
ScalaTest is free, open-source software released under the Apache 2.0 license.

Copyright © 2009-2024 Artima, Inc. All Rights Reserved.

artima