All Projects → hychen → ke-e

hychen / ke-e

Licence: MIT License
假的 (ké--ê) is a property-based testing library, inspired by QuickCheck, Hypothesis, JSVerify and faker.js.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ke-e

Propcheck
Quickcheck/hypothesis style testing for elisp
Stars: ✭ 51 (+104%)
Mutual labels:  quickcheck
quickcheck
Randomized testing for Prolog à la QuickCheck
Stars: ✭ 18 (-28%)
Mutual labels:  quickcheck
hypothesis sqlalchemy
hypothesis strategies for generating SQLAlchemy objects
Stars: ✭ 24 (-4%)
Mutual labels:  quickcheck
Fast Check
Property based testing framework for JavaScript (like QuickCheck) written in TypeScript
Stars: ✭ 2,604 (+10316%)
Mutual labels:  quickcheck
Fsharp Hedgehog
Release with confidence, state-of-the-art property testing for .NET.
Stars: ✭ 219 (+776%)
Mutual labels:  quickcheck
fuzz-rest-api
Derive property based testing fast-check into a fuzzer for REST APIs
Stars: ✭ 38 (+52%)
Mutual labels:  quickcheck
Quick check.js
A JS implementation of quick_check
Stars: ✭ 48 (+92%)
Mutual labels:  quickcheck
haskell-schema
A library for describing Haskell data types and obtain free generators, JSON codecs, pretty printers, etc.
Stars: ✭ 16 (-36%)
Mutual labels:  quickcheck
Rantly
Ruby Imperative Random Data Generator and Quickcheck
Stars: ✭ 241 (+864%)
Mutual labels:  quickcheck
kitimat
A library for generative, property-based testing in TypeScript and Jest.
Stars: ✭ 68 (+172%)
Mutual labels:  quickcheck
Quickcheck State Machine
Test monadic programs using state machine based models
Stars: ✭ 192 (+668%)
Mutual labels:  quickcheck
Rapid
Rapid is a Go library for property-based testing that supports state machine ("stateful" or "model-based") testing and fully automatic test case minimization ("shrinking")
Stars: ✭ 213 (+752%)
Mutual labels:  quickcheck
ava-fast-check
Property based testing for AVA based on fast-check
Stars: ✭ 44 (+76%)
Mutual labels:  quickcheck
Swiftcheck
QuickCheck for Swift
Stars: ✭ 1,319 (+5176%)
Mutual labels:  quickcheck
pbt-frameworks
An overview of property-based testing functionality
Stars: ✭ 29 (+16%)
Mutual labels:  quickcheck
Qcstm
A simple state-machine framework for OCaml based on QCheck
Stars: ✭ 50 (+100%)
Mutual labels:  quickcheck
quick.py
Property-based testing library for Python
Stars: ✭ 15 (-40%)
Mutual labels:  quickcheck
lplzoo
Fine-grain implementations of common lambda calculi in Haskell, tested with QuickCheck
Stars: ✭ 32 (+28%)
Mutual labels:  quickcheck
edd
Erlang Declarative Debugger
Stars: ✭ 20 (-20%)
Mutual labels:  quickcheck
efftester
Effect-Driven Compiler Tester for OCaml
Stars: ✭ 37 (+48%)
Mutual labels:  quickcheck

Build Status License

ké--ê

ké--ê is a property-based testing library, inspired by QuickCheck, Hypothesis, JSVerify and faker.js.

It is also available to generate fake data for many purpose like faker.js.

What is ké--ê?

假的 (ké--ê) is a Taiwanese word. the meaning is fake things in English.

Features

  • Property-based test utilities library.
  • Repeatable random fake data generators.
  • Mocha test framwork integration.
  • Support for multiple localities.
  • Support for browser and Node.js.

check documents for more details.

Property-Based Testing

Property-based tests make statements about the output of your code based on the input, and these statements are verified for many different possible inputs.

By default, ke.hold runs 50 tests. it reports a counter example does not satisfy the property if any test fail.

for example, the following test.

describe('Int', () => {
  ke.hold(
    '> 0',       // property name.
    x => x > 0   // predicate.
  )
  .over(0)       // first especially case.
  .over(2)       // second especially case.
  .over(ke.int)  // universal case.
})

will report:

