Socket
Book a DemoInstallSign in
Socket

fast-spec

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-spec

Discover laws in your code like with QuickSpec

latest
Source
npmnpm
Version
0.0.6
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

fast-spec

Discover laws in your code like with QuickSpec

In a nutshell

Have you ever wonder 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 discovering them.

Example

Let's find the laws that link concat, reverse and [] together.

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

Keywords

quickspec

FAQs

Package last updated on 21 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts