Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: rename misnamed files #258

Merged
merged 1 commit into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions test/lift.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,39 @@ var errorEq = require('./utils').errorEq;
var S = require('..');


describe('lift2', function() {
describe('lift', function() {

it('is a ternary function', function() {
eq(typeof S.lift2, 'function');
eq(S.lift2.length, 3);
it('is a binary function', function() {
eq(typeof S.lift, 'function');
eq(S.lift.length, 2);
});

it('type checks its arguments', function() {
throws(function() { S.lift2('wrong'); },
throws(function() { S.lift('wrong'); },
errorEq(TypeError,
'Invalid value\n' +
'\n' +
'lift2 :: (Apply a, Apply b, Apply c) => Function -> a -> b -> c\n' +
' ^^^^^^^^\n' +
' 1\n' +
'lift :: (Functor a, Functor b) => Function -> a -> b\n' +
' ^^^^^^^^\n' +
' 1\n' +
'\n' +
'1) "wrong" :: String\n' +
'\n' +
'The value at position 1 is not a member of ‘Function’.\n'));
});

it('lifts a function into the context of Applys', function() {
// positive :: Number -> Boolean
var positive = function(n) { return n > 0; };
it('lifts a function into the context of Functors', function() {
eq(S.lift(S.mult(2), S.Just(3)), S.Just(6));
eq(S.lift(S.mult(2), S.Nothing), S.Nothing);

eq(S.lift2(S.add, S.Just(3), S.Just(3)), S.Just(6));
eq(S.lift2(S.add, S.Nothing, S.Just(3)), S.Nothing);
eq(S.lift(S.mult(2), S.Left(3)), S.Left(3));
eq(S.lift(S.mult(2), S.Right(3)), S.Right(6));

eq(S.lift2(S.add, S.Right(3), S.Left(4)), S.Left(4));
eq(S.lift2(S.add, S.Right(3), S.Right(4)), S.Right(7));
eq(S.lift(S.mult(2), [1, 2, 3]), [2, 4, 6]);
eq(S.lift(S.mult(2), []), []);

eq(S.lift2(S.add, [1, 2], [10, 20]), [11, 21, 12, 22]);
eq(S.lift2(S.add, [], [1, 2]), []);

eq(S.lift2(S.and, S.even, positive)(42), true);
eq(S.lift2(S.and, S.even, positive)(43), false);
eq(S.lift2(S.and, S.even, positive)(-42), false);
eq(S.lift2(S.and, S.even, positive)(-43), false);
eq(S.lift(S.not, S.even)(42), false);
eq(S.lift(S.not, S.even)(43), true);
});

});
39 changes: 22 additions & 17 deletions test/lift2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,44 @@ var errorEq = require('./utils').errorEq;
var S = require('..');


describe('lift', function() {
describe('lift2', function() {

it('is a binary function', function() {
eq(typeof S.lift, 'function');
eq(S.lift.length, 2);
it('is a ternary function', function() {
eq(typeof S.lift2, 'function');
eq(S.lift2.length, 3);
});

it('type checks its arguments', function() {
throws(function() { S.lift('wrong'); },
throws(function() { S.lift2('wrong'); },
errorEq(TypeError,
'Invalid value\n' +
'\n' +
'lift :: (Functor a, Functor b) => Function -> a -> b\n' +
' ^^^^^^^^\n' +
' 1\n' +
'lift2 :: (Apply a, Apply b, Apply c) => Function -> a -> b -> c\n' +
' ^^^^^^^^\n' +
' 1\n' +
'\n' +
'1) "wrong" :: String\n' +
'\n' +
'The value at position 1 is not a member of ‘Function’.\n'));
});

it('lifts a function into the context of Functors', function() {
eq(S.lift(S.mult(2), S.Just(3)), S.Just(6));
eq(S.lift(S.mult(2), S.Nothing), S.Nothing);
it('lifts a function into the context of Applys', function() {
// positive :: Number -> Boolean
var positive = function(n) { return n > 0; };

eq(S.lift(S.mult(2), S.Left(3)), S.Left(3));
eq(S.lift(S.mult(2), S.Right(3)), S.Right(6));
eq(S.lift2(S.add, S.Just(3), S.Just(3)), S.Just(6));
eq(S.lift2(S.add, S.Nothing, S.Just(3)), S.Nothing);

eq(S.lift(S.mult(2), [1, 2, 3]), [2, 4, 6]);
eq(S.lift(S.mult(2), []), []);
eq(S.lift2(S.add, S.Right(3), S.Left(4)), S.Left(4));
eq(S.lift2(S.add, S.Right(3), S.Right(4)), S.Right(7));

eq(S.lift(S.not, S.even)(42), false);
eq(S.lift(S.not, S.even)(43), true);
eq(S.lift2(S.add, [1, 2], [10, 20]), [11, 21, 12, 22]);
eq(S.lift2(S.add, [], [1, 2]), []);

eq(S.lift2(S.and, S.even, positive)(42), true);
eq(S.lift2(S.and, S.even, positive)(43), false);
eq(S.lift2(S.and, S.even, positive)(-42), false);
eq(S.lift2(S.and, S.even, positive)(-43), false);
});

});
File renamed without changes.