Integrate runtypes with property-based testing
npm install runtypes-generate-benprp

Runtypes-generate convert runtypes type to jsverify arbitrary.
- Background
- Install
- Usage
- API
- Contribute
- License
Property-based testing is very awesome approach for analyze and verification program. But this approach requires the writing of generators for all datatypes in our program. This process is very time-consuming, error-prone and not DRY.
Example:
``js
import { Number, Literal, Array, Tuple, Record } from 'runtypes'
const AsteroidType = Record({
type: Literal('asteroid'),
location: Tuple(Number, Number, Number),
mass: Number,
})
const AsteroidArbitrary = jsc.record({
type: jsc.constant('asteroid'),
location: jsc.tuple(jsc.number, jsc.number, jsc.number),
mass: jsc.number
})
`
But with runtypes-generate we can get AsteroidArbitrary from AsteroidType:
`js`
import { makeJsverifyArbitrary } from 'runtypes-generate'
const AsteroidType = Record({
type: Literal('asteroid'),
location: Tuple(Number, Number, Number),
mass: Number,
})
const AsteroidArbitrary = makeJsverifyArbitrary(AsteroidType)
``
npm install --save runtypes-generate
- Core runtypes
- Custom runtypes
- makeJsverifyArbitrary(type: Reflect): jsc.Arbitrary - convert runtypes to jsverify arbitraryaddTypeToRegistry(tag: string, (x:Reflect) => jsc.Arbitrary
- - add new generator for Constraint type with tag in args attributeaddTypeToIntersectRegistry(tags: string[], generator: (x: Reflect) => jsc.Arbitrary
- - add new generator for Intersect or custom Constraint types. TODO examplegenerateAndCheck(rt: Reflect, opts?: jsc.Options): () => void
- - run jsc.assert for property rt.check(generatedData) for all generatedData obtained from makeJsverifyArbitrary(rt). Uses for verification custom generators for custom Constraint` type. See example in tests.
PRs accepted.
If you had questions just make issue or ask them in my telegram
Small note: If editing the Readme, please conform to the standard-readme specification.
MIT © typeetfunc