or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

helper-types.mdindex.mdlist-wrapper.md

index.mddocs/

0

# Cats Testkit

1

2

Cats Testkit provides testing utilities and helpers for the Cats functional programming library. It includes concrete types with controlled type class instances and wrapper types that enable comprehensive property-based testing of functional programming abstractions.

3

4

## Package Information

5

6

- **Package Name**: cats-testkit

7

- **Package Type**: maven

8

- **Language**: Scala

9

- **Installation**: Add to your `build.sbt`: `"org.typelevel" %% "cats-testkit" % "2.13.0" % Test`

10

11

## Core Imports

12

13

```scala

14

import cats.tests._

15

import cats.tests.Helpers._

16

```

17

18

For ScalaCheck integration:

19

```scala

20

import org.scalacheck.{Arbitrary, Cogen}

21

```

22

23

## Basic Usage

24

25

```scala

26

import cats.tests._

27

import cats.tests.Helpers._

28

import cats.kernel.laws.discipline.MonoidTests

29

import cats.laws.discipline.AlternativeTests

30

import org.scalatest.funsuite.AnyFunSuite

31

import org.scalatestplus.scalacheck.Checkers

32

33

class MyMonoidTests extends AnyFunSuite with Checkers {

34

// Test that your Monoid[MyType] implementation is lawful

35

// using the Mono helper type which has a Monoid instance

36

test("Monoid laws for Mono") {

37

checkAll("Monoid[Mono]", MonoidTests[Mono].monoid)

38

}

39

40

// Test different type class instances with ListWrapper

41

test("Alternative laws for ListWrapper") {

42

implicit val alt = ListWrapper.alternative

43

checkAll("ListWrapper Alternative", AlternativeTests[ListWrapper].alternative[Int, Int, Int])

44

}

45

}

46

```

47

48

## Architecture

49

50

Cats Testkit provides two main testing utilities:

51

52

1. **Helper Types** - Concrete data types with precisely controlled type class instances for testing algebraic laws

53

2. **Wrapper Types** - Generic wrapper types that enable testing different combinations of type class constraints

54

55

These components work together to enable comprehensive property-based testing of functional programming abstractions, ensuring that type class implementations are lawful across various contexts and constraint combinations.

56

57

## Capabilities

58

59

### Helper Types for Type Class Testing

60

61

Provides concrete types with controlled type class instances for testing algebraic structures like Semigroup, Monoid, Group, Order, etc.

62

63

```scala { .api }

64

// Example helper types with specific type class instances

65

case class Mono(n: Int) extends N

66

case class Grp(n: Int) extends N

67

case class Ord(n: Int) extends N

68

```

69

70

[Helper Types](./helper-types.md)

71

72

### ListWrapper for Constraint Testing

73

74

Provides a wrapper type that enables testing type class instances with different constraint combinations.

75

76

```scala { .api }

77

final case class ListWrapper[A](list: List[A]) extends AnyVal

78

79

object ListWrapper {

80

val traverse: Traverse[ListWrapper]

81

val monad: Monad[ListWrapper]

82

val alternative: Alternative[ListWrapper]

83

// ... many more type class instances

84

}

85

```

86

87

[ListWrapper Testing Infrastructure](./list-wrapper.md)