diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd4f2b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +.DS_Store diff --git a/fizzBuzz.js b/fizzBuzz.js new file mode 100644 index 0000000..cd46985 --- /dev/null +++ b/fizzBuzz.js @@ -0,0 +1,10 @@ +let methods = {} + +methods.convert = function (num) { + let Buzz = num%5 + let Fizz = num%3 + + return !Fizz ? (!Buzz ? 'FizzBuzz' : 'Fizz') : !Buzz ? 'Buzz' : '' +} + +module.exports = methods diff --git a/package.json b/package.json new file mode 100644 index 0000000..813980d --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "fizzbuzz-tdd", + "version": "1.0.0", + "description": "", + "main": "fizzBuzz.js", + "directories": { + "test": "test" + }, + "dependencies": { + "chai": "^3.5.0" + }, + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/mfpebrizal/fizzbuzz-tdd.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/mfpebrizal/fizzbuzz-tdd/issues" + }, + "homepage": "https://github.com/mfpebrizal/fizzbuzz-tdd#readme" +} diff --git a/test/fizzBuzz-test.js b/test/fizzBuzz-test.js new file mode 100644 index 0000000..1389562 --- /dev/null +++ b/test/fizzBuzz-test.js @@ -0,0 +1,33 @@ +const chai = require('chai'); +const should = chai.should() +const fizzBuzz = require('../fizzBuzz'); + +describe('FizzBuzz', function () { + it('should return "Fizz"',function () { + fizzBuzz.convert(3).should.equal('Fizz') + fizzBuzz.convert(9).should.equal('Fizz') + fizzBuzz.convert(12).should.equal('Fizz') + fizzBuzz.convert(21).should.equal('Fizz') + }) + + it('should return "Buzz"',function () { + fizzBuzz.convert(25).should.equal('Buzz') + fizzBuzz.convert(5).should.equal('Buzz') + fizzBuzz.convert(10).should.equal('Buzz') + fizzBuzz.convert(125).should.equal('Buzz') + }) + + it('should return "FizzBuzz"',function () { + fizzBuzz.convert(15).should.equal('FizzBuzz') + fizzBuzz.convert(60).should.equal('FizzBuzz') + fizzBuzz.convert(105).should.equal('FizzBuzz') + fizzBuzz.convert(90).should.equal('FizzBuzz') + }) + + it('should return nothing',function () { + fizzBuzz.convert(4).should.equal('') + fizzBuzz.convert(28).should.equal('') + fizzBuzz.convert(2).should.equal('') + fizzBuzz.convert(16).should.equal('') + }) +})