Skip to content

Instantly share code, notes, and snippets.

@Pindar
Created February 20, 2012 20:04
Show Gist options
  • Save Pindar/1871070 to your computer and use it in GitHub Desktop.
Save Pindar/1871070 to your computer and use it in GitHub Desktop.
FizzBuzz
KT.namespace("algo");
KT.algo.fizzBuzz = {
getValue: function (input) {
return ((input % 3 && !(input + '').match(/3/i)) ? (input % 5 && !(input + '').match(/5/i)) ? input : "" : "fizz") +
((input % 5 && !(input + '').match(/5/i)) ? "" : "Buzz");
}
};
(function () {
var fbUnderTest;
TestCase("fizzBuzz", sinon.testCase({
setUp: function () {
fbUnderTest = KT.algo.fizzBuzz;
},
"test fbUnderTest is an object":
function () {
assertObject(fbUnderTest);
},
"test get number of input":
function () {
assertEquals(1, fbUnderTest.getValue(1));
assertEquals(2, fbUnderTest.getValue(2));
},
"test get fizz if input a multiple of 3":
function () {
assertEquals("fizz", fbUnderTest.getValue(3));
assertEquals("fizz", fbUnderTest.getValue(6));
},
"test get fizz if input a multiple of 5":
function () {
assertEquals("Buzz", fbUnderTest.getValue(5));
assertEquals("Buzz", fbUnderTest.getValue(10));
},
"test get fizzBuzz if input is a multiple of 5 and 3":
function () {
assertEquals("fizzBuzz", fbUnderTest.getValue(15));
assertEquals("fizzBuzz", fbUnderTest.getValue(30));
},
"test if the number has a 3 in it":
function () {
assertEquals("fizz", fbUnderTest.getValue(13));
},
"test if the number has a 5 in it":
function () {
assertEquals("Buzz", fbUnderTest.getValue(59));
}
}));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment