-
-
Save sandropaganotti-zz/a18a947002832e0117f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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) { | |
return funs.map(function(f){ | |
return f(n) || ''; | |
}).join('') || n; | |
}; | |
return FizzBuzz; | |
})(); |
This file contains hidden or 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
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