Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hychen/ke-e
假的 (ké--ê) is a property-based testing library, inspired by QuickCheck, Hypothesis, JSVerify and faker.js.
https://github.com/hychen/ke-e
quickcheck
Last synced: 3 months ago
JSON representation
假的 (ké--ê) is a property-based testing library, inspired by QuickCheck, Hypothesis, JSVerify and faker.js.
- Host: GitHub
- URL: https://github.com/hychen/ke-e
- Owner: hychen
- License: mit
- Created: 2016-03-20T03:37:23.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-30T06:30:24.000Z (over 7 years ago)
- Last Synced: 2024-03-06T07:42:14.124Z (11 months ago)
- Topics: quickcheck
- Language: TypeScript
- Homepage:
- Size: 2.1 MB
- Stars: 25
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/hychen/ke-e.svg?branch=master)](https://travis-ci.org/hychen/ke-e)
[![License](http://img.shields.io/:license-mit-blue.svg)](http://badges.mit-license.org/)# ké--ê
`ké--ê` is a property-based testing library, inspired by [QuickCheck](https://hackage.haskell.org/package/QuickCheck),
[Hypothesis](https://github.com/HypothesisWorks/hypothesis-python), [JSVerify](https://github.com/jsverify/jsverify) and
[faker.js](https://github.com/marak/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](http://hychen.me/ke-e/index.html) 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](https://github.com/marak/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
```javascript
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.
```html
<script>
describe('Integer', () => {
ke.hold(
'x + y = y + x'
(x, y) => x + y === y + x
).over(ke.int, ke.int);
});```
## Get Involved
- source code : [github.com/hychen/ke-e](https://github.com/hychen/ke-e).
## License
The MIT License (MIT)