Validity and validity-based testing


Keywords
mit, validity, Propose Tags, the readme, validity-aeson, validity-bytestring, validity-containers, validity-path, validity-scientific, validity-text, validity-time, validity-unordered-containers, validity-uuid, validity-vector, , Index, Quick Jump, Data.Validity, validity-0.12.0.2.tar.gz, browse, Package description, Package maintainers, Norfair, NickskeVdb, edit package information , explicit-invariants, invalid-values, invariants, sanity-test
License
MIT
Install
cabal install validity-0.12.0.2

Documentation

Validity and validity-based testing

Why?

to make writing correct software cheaper.

  • Free generators
  • Free shrinking
  • Cheap properties

Cheap properties

  • Property Combinators:
specify "inverse functions" $ inverseFunctions (+1) (-1)
specify "equivalent functions" $ equivalent ((+ 1) . (- 1)) id
specify "transitivity" $ transitivity ((>) :: Int -> Int -> Bool)
specify "symmetry" $ symmetry ((==) :: Int -> Int -> Bool)
  • Test suite combinators:
ordSpec @Int
  Ord Int
    (<=) :: Int -> Int -> Bool
      is reflexive for "even Int"'s
        +++ OK, passed 100 tests.
      is antisymmetric for "even Int"'s
        +++ OK, passed 100 tests.
      is transitive for "even Int"'s
        +++ OK, passed 100 tests.
      is equivalent to (\a b -> compare a b /= GT) for "even Int"'s
        +++ OK, passed 100 tests.
    (>=) :: Int -> Int -> Bool
      is reflexive for "even Int"'s
        +++ OK, passed 100 tests.
      is antisymmetric for "even Int"'s
        +++ OK, passed 100 tests.
      is transitive for "even Int"'s
        +++ OK, passed 100 tests.
      is equivalent to (\a b -> compare a b /= LT) for "even Int"'s
        +++ OK, passed 100 tests.
    (<) :: Int -> Int -> Bool
      is antireflexive for "even Int"'s
        +++ OK, passed 100 tests.
      is transitive for "even Int"'s
        +++ OK, passed 100 tests.
      is equivalent to (\a b -> compare a b == LT) for "even Int"'s
        +++ OK, passed 100 tests.
    (>) :: Int -> Int -> Bool
      is antireflexive for "even Int"'s
        +++ OK, passed 100 tests.
      is transitive for "even Int"'s
        +++ OK, passed 100 tests.
      is equivalent to (\a b -> compare a b == GT) for "even Int"'s
        +++ OK, passed 100 tests.

Free generators and shrinking

data MyType = MyType
  { myRational :: Rational
  , myBool :: Bool
  } deriving (Show, Eq, Generic)

instance Validity MyType -- Implementation is derived via Generic
instance GenValid MyType -- Default implementation via Generic
genValid :: Gen MyType -- Free generator
shrinkValid :: MyType -> [MyType] -- Free _valid_ shrinking function

Cachix cache

There is a cachix cache for this project.

To use it, use cachix use validity or add the appropriate details to your nixos configuration.