Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/norfairking/validity
Validity and validity-based testing
https://github.com/norfairking/validity
explicit-invariants invalid-values invariants sanity-test validity
Last synced: 4 days ago
JSON representation
Validity and validity-based testing
- Host: GitHub
- URL: https://github.com/norfairking/validity
- Owner: NorfairKing
- License: mit
- Created: 2016-07-10T13:11:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-12T22:33:05.000Z (2 months ago)
- Last Synced: 2024-12-13T17:24:01.919Z (11 days ago)
- Topics: explicit-invariants, invalid-values, invariants, sanity-test, validity
- Language: Haskell
- Homepage: https://www.youtube.com/watch?v=eIs9qNh17SM
- Size: 1.43 MB
- Stars: 157
- Watchers: 9
- Forks: 31
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Validity and validity-based testing
## Why?
> to make writing correct software cheaper.
- Free generators
- Free shrinking
- Cheap properties### Cheap properties
- Property Combinators:
``` haskell
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:
``` haskell
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
``` haskell
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
`````` haskell
genValid :: Gen MyType -- Free generator
shrinkValid :: MyType -> [MyType] -- Free _valid_ shrinking function
```## Cachix cache
There is a [cachix](https://cachix.org) cache for this project.
To use it, use `cachix use validity` or add the appropriate details to your nixos configuration.