1) Int > 0:

      AssertionError: > 0 doesn't hold, counter example: -5, tried: 1/100
      + expected - actual

      -false
      +true

Exception-Based Testing

You can still use chai to do the testing with random test values generated by ke-e.

describe('Nat', () => {
  it('>= 0',  () => {
    ke.forall(ke.nat).eval((n) => {
      expect(n >= 0).eq(true);
    });
  }
})

Repeatable

test results are repeatable.

$ mocha
1) Int >0:
AssertionError: >0 doesn't hold, seed: -1764850555, counter example: -5265798245849472, tried: 3/3`

Seed=-1764850555 mocha
1) Int >0:
AssertionError: >0 doesn't hold, seed: -1764850555, counter example: -5265798245849472, tried: 3/3`

Localization

This project follows unicode CLDR specification. en is default locale id.

// Generate English first name.
ke.person.firstName.random.

// Generate Transitional Chinese first name.
ke.person.firstName.locale('zh-Hant-TW').random.

Node.js REPL

$ ke
> ke.int.random
123124343

Arbitraries

The purpose of a arbitraries is random generation and shrinking of values in property-based testing, but you could use them to generate fake data individually.

some of definitions of arbitraries took from faker.js project.

Primitive

  • any - produce any primitive types.
  • boolean — produce true and false with equal probability.
  • falsy — produce falsy values: false, null, undefined, '', 0, and NaN.
  • nat — produce a natural number.
  • int — produce a integer.
  • pint — produce a positive integer.
  • nint — produce a negative integer.
  • num — produce a float numbers.
  • pnum — produce a positive float numbers.
  • nnum — produce negative float numbers.
  • char — produce a unicode character.
  • asciichar — produce an ascii character.
  • string — produce a unicode string.
  • nestring - produce a non-empty unicode string.
  • asciistring — produce an ascii string.
  • neasciistring — produce an non-empty ascii string.

Combinator

  • constant — produce a constant value.
  • elements — produce one of the given values.
  • regex - produce a value from the regular expression.
  • frequency - Choose one of the given arbitraries, with a weighted random distribution.
  • oneOf — randomly uses one of the given generators.
  • maybe - produce a value or null.
  • array — produce an array.
  • nearray — produce a non-empty array.
  • sequence — produce an array of given arbitraries in order.
  • object — produce an object.
  • impl - produce a instance of class C.
  • call - produces a value of function with given arbitrary arguments.
  • func — produce a function.
  • genfunc - produce a generator.
  • promise - produce a promise.
  • recursive - produce a recursive value.

Locale

  • locale
  • localeids — produce a locale id.
  • country
  • timezone

Datetime

  • date — produce a Date.

Literate

  • literate
  • word
  • words
  • sentence
  • sentences
  • paragraph
  • paragraphs
  • lines
  • text

Person

  • person - produce an object to reprsent a person.
  • name - produce the name of a person.
  • firstName - produce the first name of a person.
  • lastName - produce the last name of a person.
  • gender - produce the gender of a person.

Internet

  • internet
  • avatar - produce an avatar uri.
  • userName - produce a internet username.
  • password - produce a password string.
  • email - produce an email.
  • url - produce an url.

Location

  • location
  • address
  • streetAddress
  • state
    • abbr
  • zipCode
  • county
  • city
  • street
  • buildingNumber
  • latitude - produce an latitude.
  • longitude - produce an longitude.
  • coordinates - produce a coordinates.

Grahpic

  • graphic
    • color
      • rgba
      • hsla
      • hsva
      • hex
      • hexCode
    • image
      • imageURL - an image url.
      • grayImageURL - a gray image url.

Installation

Node.js

install the module with: npm install ke-e

import ke from `ke-e`

describe('Integer', () => {
  ke.hold(
    'x + y = y + x'
    (x, y) => x + y === y + x
    ).over(ke.int, ke.int);
});

Browser using script tag

Download ke-e.js and place it in your project, then add it as the follwoing.

dones not work now.

<script src="http://hychen.me/ke-e/ke-e.js"</script>
<script>
describe('Integer', () => {
  ke.hold(
    'x + y = y + x'
    (x, y) => x + y === y + x
    ).over(ke.int, ke.int);
});
</script>

Get Involved

License

The MIT License (MIT)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].