Skip to content

Commit e8be523

Browse files
LomaxOnTheRuncarvallegro
authored andcommitted
Group A: FizzBuzz work
* Session for the group A, doing the Yatzy kata. * Added fizzbuzz kata
1 parent b6a929d commit e8be523

File tree

7 files changed

+399
-17
lines changed

7 files changed

+399
-17
lines changed

katas/fizz-buzz/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function fizzbuzz(number){
2+
if (isNaN(number)) {
3+
return null;
4+
}
5+
if(number % 15 == 0){
6+
return 'fizzbuzz';
7+
} else if(number % 5 == 0) {
8+
return 'buzz';
9+
} else if(number % 3 ==0) {
10+
return 'fizz';
11+
} else {
12+
return number;
13+
}
14+
}
15+
16+
function printLines (num) {
17+
return '';
18+
}
19+
20+
module.exports= {
21+
fizzbuzz, printLines
22+
}

katas/fizz-buzz/package-lock.json

Lines changed: 218 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

katas/fizz-buzz/package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{
2-
"name": "fizz-buzz",
2+
"name": "fizzbuzz",
3+
"version": "1.0.0",
4+
"description": "FizzBuzz kata",
5+
"main": "index.js",
36
"scripts": {
4-
"test": "mocha -w"
7+
"test": "mocha -w --reporter spec"
58
},
6-
"devDependencies": {
7-
"mocha": "3.2.0"
8-
}
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"chai": "^4.1.2",
13+
"mocha": "^5.2.0"
14+
},
15+
"devDependencies": {}
916
}

katas/fizz-buzz/test.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,53 @@
1-
const assert = require('assert');
1+
var fizzbuzz = require('./index').fizzbuzz;
2+
var printLines = require('./index').printLines;
23

3-
describe('Fizz Buzz Game', function() {
4+
var assert = require('chai').assert;
5+
6+
describe('Example test', function() {
47

5-
it('works', () => {
8+
it('does works', () => {
69
const expected = true;
7-
const actual = false;
10+
const actual = true;
811

912
assert.equal(actual, expected);
1013
});
14+
});
15+
16+
describe('Fizz Buzz Game', function() {
17+
18+
// Put tests here
19+
it('1 should return 1', () => {
20+
assert.equal(fizzbuzz(1), 1);
21+
})
22+
23+
it('should return fizz divisible by 3', () => {
24+
assert.equal(fizzbuzz(3), 'fizz');
25+
assert.equal(fizzbuzz(6), 'fizz');
26+
27+
})
28+
29+
it('should return buzz divisible by 5', () => {
30+
assert.equal(fizzbuzz(5), 'buzz');
31+
assert.equal(fizzbuzz(20), 'buzz');
32+
33+
})
34+
35+
it('should return fizzbuzz if divisible by 15', () => {
36+
assert.equal(fizzbuzz(15), 'fizzbuzz');
37+
assert.equal(fizzbuzz(45), 'fizzbuzz');
38+
})
39+
40+
it('should return null if input not a number', () => {
41+
assert.equal(fizzbuzz('yes'), null);
42+
})
1143

1244
});
45+
46+
describe('Line Printer', function() {
47+
48+
it('Returns an array', () => {
49+
const actual = printLines(0);
50+
const expected = '';
51+
assert.strictEqual(actual, expected);
52+
})
53+
})

katas/yatzy/index.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1-
function Yatzy(){}
1+
const _ = require('lodash')
2+
const CONSTRUCTOR_ERROR = new Error("The parameter should be an array of 5 integers between 1 and 6.");
3+
const NUMBER_OF_DICE = 5;
4+
const MAX_VALUE = 6;
5+
const MIN_VALUE = 1;
26

3-
module.exports = yatzy;
7+
class Yatzy {
8+
constructor(diceRolls) {
9+
if (!_.isArray(diceRolls) || _.size(diceRolls) !== NUMBER_OF_DICE) {
10+
throw CONSTRUCTOR_ERROR
11+
}
12+
_.forEach(diceRolls, (diceRoll) => {
13+
if (!_.isInteger(diceRoll) || !_.inRange(diceRoll, MIN_VALUE, MAX_VALUE)) {
14+
throw CONSTRUCTOR_ERROR
15+
}
16+
})
17+
this.diceRolls = diceRolls
18+
}
19+
chance() {
20+
return _.sum(this.diceRolls)
21+
}
22+
yatzy() {
23+
if (_(this.diceRolls).uniq().size() === 1) {
24+
return _.sum(this.diceRolls)
25+
}
26+
return 0
27+
}
28+
number(value) {
29+
return _(this.diceRolls).filter(roll => roll === value).sum()
30+
}
31+
pair() {
32+
if (_(this.diceRolls).uniq().size() === 5) {
33+
return 0
34+
}
35+
return _(this.diceRolls).countBy().filter((val, key) => key > 1)
36+
.map((value, key) => value * 2).max()
37+
// TODO: FIXME
38+
// TODO: find ressource to explain async and functions as arguments
39+
// TODO: find resources to explain how to setup
40+
}
41+
}
42+
module.exports = Yatzy;

katas/yatzy/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
"description": "This Refactoring Kata was designed by Jon Jagger and is available in his Cyber-Dojo. See [his blog post](http://jonjagger.blogspot.co.uk/2012/05/yahtzee-cyber-dojo-refactoring-in-java.html)",
55
"main": "index.js",
66
"scripts": {
7-
"test": "mocha -w"
7+
"test": "mocha -w",
8+
"test:coverage": "nyc mocha"
89
},
910
"devDependencies": {
1011
"mocha": "3.2.0"
1112
},
1213
"dependencies": {
13-
"chai": "^4.1.2"
14+
"chai": "^4.1.2",
15+
"lodash": "^4.17.10",
16+
"nyc": "^11.8.0"
1417
}
1518
}

0 commit comments

Comments
 (0)