npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quick_check

v0.7.0

Published

QuickCheck for JavaScript

Downloads

231

Readme

quick_check.js

quick_check.js is an implementation of QuickCheck in JavaScript. (Actually the implementation is written in CoffeeScript, but that doesn't matter much).

It works by integrating with existing test libraries. For example Jasmine expectations are written like this:

// implementation
function odd(n) {
  return n % 2 === 1;
}
// tests
it('#odd returns true for odd numbers', function() {
  expect(function(i) {
    return odd(2 * i + 1);
  }).forAll(qc.int)
});

Notice the forAll(qc.int). This indicates that our function (called property) should return true for all integers passed to it. This code in fact contains a bug which quick_check.js will helpfully find for you:

PhantomJS 1.9.7 (Mac OS X) #odd returns true for odd numbers FAILED
  Falsified after 3 attempts. Counter-example: -4

This means that quick_check.js generated 3 random integers and one of them failed the test (in this case -4). (Why? Because modulus operator in JavaScript is botched).

QuickCheck will stop after 100 generated test cases and assume that your code works.

For more information read the docs, check out my talk or read the annotated source code or the introductory blog post.

Installing

Karma + Jasmine combo should be supported easily. Simply npm install quick_check --save-dev, then add 'node_modules/quick_check/dist/quick-check.js' to your files config.

See more integrations

Generators

quick_check.js comes with batteries included. There are plenty of generators included plus it is very easy to write your own. I recommend checking out the docs, but here is a quick rundown:

Basic generators

  • qc.bool
  • qc.byte
  • qc.constructor(cons)
  • qc.fromFunction(fn)

Number generators

Almost all number generators have a large variant for generating larger numbers, as the standard generators tend not to generate numbers bigger than 10,000. The generators prefixed with u generate only positive numbers.

  • qc.ureal and qc.ureal.large
  • qc.real and qc.real.large
  • qc.uint and qc.uint.large
  • qc.int and qc.int.large
  • qc.int.between(min, max)
  • qc.natural and qc.natural.large
  • qc.range([gen])
  • qc.range.inclusive([gen])
  • qc.dice(diceDSL)

String generators

  • qc.char
  • qc.string
  • qc.string.ascii
  • qc.string.concat
  • qc.string.matching

Array generators

  • qc.arrayOf(generator[, options])
  • qc.array
  • qc.array.subsetOf(array[, options])

Object generators

  • qc.object
  • qc.objectLike(template)
  • qc.objectOf(valGen[, keyGen])

Function generators

  • qc.function
  • qc.procedure

Misc generators

  • qc.date
  • qc.any
  • qc.any.simple
  • qc.any.datatype
  • qc.color
  • qc.location

Generator combinators

These combinator functions are meant to create new generators out of other generators.

  • qc.oneOf
  • qc.oneOfByPriority
  • qc.except

Maintained By

Jakub Hampl - http://gampleman.eu

License

The MIT License (MIT)

Copyright (c) 2014 RightScale

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.