Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dubzzz/fast-spec
Discover laws in your code like with QuickSpec
https://github.com/dubzzz/fast-spec
fast-check laws quickspec
Last synced: 2 months ago
JSON representation
Discover laws in your code like with QuickSpec
- Host: GitHub
- URL: https://github.com/dubzzz/fast-spec
- Owner: dubzzz
- License: mit
- Created: 2019-10-17T17:35:12.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-06T15:38:36.000Z (over 3 years ago)
- Last Synced: 2024-08-11T10:49:27.777Z (4 months ago)
- Topics: fast-check, laws, quickspec
- Language: TypeScript
- Homepage:
- Size: 86.9 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fast-spec
Discover laws in your code like with QuickSpec
## In a nutshell
Have you ever wondered what could be the laws that rule your code? The complex relations there might be between two distinct functions?
`fast-spec` is able to help you discover them.
## Example
Let's find the laws that link `concat`, `reverse` and `[]` together.
```js
import * as fc from "fast-check";
import { funcDef, instDef, varDef, findSpecs } from "fast-spec";
// const fc = require("fast-check");
// const { funcDef, instDef, varDef, findSpecs } = require("fast-spec");findSpecs([
// declare functions to be considered
funcDef("concat", 2, (a, b) => [...a, ...b]),
funcDef("reverse", 1, (a) => [...a].reverse()),
// declare basic root values (of special interest)
instDef("[]", []),
// declare complex values that can be consumed by your functions
varDef("x", fc.array(fc.char()))
], { // optional settings
// number of combinations to try - default: 100
numSamples: 100,
// complexity of the combinations - default: 2
complexity: 2,
// number of inputs to try to confirm a combination - default: 100
numFuzz: 100
})
````fast-spec` will be able to find relationships like:
- concat([], []) = []
- concat([], x0) == x0
- concat(x0, []) == x0
- concat(concat(x0, x1), x2) == concat(x0, concat(x1, x2))
- concat(reverse(x0), reverse(x1)) == reverse(concat(x1, x0))
- reverse([]) = []
- reverse(reverse(x0)) == x0
- ...*Live example available at https://runkit.com/dubzzz/hello-world-fast-spec-v2*