Skip to content

Commit

Permalink
reformat test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Apr 30, 2018
1 parent 8cbd2a5 commit 482da54
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- restore_cache:
keys:
- nvm-cache-{{ checksum ".circleci/config.yml" }}
- run: curl https://github.com/raw/creationix/nvm/v0.33.11/install.sh | bash
- run: curl https://github.com/raw/creationix/nvm/v0.33.6/install.sh | bash
- save_cache:
key: nvm-cache-{{ checksum ".circleci/config.yml" }}
paths:
Expand Down
7 changes: 5 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
{
"files": ["test/*.js"],
"rules": {
"func-call-spacing": ["off"],
"func-call-spacing": ["error", "always", {"allowNewlines": true}],
"func-style": ["error", "declaration", {"allowArrowFunctions": true}],
"indent": ["off"],
"no-unexpected-multiline": ["off"]
"no-extra-parens": ["off"],
"no-unexpected-multiline": ["off"],
"no-var": ["error"]
}
}
]
Expand Down
114 changes: 53 additions & 61 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';

var assert = require('assert');
const assert = require ('assert');

var laws = require('fantasy-laws');
var jsc = require('jsverify');
const show = require('sanctuary-show');
var Z = require('sanctuary-type-classes');
const laws = require ('fantasy-laws');
const jsc = require ('jsverify');
const show = require ('sanctuary-show');
const Z = require ('sanctuary-type-classes');

var Identity = require('..');
const Identity = require ('..');


// eq :: a -> b -> Undefined !
// eq :: a -> b -> Undefined !
function eq(actual) {
assert.strictEqual (arguments.length, eq.length);
return function eq$1(expected) {
Expand All @@ -20,91 +20,83 @@ function eq(actual) {
};
}

// IdentityArb :: Arbitrary a -> Arbitrary (Identity a)
function IdentityArb(arb) {
return arb.smap(Identity, value, show);
}
// IdentityArb :: Arbitrary a -> Arbitrary (Identity a)
const IdentityArb = arb => arb.smap (Identity, value, show);

// compose :: (b -> c, a -> b) -> a -> c
function compose(f, g) {
return function(x) {
return f(g(x));
};
}
// compose :: (b -> c) -> (a -> b) -> a -> c
const compose = f => g => x => f (g (x));

// value :: { value :: a } -> a
function value(r) {
return r.value;
}
// value :: { value :: a } -> a
const value = r => r.value;


test('equals', function() {
eq(Z.equals(Identity([1, 2, 3]), Identity([1, 2, 3])))(true);
eq(Z.equals(Identity([1, 2, 3]), Identity([3, 2, 1])))(false);
test ('equals', () => {
eq (Z.equals (Identity ([1, 2, 3]), Identity ([1, 2, 3]))) (true);
eq (Z.equals (Identity ([1, 2, 3]), Identity ([3, 2, 1]))) (false);
});

test('lte', function() {
eq(Z.lte(Identity(0), Identity(0)))(true);
eq(Z.lte(Identity(0), Identity(1)))(true);
eq(Z.lte(Identity(1), Identity(0)))(false);
test ('lte', () => {
eq (Z.lte (Identity (0), Identity (0))) (true);
eq (Z.lte (Identity (0), Identity (1))) (true);
eq (Z.lte (Identity (1), Identity (0))) (false);
});

test('concat', function() {
eq(Z.concat(Identity([1, 2]), Identity([3, 4])))(Identity([1, 2, 3, 4]));
test ('concat', () => {
eq (Z.concat (Identity ([1, 2]), Identity ([3, 4]))) (Identity ([1, 2, 3, 4]));
});

test('map', function() {
eq(Z.map(Math.sqrt, Identity(9)))(Identity(3));
test ('map', () => {
eq (Z.map (Math.sqrt, Identity (9))) (Identity (3));
});

test('ap', function() {
eq(Z.ap(Identity(Math.sqrt), Identity(9)))(Identity(3));
test ('ap', () => {
eq (Z.ap (Identity (Math.sqrt), Identity (9))) (Identity (3));
});

test('of', function() {
eq(Z.of(Identity, 42))(Identity(42));
test ('of', () => {
eq (Z.of (Identity, 42)) (Identity (42));
});

test('chain', function() {
eq(Z.chain(compose(Identity, Math.sqrt), Identity(9)))(Identity(3));
test ('chain', () => {
eq (Z.chain (compose (Identity) (Math.sqrt), Identity (9))) (Identity (3));
});

test('alt', function() {
eq(Z.alt(Identity([1, 2]), Identity([3, 4])))(Identity([1, 2, 3, 4]));
test ('alt', () => {
eq (Z.alt (Identity ([1, 2]), Identity ([3, 4]))) (Identity ([1, 2, 3, 4]));
});

test('reduce', function() {
eq(Z.reduce(Z.concat, [1, 2], Identity([3, 4])))([1, 2, 3, 4]);
test ('reduce', () => {
eq (Z.reduce (Z.concat, [1, 2], Identity ([3, 4]))) ([1, 2, 3, 4]);
});

test('traverse', function() {
eq(Z.traverse(Array, function(s) { return s.split(''); }, Identity('abc')))
([Identity('a'), Identity('b'), Identity('c')]);
test ('traverse', () => {
eq (Z.traverse (Array, s => s.split (''), Identity ('abc')))
([Identity ('a'), Identity ('b'), Identity ('c')]);
});

test('extend', function() {
eq(Z.extend(compose(Math.sqrt, value), Identity(9)))(Identity(3));
test ('extend', () => {
eq (Z.extend (compose (Math.sqrt) (value), Identity (9))) (Identity (3));
});

test('extract', function() {
eq(Z.extract(Identity(0)))(0);
test ('extract', () => {
eq (Z.extract (Identity (0))) (0);
});

test('@@show', function() {
eq(show(Identity([1, 2, 3])))('Identity ([1, 2, 3])');
test ('@@show', () => {
eq (show (Identity ([1, 2, 3]))) ('Identity ([1, 2, 3])');
});

suite('Comonad laws', function() {
suite ('Comonad laws', () => {

test('left identity',
laws.Comonad(Z.equals).leftIdentity(
IdentityArb(jsc.integer)
));
test ('left identity',
(laws.Comonad (Z.equals)).leftIdentity (
IdentityArb (jsc.integer)
));

test('right identity',
laws.Comonad(Z.equals).rightIdentity(
IdentityArb(jsc.integer),
jsc.constant(function(identity) { return identity.value + 1; })
));
test ('right identity',
(laws.Comonad (Z.equals)).rightIdentity (
IdentityArb (jsc.integer),
jsc.constant (identity => identity.value + 1)
));

});

0 comments on commit 482da54

Please sign in to comment.