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..fe4d20f --- /dev/null +++ b/test/dec.js @@ -0,0 +1,31 @@ +var constantly = require('../lib/constantly') + , expect = require('must') + , 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/funkis.js b/test/funkis.js index d61874e..d3021fc 100644 --- a/test/funkis.js +++ b/test/funkis.js @@ -2,14 +2,16 @@ 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() { - 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.have.property(name) + }) }) }) \ No newline at end of file diff --git a/test/inc.js b/test/inc.js new file mode 100644 index 0000000..5b1c2bc --- /dev/null +++ b/test/inc.js @@ -0,0 +1,31 @@ +var constantly = require('../lib/constantly') + , expect = require('must') + , 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