typelevel / typelevel/cats

regarding property-based testing: allow equality to only return Prop instead of Boolean

Open
#1,058 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
5.5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
5

Description

For some types, equality is not decidable, but it's still possible to find counterexamples to equality. One of the simpler examples is function application. Consider we introduce

trait PropEq[A] {
  def eqv(left: A, right: A): Prop[Boolean]
}

Then we can use this for functions:

implicit class functionEq[A, B](f: A => B)(implicit arbitrary: Arbitrary[A], eq: PropEq[A]) extends PropEq[A => B] {
  def env(left: A => B, right: A => B) = forall (x => eq.eqv(left(x), right(y)))
}

For Eq instances, the PropEq instance can be implicitly inferred. Then we can use them in places like ApplicativeTests: instead of requiring an implicit Eq[A] etc. we only require PropEq[A] (in the end the result of this equality is converted to a prop anyway by isEqToProp implicit).

This would make the typeclass laws more useful, because we could then also automatically test instances which are not deterministically comparable.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ApplicativeTests references and the isEqToProp conversion mentioned in the issue, then trace how existing Eq instances are required by property-based laws. The work is complete when PropEq can support nondeterministic equality, including function values, and the affected laws accept it without requiring deterministic Eq instances.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.