Compare

@implicitNotFound("Can\'t compare these two types:\n First type: ${A}\n Second type: ${B}\nPossible ways to fix this error:\n Alternative 1: provide an implicit instance for Compare[${A}, ${B}]\n Alternative 2: upcast either type into `Any` or a shared supertype")
trait Compare[A, B]

A type-class that is used to compare values in MUnit assertions.

By default, uses == and allows comparison between any two types as long they have a supertype/subtype relationship. For example:

  • Compare[T, T] OK
  • Compare[Some[Int], Option[Int]] OK, subtype
  • Compare[Option[Int], Some[Int]] OK, supertype
  • Compare[List[Int], collection.Seq[Int]] OK, subtype
  • Compare[List[Int], Vector[Int]] Error, requires upcast to Seq[Int]
Companion:
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def isEqual(obtained: A, expected: B): Boolean

Returns true if the values are equal according to the rules of this Compare[A, B] instance.

Returns true if the values are equal according to the rules of this Compare[A, B] instance.

The default implementation of this method uses ==.

Concrete methods

def failEqualsComparison(obtained: A, expected: B, title: Any, loc: Location, assertions: Assertions): Nothing

Throws an exception to fail this assertion when two values are not equal.

Throws an exception to fail this assertion when two values are not equal.

Override this method to customize the error message. For example, it may be helpful to generate an image/HTML file if you're comparing visual values. Anything is possible, use your imagination!

Returns:

should ideally throw a org.junit.ComparisonFailException in order to support the IntelliJ diff viewer.