Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Add inc/dev functions #23

Merged
merged 5 commits into from
Jan 31, 2015
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
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 13 additions & 0 deletions lib/dec.js
Original file line number Diff line number Diff line change
@@ -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')
13 changes: 13 additions & 0 deletions lib/inc.js
Original file line number Diff line number Diff line change
@@ -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')
31 changes: 31 additions & 0 deletions test/dec.js
Original file line number Diff line number Diff line change
@@ -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()
})
})
})
})
14 changes: 8 additions & 6 deletions test/funkis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
31 changes: 31 additions & 0 deletions test/inc.js
Original file line number Diff line number Diff line change
@@ -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()
})
})
})
})