<commit_before>package algebra
package laws

import algebra.lattice._
import algebra.number._
import algebra.ring._
import algebra.std.all._
import algebra.std.Rat

import CheckSupport._

import org.typelevel.discipline.scalatest.Discipline
import org.scalatest.FunSuite

class LawTests extends FunSuite with Discipline {

  implicit val byteLattice: Lattice[Byte] = ByteMinMaxLattice
  implicit val shortLattice: Lattice[Short] = ShortMinMaxLattice
  implicit val intLattice: Lattice[Int] = IntMinMaxLattice
  implicit val longLattice: Lattice[Long] = LongMinMaxLattice

  checkAll("Boolean", OrderLaws[Boolean].order)
  checkAll("Boolean", LogicLaws[Boolean].bool)
  checkAll("Boolean", LatticePartialOrderLaws[Boolean].boundedLatticePartialOrder)

  checkAll("String", OrderLaws[String].order)
  checkAll("String", GroupLaws[String].monoid)

  {
    // TODO: test a type that has Eq but not Order
    implicit val g: Group[Int] = Group.additive[Int]
    checkAll("Option[Int]", OrderLaws[Option[Int]].order)
    checkAll("Option[Int]", GroupLaws[Option[Int]].monoid)
    checkAll("Option[String]", OrderLaws[Option[String]].order)
    checkAll("Option[String]", GroupLaws[Option[String]].monoid)
  }

  checkAll("List[Int]", OrderLaws[List[Int]].order)
  checkAll("List[Int]", GroupLaws[List[Int]].monoid)
  checkAll("List[String]", OrderLaws[List[String]].order)
  checkAll("List[String]", GroupLaws[List[String]].monoid)

  checkAll("Set[Int]", LatticeLaws[Set[Int]].lattice)
  checkAll("Set[Int]", OrderLaws[Set[Int]].partialOrder)
  checkAll("Set[Int]", RingLaws[Set[Int]].semiring)
  checkAll("Set[String]", RingLaws[Set[String]].semiring)

  checkAll("Map[Char, Int]", OrderLaws[Map[Char, Int]].eqv)
  checkAll("Map[Char, Int]", RingLaws[Map[Char, Int]].rng)
  checkAll("Map[Int, BigInt]", OrderLaws[Map[Int, BigInt]].eqv)
  checkAll("Map[Int, BigInt]", RingLaws[Map[Int, BigInt]].rng)

  checkAll("Byte", OrderLaws[Byte].order)
  checkAll("Byte", RingLaws[Byte].euclideanRing)
  checkAll("Byte", LatticeLaws[Byte].lattice)

  checkAll("Short", OrderLaws[Short].order)
  checkAll("Short", RingLaws[Short].euclideanRing)
  checkAll("Short", LatticeLaws[Short].lattice)

  checkAll("Char", OrderLaws[Char].order)

  checkAll("Int", OrderLaws[Int].order)
  checkAll("Int", RingLaws[Int].euclideanRing)
  checkAll("Int", LatticeLaws[Int].lattice)

  checkAll("Long", OrderLaws[Long].order)
  checkAll("Long", RingLaws[Long].euclideanRing)
  checkAll("Long", LatticeLaws[Long].lattice)

  checkAll("BigInt", BaseLaws[BigInt].isReal)
  checkAll("BigInt", RingLaws[BigInt].euclideanRing)

  checkAll("Rat", BaseLaws[Rat].isReal)
  checkAll("Rat", RingLaws[Rat].field)

  {
    implicit val tupEq: Eq[(Int, Int)] = new Eq[(Int, Int)] {
      def eqv(a: (Int, Int), b: (Int, Int)) = a == b
    }
    implicit val band = new Band[(Int, Int)] {
      def combine(a: (Int, Int), b: (Int, Int)) = (a._1, b._2)
    }
    checkAll("(Int, Int) Band", GroupLaws[(Int, Int)].band)
  }
}
<commit_msg>Stay DRY between tested types and test names.<commit_after>package algebra
package laws

import scala.reflect.runtime.universe.TypeTag

import algebra.lattice._
import algebra.number._
import algebra.ring._
import algebra.std.all._
import algebra.std.Rat

import CheckSupport._

import org.typelevel.discipline.{Laws, Predicate}
import org.typelevel.discipline.scalatest.Discipline
import org.scalacheck.Arbitrary
import org.scalatest.FunSuite

class LawTests extends FunSuite with Discipline {

