This is a continuation of Code Kata == Practice; I left off with two tests for my fake customer request; one test is passing and the other isn’t. Going forward I had decided to create a new class WordFinder which is responsible for finding all of the words in the provided string. For definition purposes a word is text that is separated from other words by spaces.
It starts with a single test.
@Test
public void testFindWords() {
String seed = "I am a programmer";
String[] expectedWords = { "I", "am", "a", "programmer" };
int expectedNumberOfWords = expectedWords.length;
WordFinder finder = new WordFinder();
String[] foundWords = finder.findWords(seed);
assertEquals(expectedNumberOfWords, foundWords.length);
assertEquals(expectedWords[0], foundWords[0]);
assertEquals(expectedWords[1], foundWords[1]);
assertEquals(expectedWords[2], foundWords[2]);
assertEquals(expectedWords[3], foundWords[3]);
}
and then an implementation:
public String[] findWords(String seed) {
String[] foundWords = seed.split(SINGLE_SPACE);
return foundWords;
}
