From c16c192c1a00ed89abb1bbd53c7b22c882ba806a Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Sun, 7 Sep 2014 01:02:19 +0100 Subject: [PATCH 1/5] Improved `funkis` test output to be more specific with missing keys --- test/funkis.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/funkis.js b/test/funkis.js index d61874e..f77daf1 100644 --- a/test/funkis.js +++ b/test/funkis.js @@ -6,10 +6,12 @@ var fs = require('fs') describe('funkis', function() { it('should export every function in lib/', function() { - var names = fs.readdirSync(path.join(__dirname, '../lib')) - .map(function(file) { - var module = path.basename(file, '.js') - expect(funkis).to.have.key(module) - }) + var names = fs.readdirSync(path.join(__dirname, '../lib')).map(function(file) { + return path.basename(file, '.js') + }) + + each(names, function(name) { + expect(funkis).to.contain.key(name) + }) }) }) \ No newline at end of file From b3a8bc48ba7ee5c8fd4494ec2d4a7f6d95fe3299 Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Sun, 7 Sep 2014 02:08:01 +0100 Subject: [PATCH 2/5] Added `inc` and `dec`, first iteration --- index.js | 2 ++ lib/dec.js | 13 +++++++++++++ lib/inc.js | 13 +++++++++++++ test/dec.js | 31 +++++++++++++++++++++++++++++++ test/inc.js | 31 +++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 lib/dec.js create mode 100644 lib/inc.js create mode 100644 test/dec.js create mode 100644 test/inc.js diff --git a/index.js b/index.js index 15e3c2e..9a8929c 100644 --- a/index.js +++ b/index.js @@ -5,11 +5,13 @@ module.exports = , compose : require('./lib/compose') , constantly : require('./lib/constantly') , count : require('./lib/count') + , dec : require('./lib/dec') , each : require('./lib/each') , eq : require('./lib/eq') , gt : require('./lib/gt') , get : require('./lib/get') , identity : require('./lib/identity') + , inc : require('./lib/inc') , is : require('./lib/is') , isEmpty : require('./lib/isEmpty') , isnt : require('./lib/isnt') diff --git a/lib/dec.js b/lib/dec.js new file mode 100644 index 0000000..d32e783 --- /dev/null +++ b/lib/dec.js @@ -0,0 +1,13 @@ +module.exports = dec + +function dec(x) { + var n = val(x) + + assert(is(Number, n), "Expected number, got: " + x) + + return n - 1 +} + +var assert = require('./assert') + , val = require('./val') + , is = require('./is') \ No newline at end of file diff --git a/lib/inc.js b/lib/inc.js new file mode 100644 index 0000000..8c54410 --- /dev/null +++ b/lib/inc.js @@ -0,0 +1,13 @@ +module.exports = inc + +function inc(x) { + var n = val(x) + + assert(is(Number, n), "Expected number, got: " + x) + + return n + 1 +} + +var assert = require('./assert') + , val = require('./val') + , is = require('./is') \ No newline at end of file diff --git a/test/dec.js b/test/dec.js new file mode 100644 index 0000000..841b662 --- /dev/null +++ b/test/dec.js @@ -0,0 +1,31 @@ +var constantly = require('../lib/constantly') + , expect = require('chai').expect + , range = require('../lib/range') + , each = require('../lib/each') + , dec = require('../lib/dec') + , $ = require('../lib/partial') + +describe('dec', function() { + describe('when given a number `n`', function() { + it('should decrement that number by one and return the result', function() { + each(range(100), function(n) { + expect(dec(n)).to.equal(n - 1) + }) + }) + }) + + describe('when given a function', function() { + it('should call the function and try to decrement the return value', function() { + var three = constantly(3) + expect(dec(three)).to.equal(2) + }) + }) + + describe('when given a value that is not a number', function() { + it('should throw', function() { + each([ 'foo', true, false, null, undefined, NaN ], function(x) { + expect($(dec, x)).to.throw() + }) + }) + }) +}) \ No newline at end of file diff --git a/test/inc.js b/test/inc.js new file mode 100644 index 0000000..a9077eb --- /dev/null +++ b/test/inc.js @@ -0,0 +1,31 @@ +var constantly = require('../lib/constantly') + , expect = require('chai').expect + , range = require('../lib/range') + , each = require('../lib/each') + , inc = require('../lib/inc') + , $ = require('../lib/partial') + +describe('inc', function() { + describe('when given a number `n`', function() { + it('should increment that number by one and return the result', function() { + each(range(100), function(n) { + expect(inc(n)).to.equal(n + 1) + }) + }) + }) + + describe('when given a function', function() { + it('should call the function and try to increment the return value', function() { + var three = constantly(3) + expect(inc(three)).to.equal(4) + }) + }) + + describe('when given a value that is not a number', function() { + it('should throw', function() { + each([ 'foo', true, false, null, undefined, NaN ], function(x) { + expect($(inc, x)).to.throw() + }) + }) + }) +}) \ No newline at end of file From 1e6d2a36792ebcd2ad450efdc768420c51260bcb Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Sun, 7 Sep 2014 13:28:55 +0100 Subject: [PATCH 3/5] Convert tabs to spaces. Damn windows. From 746340620deb18a7806e27019274b5f25ac693ba Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Sat, 31 Jan 2015 13:20:00 +0000 Subject: [PATCH 4/5] Get inc/dev branch up to date with the new test setup --- test/dec.js | 2 +- test/funkis.js | 4 ++-- test/inc.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/dec.js b/test/dec.js index 841b662..b6d976a 100644 --- a/test/dec.js +++ b/test/dec.js @@ -1,5 +1,5 @@ var constantly = require('../lib/constantly') - , expect = require('chai').expect + , expect = require('must') , range = require('../lib/range') , each = require('../lib/each') , dec = require('../lib/dec') diff --git a/test/funkis.js b/test/funkis.js index f77daf1..d3021fc 100644 --- a/test/funkis.js +++ b/test/funkis.js @@ -2,7 +2,7 @@ var fs = require('fs') , path = require('path') , each = require('../lib/each') , funkis = require('../') - , expect = require('expect.js') + , expect = require('must') describe('funkis', function() { it('should export every function in lib/', function() { @@ -11,7 +11,7 @@ describe('funkis', function() { }) each(names, function(name) { - expect(funkis).to.contain.key(name) + expect(funkis).to.have.property(name) }) }) }) \ No newline at end of file diff --git a/test/inc.js b/test/inc.js index a9077eb..eeca2d3 100644 --- a/test/inc.js +++ b/test/inc.js @@ -1,5 +1,5 @@ var constantly = require('../lib/constantly') - , expect = require('chai').expect + , expect = require('must') , range = require('../lib/range') , each = require('../lib/each') , inc = require('../lib/inc') From 2159e07ea5e4f9da7093a30d51b48f81a97b3296 Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Sat, 31 Jan 2015 13:21:39 +0000 Subject: [PATCH 5/5] Fix indentation. Note to self: never use Windows again. --- test/dec.js | 4 ++-- test/inc.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/dec.js b/test/dec.js index b6d976a..fe4d20f 100644 --- a/test/dec.js +++ b/test/dec.js @@ -9,7 +9,7 @@ describe('dec', function() { describe('when given a number `n`', function() { it('should decrement that number by one and return the result', function() { each(range(100), function(n) { - expect(dec(n)).to.equal(n - 1) + expect(dec(n)).to.equal(n - 1) }) }) }) @@ -24,7 +24,7 @@ describe('dec', function() { describe('when given a value that is not a number', function() { it('should throw', function() { each([ 'foo', true, false, null, undefined, NaN ], function(x) { - expect($(dec, x)).to.throw() + expect($(dec, x)).to.throw() }) }) }) diff --git a/test/inc.js b/test/inc.js index eeca2d3..5b1c2bc 100644 --- a/test/inc.js +++ b/test/inc.js @@ -9,7 +9,7 @@ describe('inc', function() { describe('when given a number `n`', function() { it('should increment that number by one and return the result', function() { each(range(100), function(n) { - expect(inc(n)).to.equal(n + 1) + expect(inc(n)).to.equal(n + 1) }) }) }) @@ -24,7 +24,7 @@ describe('inc', function() { describe('when given a value that is not a number', function() { it('should throw', function() { each([ 'foo', true, false, null, undefined, NaN ], function(x) { - expect($(inc, x)).to.throw() + expect($(inc, x)).to.throw() }) }) })