  implicit val byteLattice: Lattice[Byte] = ByteMinMaxLattice
  implicit val shortLattice: Lattice[Short] = ShortMinMaxLattice
  implicit val intLattice: Lattice[Int] = IntMinMaxLattice
  implicit val longLattice: Lattice[Long] = LongMinMaxLattice

  implicit def orderLaws[A: Eq: Arbitrary] = OrderLaws[A]
  implicit def groupLaws[A: Eq: Arbitrary] = GroupLaws[A]
  implicit def logicLaws[A: Eq: Arbitrary] = LogicLaws[A]
  implicit def latticeLaws[A: Eq: Arbitrary] = LatticeLaws[A]
  implicit def ringLaws[A: Eq: Arbitrary: Predicate] = RingLaws[A]
  implicit def baseLaws[A: Eq: Arbitrary] = BaseLaws[A]
  implicit def latticePartialOrderLaws[A: Eq: Arbitrary] = LatticePartialOrderLaws[A]

  case class LawChecker[L <: Laws](name: String, laws: L) {
    def check(f: L => L#RuleSet): Unit = checkAll(name, f(laws))
  }

  private def laws[L[_] <: Laws, A](implicit
      laws: L[A], tag: TypeTag[A]): LawChecker[L[A]] =
    LawChecker("[" + tag.tpe.toString + "]", laws)

  laws[OrderLaws, Boolean].check(_.order)
  laws[LogicLaws, Boolean].check(_.bool)
  laws[LatticePartialOrderLaws, Boolean].check(_.boundedLatticePartialOrder)

  laws[OrderLaws, String].check(_.order)
  laws[GroupLaws, String].check(_.monoid)

  {
    // TODO: test a type that has Eq but not Order
    implicit val g: Group[Int] = Group.additive[Int]
    laws[OrderLaws, Option[Int]].check(_.order)
    laws[GroupLaws, Option[Int]].check(_.monoid)
    laws[OrderLaws, Option[String]].check(_.order)
    laws[GroupLaws, Option[String]].check(_.monoid)
  }

  laws[OrderLaws, List[Int]].check(_.order)
  laws[GroupLaws, List[Int]].check(_.monoid)
  laws[OrderLaws, List[String]].check(_.order)
  laws[GroupLaws, List[String]].check(_.monoid)

  laws[LatticeLaws, Set[Int]].check(_.lattice)
  laws[OrderLaws, Set[Int]].check(_.partialOrder)
  laws[RingLaws, Set[Int]].check(_.semiring)
  laws[RingLaws, Set[String]].check(_.semiring)

  laws[OrderLaws, Map[Char, Int]].check(_.eqv)
  laws[RingLaws, Map[Char, Int]].check(_.rng)
  laws[OrderLaws, Map[Int, BigInt]].check(_.eqv)
  laws[RingLaws, Map[Int, BigInt]].check(_.rng)

  laws[OrderLaws, Byte].check(_.order)
  laws[RingLaws, Byte].check(_.euclideanRing)
  laws[LatticeLaws, Byte].check(_.lattice)

  laws[OrderLaws, Short].check(_.order)
  laws[RingLaws, Short].check(_.euclideanRing)
  laws[LatticeLaws, Short].check(_.lattice)

  laws[OrderLaws, Char].check(_.order)

  laws[OrderLaws, Int].check(_.order)
  laws[RingLaws, Int].check(_.euclideanRing)
  laws[LatticeLaws, Int].check(_.lattice)

  laws[OrderLaws, Long].check(_.order)
  laws[RingLaws, Long].check(_.euclideanRing)
  laws[LatticeLaws, Long].check(_.lattice)

  laws[BaseLaws, BigInt].check(_.isReal)
  laws[RingLaws, BigInt].check(_.euclideanRing)

  laws[BaseLaws, Rat].check(_.isReal)
  laws[RingLaws, Rat].check(_.field)

  {
    implicit val tupEq: Eq[(Int, Int)] = new Eq[(Int, Int)] {
      def eqv(a: (Int, Int), b: (Int, Int)) = a == b
    }
    implicit val band = new Band[(Int, Int)] {
      def combine(a: (Int, Int), b: (Int, Int)) = (a._1, b._2)
    }
    checkAll("(Int, Int) Band", GroupLaws[(Int, Int)].band)
  }
}

{'fraction_non_alphanumeric': 0.15717092337917485, 'fraction_numerical': 0.0006045035514583648, 'mean_word_length': 5.4003868471953576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '970626', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2400, 'n_words': 444}