Skip to content

Instantly share code, notes, and snippets.

@emadb emadb/fizzbuzz.js
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.