Skip to content

Instantly share code, notes, and snippets.

@emadb
Last active August 29, 2015 14:06
Show Gist options
  • Save emadb/59d539f5c423d93758c3 to your computer and use it in GitHub Desktop.
Save emadb/59d539f5c423d93758c3 to your computer and use it in GitHub Desktop.
module.exports = (function() {
var fizzFun = function(n){
if (n % 3 == 0)
return 'fizz';
};
var buzzFun = function(n){
if (n % 5 == 0)
return 'buzz';
};
var funs = [fizzFun, buzzFun];
var FizzBuzz = function() { };
FizzBuzz.prototype.process = function(n) {
var result = funs.map(function(f){
return f(n) || '';
}).reduce(function(p, c){
return p + c;
});
if (result == '')
return n;
return result;
};
return FizzBuzz;
})();
var sinon = require("sinon")
var FizzBuzz = require("../libs/fizzBuzz");
var should = require("should")
describe("FizzBuzz", function() {
beforeEach(function() {
this.fizzBuzz = new FizzBuzz();
});
it("1 should return 1", function() {
var result = this.fizzBuzz.process(1);
result.should.eql(1);
});
it("2 should return 2", function() {
var result = this.fizzBuzz.process(2);
result.should.eql(2);
});
it("3 should return fizz", function() {
var result = this.fizzBuzz.process(3);
result.should.eql('fizz');
});
it("6 should return fizz", function() {
var result = this.fizzBuzz.process(6);
result.should.eql('fizz');
});
it("5 should return buzz", function() {
var result = this.fizzBuzz.process(5);
result.should.eql('buzz');
});
it("15 should return fizzbuzz", function() {
var result = this.fizzBuzz.process(15);
result.should.eql('fizzbuzz');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment