### Question:
BytesFunctions { public static int indexOf(final byte[] bytes, final byte[] pattern, final int firstIndex, final int lastIndex) { for (int i = firstIndex; i <= lastIndex - pattern.length; i++) { if (bytes[i] == pattern[0]) { boolean isEqual = true; for (int j = 1; j < pattern.length; j++) { if (bytes[i + j] != pattern[j]) { isEqual = false; break; } } if (isEqual) { return i; } } } return -1; } private  BytesFunctions(); static int indexOf(final byte[] bytes, final byte[] pattern, final int firstIndex, final int lastIndex); static int compare(final byte[] b1, final byte[] b2);  }### Answer:
@Test public void testIndexOf() { final int length = 100; final byte[] bytes = getBytes(length); final int startIndex = 0; final int lastIndex = length; final List<Pair<Integer, byte[]>> list = new ArrayList<>(); list.add(new Pair<>(45, new byte[] { 45, 46, 47 })); list.add(new Pair<>(-1, new byte[] { 45, 30, 12 })); list.add(new Pair<>(-1, new byte[] { length - 1, length })); list.add(new Pair<>(-1, new byte[] { length })); list.add(new Pair<>(length - 2, new byte[] { length - 2, length - 1 })); list.add(new Pair<>(length - 1, new byte[] { length - 1 })); list.add(new Pair<>(0, new byte[] { 0, 1 })); list.add(new Pair<>(0, new byte[] { 0 })); for (final Pair<Integer, byte[]> pair : list) { Assert.assertEquals(pair.getFirst().intValue(), BytesFunctions.indexOf(bytes, pair.getSecond(), startIndex, lastIndex)); } }