Comparing version 0.5.2 to 0.5.3
## Release History | ||
- **0.5.3** — *2015-04-21* — More algebra | ||
- `unit` and `either` arbitraries | ||
- `arbitrary.smap` to help creating compound data | ||
- **0.5.2** — *2015-04-10* — `show.def` -change | ||
@@ -4,0 +7,0 @@ - **0.5.1** — *2015-02-19* — Dependencies bump |
/* @flow weak */ | ||
"use strict"; | ||
var arbitraryBless = require("./arbitraryBless.js"); | ||
var assert = require("assert"); | ||
@@ -23,7 +24,7 @@ var generator = require("./generator.js"); | ||
return { | ||
return arbitraryBless({ | ||
generator: arb.generator, | ||
shrink: shrink.noop, | ||
show: arb.show, | ||
}; | ||
}); | ||
} | ||
@@ -35,7 +36,7 @@ | ||
return { | ||
return arbitraryBless({ | ||
generator: generator[flavour](arb.generator), | ||
shrink: shrink[flavour](arb.shrink), | ||
show: show.array(arb.show), | ||
}; | ||
}); | ||
}; | ||
@@ -55,2 +56,25 @@ } | ||
/** | ||
- `unit: arbitrary ()` | ||
*/ | ||
var unit = arbitraryBless({ | ||
generator: generator.unit, | ||
shrink: shrink.noop, | ||
show: show.def, | ||
}); | ||
/** | ||
- `either(arbA: arbitrary a, arbB : arbitrary b): arbitrary (either a b)` | ||
*/ | ||
function either(a, b) { | ||
a = utils.force(a || primitive.json); | ||
b = utils.force(b || primitive.json); | ||
return arbitraryBless({ | ||
generator: generator.either(a.generator, b.generator), | ||
shrink: shrink.either(a.shrink, b.shrink), | ||
show: show.either(a.show, b.show), | ||
}); | ||
} | ||
/** | ||
- `pair(arbA: arbitrary a, arbB : arbitrary b): arbitrary (pair a b)` | ||
@@ -64,7 +88,7 @@ | ||
return { | ||
return arbitraryBless({ | ||
generator: generator.pair(a.generator, b.generator), | ||
shrink: shrink.pair(a.shrink, b.shrink), | ||
show: show.pair(a.show, b.show), | ||
}; | ||
}); | ||
} | ||
@@ -77,7 +101,7 @@ | ||
arbs = arbs.map(utils.force); | ||
return { | ||
return arbitraryBless({ | ||
generator: generator.tuple(utils.pluck(arbs, "generator")), | ||
shrink: shrink.tuple(utils.pluck(arbs, "shrink")), | ||
show: show.tuple(utils.pluck(arbs, "show")), | ||
}; | ||
}); | ||
} | ||
@@ -106,2 +130,10 @@ | ||
function makeMapShow(elShow) { | ||
return function (m) { | ||
return "{" + Object.keys(m).map(function (k) { | ||
return k + ": " + elShow(m[k]); | ||
}).join(", ") + "}"; | ||
}; | ||
} | ||
function map(arb) { | ||
@@ -112,11 +144,3 @@ arb = utils.force(arb || primitive.json); | ||
return { | ||
generator: arrayArbitrary.generator.map(fromArray), | ||
shrink: arrayArbitrary.shrink.isomap(fromArray, toArray), | ||
show: function (m) { | ||
return "{" + Object.keys(m).map(function (k) { | ||
return k + ": " + arb.show(m[k]); | ||
}).join(", ") + "}"; | ||
} | ||
}; | ||
return arrayArbitrary.smap(fromArray, toArray, makeMapShow(arb.show)); | ||
} | ||
@@ -146,3 +170,3 @@ | ||
return { | ||
return arbitraryBless({ | ||
generator: generator.oneof(generators), | ||
@@ -152,3 +176,3 @@ // TODO: make shrink | ||
show: show.def, | ||
}; | ||
}); | ||
} | ||
@@ -168,3 +192,3 @@ | ||
return { | ||
return arbitraryBless({ | ||
generator: generator.bless(function (size) { | ||
@@ -190,3 +214,3 @@ var res = {}; | ||
} | ||
}; | ||
}); | ||
} | ||
@@ -197,2 +221,4 @@ | ||
pair: pair, | ||
either: either, | ||
unit: unit, | ||
tuple: tuple, | ||
@@ -199,0 +225,0 @@ array: array, |
@@ -11,2 +11,4 @@ /* @flow weak */ | ||
pair: arbitrary.pair, | ||
unit: arbitrary.unit, | ||
either: arbitrary.either, | ||
array: arbitrary.array, | ||
@@ -13,0 +15,0 @@ nearray: arbitrary.nearray, |
@@ -5,2 +5,3 @@ /* @flow weak */ | ||
var random = require("./random.js"); | ||
var either = require("./either.js"); | ||
var utils = require("./utils.js"); | ||
@@ -144,2 +145,25 @@ | ||
/** | ||
- `generator.either(genA: generator a, genB: generator b): generator (either a b)` | ||
*/ | ||
function generateEither(genA, genB) { | ||
var result = generatorBless(function (size) { | ||
var n = random(0, 1); | ||
switch (n) { | ||
case 0: return either.left(genA(size)); | ||
case 1: return either.right(genB(size)); | ||
} | ||
}); | ||
return utils.curried3(result, arguments); | ||
} | ||
/** | ||
- `generator.unit: generator () | ||
`unit` is an empty tuple, i.e. empty array in JavaScript representation. This is useful as a building block. | ||
*/ | ||
function generateUnit() { | ||
return []; | ||
} | ||
/** | ||
- `generator.tuple(gens: (generator a, generator b...): generator (a, b...)` | ||
@@ -260,2 +284,4 @@ */ | ||
pair: generatePair, | ||
either: generateEither, | ||
unit: generateUnit, | ||
tuple: generateTuple, | ||
@@ -262,0 +288,0 @@ array: generateArray, |
@@ -97,2 +97,3 @@ /* @flow weak */ | ||
var arbitrary = require("./arbitrary.js"); | ||
var either = require("./either.js"); | ||
var environment = require("./environment.js"); | ||
@@ -395,2 +396,3 @@ var FMap = require("./finitemap.js"); | ||
/// include ./typify.js | ||
/// include ./arbitraryBless.js | ||
/// include ./primitive.js | ||
@@ -403,2 +405,3 @@ /// include ./arbitrary.js | ||
/// include ./random.js | ||
/// include ./either.js | ||
/// include ./utils.js | ||
@@ -420,2 +423,6 @@ | ||
// either | ||
left: either.left, | ||
right: either.right, | ||
// compile | ||
@@ -422,0 +429,0 @@ compile: function (str, env) { |
@@ -31,2 +31,21 @@ /* @flow weak */ | ||
/** | ||
- `show.either(showA: a -> string, showB: b -> string, e: either a b): string` | ||
*/ | ||
function showEither(showA, showB) { | ||
function showLeft(value) { | ||
return "Left(" + showA(value) + ")"; | ||
} | ||
function showRight(value) { | ||
return "Right(" + showB(value) + ")"; | ||
} | ||
var result = function (e) { | ||
return e.either(showLeft, showRight); | ||
}; | ||
return utils.curried3(result, arguments); | ||
} | ||
/** | ||
- `show.tuple(shrinks: (a -> string, b -> string...), x: (a, b...)): string` | ||
@@ -60,4 +79,5 @@ */ | ||
pair: showPair, | ||
either: showEither, | ||
tuple: showTuple, | ||
array: showArray, | ||
}; |
@@ -5,2 +5,3 @@ /* @flow weak */ | ||
var assert = require("assert"); | ||
var either = require("./either.js"); | ||
var utils = require("./utils.js"); | ||
@@ -86,2 +87,21 @@ | ||
/** | ||
- `shrink.either(shrA: shrink a, shrB: shrink b): shrink (either a b)` | ||
*/ | ||
function shrinkEither(shrinkA, shrinkB) { | ||
function shrinkLeft(value) { | ||
return shrinkA(value).map(either.left); | ||
} | ||
function shrinkRight(value) { | ||
return shrinkB(value).map(either.right); | ||
} | ||
var result = shrinkBless(function (e) { | ||
return e.either(shrinkLeft, shrinkRight); | ||
}); | ||
return utils.curried3(result, arguments); | ||
} | ||
// a → Vec a 1 | ||
@@ -184,2 +204,3 @@ function toSingleton(x) { | ||
pair: shrinkPair, | ||
either: shrinkEither, | ||
tuple: shrinkTuple, | ||
@@ -186,0 +207,0 @@ array: shrinkArray, |
{ | ||
"name": "jsverify", | ||
"description": "Property-based testing for JavaScript.", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"homepage": "http://jsverify.github.io/", | ||
@@ -35,3 +35,3 @@ "author": { | ||
"david": "^6.0.1", | ||
"eslint": "^0.16.1", | ||
"eslint": "^0.17.1", | ||
"esprima": "~2.1.0", | ||
@@ -38,0 +38,0 @@ "istanbul": "~0.3.0", |
@@ -167,2 +167,20 @@ # JSVerify | ||
### Arbitrary data | ||
- `arb.bless({...}): arbitrary a` | ||
Bless generator, shrink, show triple with with `.smap` property. | ||
- `.smap(f: a -> b, g: b -> a, newShow: (b -> string)?): arbitrary b` | ||
Transform `arbitrary a` into `arbitrary b`. For example: | ||
`g` should be a [right inverse](http://en.wikipedia.org/wiki/Surjective_function#Surjections_as_right_invertible_functions) of `f`. | ||
```js | ||
positiveIntegersArb = nat.smap( | ||
function (x) { return x + 1; }, | ||
function (x) { return x - 1; }); | ||
``` | ||
### Primitive arbitraries | ||
@@ -247,2 +265,6 @@ | ||
- `unit: arbitrary ()` | ||
- `either(arbA: arbitrary a, arbB : arbitrary b): arbitrary (either a b)` | ||
- `pair(arbA: arbitrary a, arbB : arbitrary b): arbitrary (pair a b)` | ||
@@ -313,2 +335,8 @@ | ||
- `generator.either(genA: generator a, genB: generator b): generator (either a b)` | ||
- `generator.unit: generator () | ||
`unit` is an empty tuple, i.e. empty array in JavaScript representation. This is useful as a building block. | ||
- `generator.tuple(gens: (generator a, generator b...): generator (a, b...)` | ||
@@ -363,2 +391,4 @@ | ||
- `shrink.either(shrA: shrink a, shrB: shrink b): shrink (either a b)` | ||
- `shrink.tuple(shrs: (shrink a, shrink b...)): shrink (a, b...)` | ||
@@ -380,2 +410,4 @@ | ||
- `show.either(showA: a -> string, showB: b -> string, e: either a b): string` | ||
- `show.tuple(shrinks: (a -> string, b -> string...), x: (a, b...)): string` | ||
@@ -399,2 +431,32 @@ | ||
### either | ||
- `either.left(value: a): either a b` | ||
- `either.right(value: b): either a b` | ||
- `either.either(l: a -> x, r: b -> x): x` | ||
- `either.isEqual(other: either a b): bool | ||
TODO: add `eq` optional parameter | ||
- `either.bimap(f: a -> c, g: b -> d): either c d` | ||
```js | ||
either.bimap(compose(f, g), compose(h, i)) ≡ either.bimap(g, i).bimap(f, h); | ||
``` | ||
- `either.first(f: a -> c): either c b` | ||
```js | ||
either.first(f) ≡ either.bimap(f, utils.identity) | ||
``` | ||
- `either.second(g: b -> d): either a d` | ||
```js | ||
either.second(g) === either.bimap(utils.identity, g) | ||
``` | ||
### Utility functions | ||
@@ -427,2 +489,5 @@ | ||
- **0.5.3** — *2015-04-21* — More algebra | ||
- `unit` and `either` arbitraries | ||
- `arbitrary.smap` to help creating compound data | ||
- **0.5.2** — *2015-04-10* — `show.def` -change | ||
@@ -429,0 +494,0 @@ - **0.5.1** — *2015-02-19* — Dependencies bump |
Sorry, the diff of this file is too big to display
185405
26
5217
639