WordSearch { public boolean contains(char[][] wordSearch, String word) { validateInputData(wordSearch, word); for (int i = 0; i < wordSearch.length; i++) { for (int j = 0; j < wordSearch[i].length; j++) { if (matches(wordSearch, i, j, word.charAt(0))) { if (isWordInWordSearchInner(wordSearch, word, i, j)) { return true; } } } } return false; }  boolean contains(char[][] wordSearch, String word);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullWordSearch() { wordSearch.contains(null, "word"); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullWordsToSearchInTheMatrix() { wordSearch.contains(new char[0][0], null); }
@Test public void shouldReturnFalseIfWordSearchIsEmpty() { char[][] matrix = { { 'a', 'a', 'c', 'd', 'e' }, { 'a', 'd', 'a', 'r', 'c' }, { 'a', 'd', 'a', 'c', 'c' }, { 'b', 'a', 'c', 'o', 'o' } }; boolean result = wordSearch.contains(matrix, "pedro"); assertFalse(result); }
@Test public void shouldReturnTrueIfWordToSearchIsInsideWordSearch() { char[][] matrix = { { 'a', 'a', 'c', 'd', 'e' }, { 'a', 'd', 'a', 'r', 'c' }, { 'a', 'd', 'a', 'c', 'c' }, { 'b', 'a', 'c', 'o', 'o' } }; boolean result = wordSearch.contains(matrix, "baco"); assertTrue(result); }