Created
February 17, 2016 09:53
-
-
Save wolframkriesing/45906736fdd20646e9bc to your computer and use it in GitHub Desktop.
Based on the article http://blog.8thlight.com/uncle-bob/2012/04/20/Why-Is-Estimating-So-Hard.html we did this kata in the team
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
// doing the above kata with the crewmeister team, yeah | |
const text = 'Four score and seven years ago our fathers brought forth upon this continent a new nation, conceived in liberty and dedicated to the proposition that all men are created equal'; | |
const maxCharactersPerLine = 13; | |
const SEPARATOR = ' '; | |
const splitUpIntoWords = (s) => s.split(SEPARATOR); | |
const joining = (line) => line.join(SEPARATOR); | |
const textFormatter = () => { | |
const parts = splitUpIntoWords(text); | |
let index = 0; | |
let formatted = []; | |
while (index < parts.length) { | |
let newLine = thePartsFrom(parts, index); | |
formatted.push(newLine); | |
index = index + newLine.length; | |
} | |
return formatted.map(joining); | |
} | |
const thePartsFrom = (parts, index) => { | |
const firstWord = parts[index + 0]; | |
const secondWord = parts[index + 1]; | |
const thirdWord = parts[index + 2]; | |
if ([firstWord, secondWord, thirdWord].join(' ').length <= maxCharactersPerLine) { | |
return [firstWord, secondWord, thirdWord]; | |
} | |
if ([firstWord, secondWord].join(' ').length <= maxCharactersPerLine) { | |
return [firstWord, secondWord]; | |
} | |
return [firstWord]; | |
} | |
describe('estimation kata', function() { | |
it('split up the words', () => { | |
const s = 'a b c'; | |
assert.deepEqual(['a', 'b', 'c'], splitUpIntoWords(s)); | |
}); | |
it('first line is "Four score"', () => { | |
const [firstLine] = textFormatter(text); | |
assert.equal("Four score", firstLine); | |
}); | |
it('second line is "and seven"', () => { | |
const [,secondLine] = textFormatter(text); | |
assert.equal("and seven", secondLine); | |
}); | |
it('third line is "years ago our"', () => { | |
const [,,thirdLine] = textFormatter(text); | |
assert.equal("years ago our", thirdLine); | |
}); | |
it('fourth line is "fathers"', () => { | |
const [,,,fourthLine] = textFormatter(text); | |
assert.equal("fathers", fourthLine); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment