This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from mstade/inc-dec
Add inc/dev functions
- Loading branch information
Showing
6 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) | ||
}) |