WordFinder Kata

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.

	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;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s