Re: AbstractTraversable.headOption throws NoSuchElementException

Jason Zaugg <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <CAG3_yeVfJEV8tXej0v=fRecbj8B=3No0qsonxs2m+xEyNj1ntw@mail.gmail.com>
On Thu, May 7, 2015 at 9:20 AM, Erik Osheim <[email protected]>
wrote:

> On Wed, May 06, 2015 at 12:58:06PM -0700, Rex Kerr wrote:
> > I'm not sure there's any way to catch wonky usages of the API except to
> try
> > them and see what happens (and submit a bug report to the offending
> project
> > if it does something weird).
>
> This might be overkill for Scala collections, but I could imagine
> publishing a laws package that encodes the invariants for each
> collection type, allowing folks to easily test their own custom
> implementations against the expectations of the API/library.
>
> For example, I could imagine testing the following properties:
>
>     // C[A] <: Iterable[A]
>     forAll { (xs: C[A]) =>
>       val lst1 = xs.iterator.toList
>       val lst2 = xs.iterator.toList
>       lst1 shouldBe lst2
>
>       xs.size shouldBe xs.iterator.size
>
>       xs.isEmpty shouldBe xs.iterator.isEmpty
>
>       // ...and so on
>     }
>
> I just thought I'd mention this, since the strategy of exporting laws
> to test against has been pretty successful in the "functional" corner
> of the Scala ecosystem.
>

Rex Kerr has been working on something like this for the collections:

  https://github.com/scala/scala-collections-laws

So far, our focus has been on using this to test the standard collections,
we haven't documented how to use this for your own collections.

Unlike traditional reusable property based tests, this suite uses code
generation so that interactions with type inference and implicit search for
the relevant CanBuildFrom is tested.

-jason

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.