RandomProblem002 { public static boolean patternExistInText(String text, String pattern) { int n = text.length(); int m = pattern.length(); for (int i = 0; i < n - m; i++) { int j = 0; while (j < m && text.charAt(i + j) == pattern.charAt(j)) { j++; } if (j == m) return true; } return false; }  static boolean patternExistInText(String text, String pattern);  }
@Test public void shouldGiveTrueWhenPatternExistInText() throws Exception { String text = Files.lines(Paths.get("src", "test", "resources", "book.txt")).collect(joining()); boolean patternExists = RandomProblem002.patternExistInText(text, "prudent"); assertTrue(patternExists); }
@Test public void shouldGiveFalseWhenPatternDoesNotExistInText() throws Exception { String text = Files.lines(Paths.get("src", "test", "resources", "book.txt")).collect(joining()); boolean patternExists = RandomProblem002.patternExistInText(text, "awesome"); assertFalse(patternExists); }