Skip to content

Commit

Permalink
100% coverage in lib
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeKittens committed Jun 4, 2014
1 parent 88c68d7 commit a84ca2d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ http://programmers.stackexchange.com/questions/68980/interesting-variations-of-f
https://sites.google.com/site/steveyegge2/five-essential-phone-screen-questions
http://en.wikipedia.org/wiki/Fizz_buzz#Variations

Also find common characters in a string
Find common characters in a string

large array of numbers that can repeat and are not sorted
find first pair of numbers that sums to given integer
7 changes: 6 additions & 1 deletion bin/fizzbuzz
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ var fizzbuzz
p: prime
};

var handleError = function(errMsg) {
console.error(errMsg);
process.exit(1);
}

if (semver.gt(process.version.replace('v', ''), '0.11.0')) {
fizzbuzz = require('../lib/yield');
} else {
fizzbuzz = require('../lib/standard');
}

fizzbuzz(config, console.log);
fizzbuzz(config, console.log, handleError);
5 changes: 2 additions & 3 deletions lib/yield.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ var reset = function() {
buzzGen = buzz();
};

module.exports = function fizzbuzz(config, out) {
module.exports = function fizzbuzz(config, out, error) {
reset();
if (config.s - 1 % 3 !== 0) {
console.error('Yield method only works with numbers in the sequence 1, 4, 7...');
process.exit(1);
return error('Yield method only works with numbers in the sequence 1, 4, 7...');
}
for (var i = config.s; i <= config.e; i++) {
var outStr = '';
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interview",
"version": "0.0.11",
"version": "0.0.13",
"description": "A collection of command line tools for snarky answers to generic interview questions",
"main": "bin/fizzbuzz",
"bin": {
Expand All @@ -12,7 +12,8 @@
},
"preferGlobal": true,
"scripts": {
"test": "mocha --harmony"
"test": "mocha --harmony -R nyan",
"cover": "node --harmony node_modules/istanbul/lib/cli.js cover _mocha -- -R nyan"
},
"repository": {
"type": "git",
Expand All @@ -21,7 +22,8 @@
"keywords": [
"fizzbuzz",
"snark",
"interview"
"interview",
"Fibonacci"
],
"author": "Randall Koutnik <[email protected]>",
"license": "MIT",
Expand All @@ -30,10 +32,11 @@
},
"homepage": "https://github.com/SomeKittens/Interview",
"dependencies": {
"commander": "^2.2.0",
"commander": "2.2.0",
"semver": "~2.2.1"
},
"devDependencies": {
"should": "^3.3.1"
"should": "4.0.x",
"istanbul": "git://github.com/gotwarlost/istanbul.git#harmony"
}
}
8 changes: 7 additions & 1 deletion test/fizz.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,19 @@ describe('fizzbuzz', function() {
}
});
it('can also display primes', function() {
standardFizz({s: 1, e: 100, p: true}, addToResults);
yieldFizz({s: 1, e: 100, p: true}, addToResults);

results.length.should.eql(100);
for (var i = 0; i < 100; i++) {
results[i].should.eql(oneto100p[i]);
}
});
it('will give an error with an incorrect starting point', function() {
yieldFizz({s: 2, e: 100}, function() {}, addToResults);

results.length.should.eql(1);
results[0].should.eql('Yield method only works with numbers in the sequence 1, 4, 7...');
});
});

describe('prime', function() {
Expand Down
13 changes: 13 additions & 0 deletions test/sleepSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,17 @@ describe('sorts by sleeping!', function() {
done();
});
});

it('should stop processing after finding an error', function(done) {
sleepSort([671, 'bananas', 999], function(err, sortedArr) {
(err === null).should.be.false;
err.should.be.an.Error;
(sortedArr === undefined).should.be.true;

err.message.should.be.ok;
err.message.should.eql('Bad data at array index 1');

done();
});
});
});
2 changes: 0 additions & 2 deletions test/strrev.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

console.log(__dirname);

require('should');

var exec = require('child_process').exec;
Expand Down

0 comments on commit a84ca2d

Please sign in to comment.