jasmine-static-land
Advanced tools
Comparing version 0.1.1 to 0.2.0
95
index.js
@@ -19,3 +19,3 @@ module.exports = { | ||
// Matchers | ||
toBeSetoid: function(util, custom){ | ||
toBeSetoid: function(){ | ||
return { | ||
@@ -42,3 +42,3 @@ compare: function(S){ | ||
toBeSemigroup: function(util, custom){ | ||
toBeSemigroup: function(){ | ||
return { | ||
@@ -92,2 +92,12 @@ compare: function(S){ | ||
compare: function(B){ | ||
const a = 400 | ||
const f = x => x * 2 | ||
const g = x => x - 40 | ||
const h = x => x + 20 | ||
const i = x => x / 2 | ||
if(B.bimap(x => x, x => x, a) !== a) | ||
return { pass: false, message: 'No Identity' } | ||
if( B.bimap(x => f(g(x)), x => h(i(x)), a) !== B.bimap(f, h, B.bimap(g, i, a)) ) | ||
return { pass: false, message: 'No Composition' } | ||
return {pass: true} | ||
@@ -101,2 +111,11 @@ } | ||
compare: function(P){ | ||
const a = 400 | ||
const f = x => x * 2 | ||
const g = x => x - 40 | ||
const h = x => x + 20 | ||
const i = x => x / 2 | ||
if(P.promap(x => x, x => x, a) !== a) | ||
return { pass: false, message: 'No Identity' } | ||
if(P.promap(x => f(g(x)), x => h(i(x)), a) !== P.promap(g, h, P.promap(f, i, a))) | ||
return { pass: false, message: 'No Composition' } | ||
return {pass: true} | ||
@@ -110,2 +129,7 @@ } | ||
compare: function(A){ | ||
const a = 400 | ||
const u = x => x / 2 // think functor is correct? | ||
const v = x => x + 2 | ||
if(A.ap(A.ap(A.map(f => g => x => f(g(x)), a), u), v) !== A.ap(a, A.ap(u, v))) | ||
return {pass: false, message: 'No Composition'} | ||
return {pass: true} | ||
@@ -119,2 +143,13 @@ } | ||
compare: function(A){ | ||
const v = 22 | ||
const f = x => x + 22 | ||
const u = x => x * 2 | ||
const y = x => x - 10 | ||
const x = x => x + 50 // x is wrong? | ||
if( A.ap(A.of(x => x), v) !== v) | ||
return { pass: false, message: 'No Identity' } | ||
if( A.ap(A.of(f), A.of(v)) !== A.of(f(x)) ) | ||
return { pass: false, message: 'No Homomorphism' } | ||
if( A.ap(u, A.of(y)) !== A.ap(A.of(f => f(y)), u) ) | ||
return { pass: false, message: 'Interchange' } | ||
return {pass: true} | ||
@@ -127,3 +162,8 @@ } | ||
return { | ||
compare: function(C){ | ||
compare: function(M){ | ||
const u = 5 | ||
const f = x => x + 22 | ||
const g = x => x - 8 | ||
if( M.chain(g, M.chain(f, u)) !== M.chain(x => M.chain(g, f(x)), u) ) | ||
return { pass: false, message: '' } | ||
return {pass: true} | ||
@@ -137,2 +177,10 @@ } | ||
compare: function(C){ | ||
const i = 54 | ||
const p = x => x + 2 | ||
const d = x => x - 20 | ||
const n = x => x * 2 | ||
const left = C.chainRec((next, done, v) => p(v) ? C.map(done, d(v)) : C.map(next, n(v)), i) | ||
const right = (function step(v) { return p(v) ? d(v) : C.chain(step, n(v)) }(i)) | ||
if(left !== right) | ||
return {pass: false, message: 'No Equivalence'} | ||
return {pass: true} | ||
@@ -146,2 +194,9 @@ } | ||
compare: function(M){ | ||
const f = x => x + 2 | ||
const a = 11 | ||
const u = 22 | ||
if( M.chain(f, M.of(a)) !== f(a) ) | ||
return {pass: false, message: 'No Left identity'} | ||
if( M.chain(M.of, u) !== u ) | ||
return {pass: false, message: 'No Right identity'} | ||
return {pass: true} | ||
@@ -155,2 +210,5 @@ } | ||
compare: function(F){ | ||
const right = (f, x, u) => F.reduce((acc, y) => acc.concat([y]), [], u).reduce(f, x) | ||
if( F.reduce !== right ) | ||
return { pass: false, message: 'No ?' } | ||
return {pass: true} | ||
@@ -164,2 +222,8 @@ } | ||
compare: function(E){ | ||
// types wrong? | ||
const f = {name: 'cat'} | ||
const g = {} | ||
const w = {} | ||
if( E.extend(f, E.extend(g, w)) !== E.extend(_w => f(E.extend(g, _w)), w) ) | ||
return { pass: false, message: 'No Associativity' } | ||
return {pass: true} | ||
@@ -173,2 +237,10 @@ } | ||
compare: function(C){ | ||
const w = {id: 2, name: 'memes'} | ||
const f = x => x.id + 2 | ||
if( C.extend(C.extract, w) !== w ) | ||
return { pass: false, message: 'No ?' } | ||
if( C.extract(C.extend(f, w)) !== f(w) ) | ||
return { pass: false, message: 'No ?' } | ||
if( C.extend(f, w) !== C.map(f, C.extend(x => x, w)) ) | ||
return { pass: false, message: 'No ?' } | ||
return {pass: true} | ||
@@ -182,2 +254,19 @@ } | ||
compare: function(T){ | ||
const ComposeAB = { | ||
of(x) { return A.of(B.of(x)) }, | ||
ap(a1, a2) { return A.ap(A.map(b1 => b2 => B.ap(b1, b2), a1), a2) }, | ||
map(f, a) { return A.map(b => B.map(f, b), a) } | ||
} | ||
//Applicatives | ||
const u = {id: 1, name: 'ferret'} | ||
const F = x => x.id + 1 | ||
const A = x => x.id + 2 | ||
const B = x => x.id + 3 | ||
const f = ComposeAB.map // f => B.map(g, f(a)) ≡ f(A.map(g, a)) | ||
if( f(T.traverse(A, x => x, u)) !== T.traverse(B, f, u) ) | ||
return { pass: false, message: 'No Naturality' } | ||
if( T.traverse(F, F.of, u) !== F.of(u) ) | ||
return { pass: false, message: 'No Identity' } | ||
if( T.traverse(ComposeAB, x => x, u) !== A.map(v => T.traverse(B, x => x, v), T.traverse(A, x => x, u)) ) | ||
return { pass: false, message: 'No Composition' } | ||
return {pass: true} | ||
@@ -184,0 +273,0 @@ } |
{ | ||
"name": "jasmine-static-land", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "A package containing unit tests for static land specifications", | ||
@@ -15,3 +15,6 @@ "main": "index.js", | ||
"jasmine", | ||
"static-land" | ||
"static-land", | ||
"static land", | ||
"functional", | ||
"fp" | ||
], | ||
@@ -18,0 +21,0 @@ "author": "Mark Beukers", |
@@ -5,3 +5,3 @@ <img width="131" height="82" src="https://raw.githubusercontent.com/rpominov/static-land/master/logo/logo.png" /> | ||
# jasmine-static-land | ||
![stability-wip](https://img.shields.io/badge/stability-work_in_progress-lightgrey.svg) [![Build Status](https://travis-ci.org/Shard/jasmine-static-land.svg)](https://travis-ci.org/Shard/jasmine-static-land) | ||
![stability-experimental](https://img.shields.io/badge/stability-experimental-orange.svg) [![Build Status](https://travis-ci.org/Shard/jasmine-static-land.svg)](https://travis-ci.org/Shard/jasmine-static-land) | ||
@@ -8,0 +8,0 @@ A package for testing the compatability of your [Static land](https://github.com/rpominov/static-land) types against it's laws within [Jasmine](http://jasmine.github.io/) |
@@ -9,6 +9,21 @@ const JSL = require('../index.js') | ||
const cat = {equals: function(a,b){ return a === b }} | ||
// cat :: number | ||
const cat = { | ||
equals: function(a,b){ return a === b }, | ||
empty: function(){ return 0 }, | ||
concat: function(a,b){ return a + b }, | ||
map: function(f,a){ return f(a) } | ||
} | ||
// dog :: string | ||
const dog = { | ||
equals: function(a,b){ return a === b }, | ||
empty: function(){ return '' }, | ||
concat: function(a,b){ return a + b }, | ||
map: function(f,a){ return f(a) } | ||
} | ||
it('can enforce Setoid', function(){ | ||
expect(cat).toBeSetoid() | ||
expect(dog).toBeSetoid() | ||
}) | ||
@@ -18,2 +33,3 @@ | ||
expect(cat).toBeSemigroup() | ||
expect(dog).toBeSemigroup() | ||
}) | ||
@@ -23,2 +39,3 @@ | ||
expect(cat).toBeMonoid() | ||
expect(cat).toBeMonoid() | ||
}) | ||
@@ -28,2 +45,3 @@ | ||
expect(cat).toBeFunctor() | ||
expect(dog).toBeFunctor() | ||
}) | ||
@@ -30,0 +48,0 @@ |
14407
344