项目作者: NorfairKing

项目描述 :
Validity and validity-based testing
高级语言: Haskell
项目地址: git://github.com/NorfairKing/validity.git
创建时间: 2016-07-10T13:11:41Z
项目社区:https://github.com/NorfairKing/validity

开源协议:

下载


Validity and validity-based testing

Why?

to make writing correct software cheaper.

  • Free generators
  • Free shrinking
  • Cheap properties

Cheap properties

  • Property Combinators:
  1. specify "inverse functions" $ inverseFunctions (+1) (-1)
  2. specify "equivalent functions" $ equivalent ((+ 1) . (- 1)) id
  3. specify "transitivity" $ transitivity ((>) :: Int -> Int -> Bool)
  4. specify "symmetry" $ symmetry ((==) :: Int -> Int -> Bool)
  • Test suite combinators:
  1. ordSpec @Int
  1. Ord Int
  2. (<=) :: Int -> Int -> Bool
  3. is reflexive for "even Int"'s
  4. +++ OK, passed 100 tests.
  5. is antisymmetric for "even Int"'s
  6. +++ OK, passed 100 tests.
  7. is transitive for "even Int"'s
  8. +++ OK, passed 100 tests.
  9. is equivalent to (\a b -> compare a b /= GT) for "even Int"'s
  10. +++ OK, passed 100 tests.
  11. (>=) :: Int -> Int -> Bool
  12. is reflexive for "even Int"'s
  13. +++ OK, passed 100 tests.
  14. is antisymmetric for "even Int"'s
  15. +++ OK, passed 100 tests.
  16. is transitive for "even Int"'s
  17. +++ OK, passed 100 tests.
  18. is equivalent to (\a b -> compare a b /= LT) for "even Int"'s
  19. +++ OK, passed 100 tests.
  20. (<) :: Int -> Int -> Bool
  21. is antireflexive for "even Int"'s
  22. +++ OK, passed 100 tests.
  23. is transitive for "even Int"'s
  24. +++ OK, passed 100 tests.
  25. is equivalent to (\a b -> compare a b == LT) for "even Int"'s
  26. +++ OK, passed 100 tests.
  27. (>) :: Int -> Int -> Bool
  28. is antireflexive for "even Int"'s
  29. +++ OK, passed 100 tests.
  30. is transitive for "even Int"'s
  31. +++ OK, passed 100 tests.
  32. is equivalent to (\a b -> compare a b == GT) for "even Int"'s
  33. +++ OK, passed 100 tests.

Free generators and shrinking

  1. data MyType = MyType
  2. { myRational :: Rational
  3. , myBool :: Bool
  4. } deriving (Show, Eq, Generic)
  5. instance Validity MyType -- Implementation is derived via Generic
  6. instance GenValid MyType -- Default implementation via Generic
  1. genValid :: Gen MyType -- Free generator
  2. 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.