I'm trying to unit-test some Scala that is very collection-heavy. These collections are returned as Iterable[T]
, so I am interested in the contents of the collection, even if the underlying types differ. This is actually two related problems:
In summary, I'm looking the Scala-equivalent of NUnit's CollectionAssert.AreEqual
(ordered) and CollectionAssert.AreEquivalent
(unordered) in ScalaTest:
Set(1, 2) should equal (List(1, 2)) // ordered, pass
Iterable(2, 1) should equal (Iterable(1, 2)) // unordered, pass
Meanwhile you can use
Iterable(2, 1) should contain theSameElementsAs Iterable(1, 2)
To test the ordered set you have to convert it to a sequence.
Set(1, 2).toSeq should contain theSameElementsInOrderAs List(1, 2)