Skip to content

Commit

Permalink
yield tests and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeKittens committed May 9, 2014
1 parent 9a9aec1 commit 7283a89
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
11 changes: 9 additions & 2 deletions lib/yield.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

/* jshint esnext: true */

// In separate file to avoid syntax errors in older versions of node
// Currently only works when starting at one.

Expand All @@ -21,10 +23,15 @@ var buzz = function *() {
}
};

var fizzGen = fizz()
, buzzGen = buzz();
var fizzGen, buzzGen;

var reset = function() {
fizzGen = fizz();
buzzGen = buzz();
};

module.exports = function fizzbuzz(e, s, out) {
reset();
if (e - 1 % 3 !== 0) {
console.error('Yield method only works with numbers in the sequence 1, 4, 7...');
process.exit(1);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interview",
"version": "0.0.4",
"version": "0.0.5",
"description": "A collection of command line tools for snarky answers to generic interview questions",
"main": "bin/fizzbuzz",
"bin": {
Expand All @@ -9,7 +9,7 @@
},
"preferGlobal": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha --harmony"
},
"repository": {
"type": "git",
Expand Down
53 changes: 38 additions & 15 deletions test/fizz.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var should = require('should');

var oneto100 = require('./ans/1-100.json');

var standard = require('../lib/standard');
var standardFizz = require('../lib/standard')
, yieldFizz = require('../lib/yield');

describe('fizzbuzz', function() {
var results = []
Expand All @@ -14,20 +15,42 @@ describe('fizzbuzz', function() {
beforeEach(function() {
results = [];
});
it('should run through the basic fizzbuzz test', function() {
standard(1, 100, addToResults);

results.length.should.eql(100);
for (var i = 0; i < 100; i++) {
results[i].should.eql(oneto100[i]);
}
describe('standard', function() {
it('should run through the basic fizzbuzz test', function() {
standardFizz(1, 100, addToResults);

results.length.should.eql(100);
for (var i = 0; i < 100; i++) {
results[i].should.eql(oneto100[i]);
}
});
it('works on numbers other than 1-100', function() {
standardFizz(1, 10, addToResults);

results.length.should.eql(10);
for (var i = 0; i < 10; i++) {
results[i].should.eql(oneto100[i]);
}
});
});

describe('yield', function() {
it('should run through the basic fizzbuzz test', function() {
yieldFizz(1, 100, addToResults);

results.length.should.eql(100);
for (var i = 0; i < 100; i++) {
results[i].should.eql(oneto100[i]);
}
});
it('works on numbers other than 1-100', function() {
yieldFizz(1, 10, addToResults);

results.length.should.eql(10);
for (var i = 0; i < 10; i++) {
results[i].should.eql(oneto100[i]);
}
});
});
it('works on numbers other than 1-100', function() {
standard(1, 10, addToResults);

results.length.should.eql(10);
for (var i = 0; i < 10; i++) {
results[i].should.eql(oneto100[i]);
}
})
});

0 comments on commit 7283a89

Please sign in to comment.