Рассмотрите возможность определения пользовательского равенства , например,
case class A(a: Int, l: List[Int])
object A {
implicit val aEq: Equality[A] = (a: A, b: Any) => b match {
case bb: A => bb.a == a.a && bb.l.sorted == a.l.sorted
case _ => false
}
}
class ExampleSpec extends FlatSpec with Matchers {
"As" should "be equal ignoring the order of elements in lists" in {
val aa = A(100, List(2, 4))
val bb = A(100, List(4, 2))
aa should equal (bb)
}
}
или matchPattern
, например,
"As" should "be equal ignoring the order of elements in lists" in {
case class A(a: Int, l: List[Int])
val aa = A(100, List(2, 4))
val bb = A(100, List(4, 3))
aa should matchPattern { case A(a, l) if bb.a == a && bb.l.sorted == l.sorted => }
}
.