typelevel / algebra

Experimental project to lay out basic algebra type classes
https://typelevel.org/algebra/
Other
378 stars 69 forks source link

Add a algebra-test package with scalacheck laws #10

Closed johnynek closed 9 years ago

johnynek commented 9 years ago

One thing we did in algebird was make an algebird-test package. Here we defined thinks like def monoidLaws[T: Arbitrary: Monoid]: Prop so users could easily test their monoids just by making an Arbitrary for their type.

It would be really nice to have something like this. If we want to generalize:

trait Law[C[_]] {
  def apply[T](structure: C[T], arb: Arbitrary[T]): Prop
}

Then we could test triples like: List(MonoidLaw, ListMonoid, implicitly[Arbitrary[List[Int]]], ...)

tixxit commented 9 years ago

We do something similar in Spire with Discipline (https://github.com/non/spire/tree/master/scalacheck-binding/src/main/scala/spire/laws) - I think @non was going to copy these tests over or follow a similar strategy.

non commented 9 years ago

Yes, definitely. My plan is to port over the discipline laws (assuming we are OK with a test dependency on Discipline). I was going to wait until we had hammered out exactly what we wanted, but obviously (as we saw) that allows bug to creep through, so I can also do it now.

One tricky thing is that since this project doesn't currently supply type class instances, we'd need "sample implementations" of those in order to test. What are people's thoughts about this?

non commented 9 years ago

I was thinking we could have a separate sub-project of "sample instances" that people could choose to use. That would allow us to use those for tests, and also to allow projects to share instances if they wanted. What do you all think?

tixxit commented 9 years ago

Yeah, something like algebra-std? You still need some toy instances though (see https://github.com/non/spire/blob/master/tests/src/test/scala/spire/laws/D3.scala)

johnynek commented 9 years ago

+1 to algebra-std (or even algebra-standard to be a bit more verbose).

non commented 9 years ago

I'm starting to set this up. The basic project structure so far is:

How does this sound? I went with std for brevity (mild preference) but if that is a pain I can extend it to standard.

Also are folks alright with ScalaTest, ScalaCheck, and Discipline being used for testing and law-checking?

johnynek commented 9 years ago

+1 to all of this. Perfect.