### Question:
CaterpillarSelectHostsStrategy implements SelectHostsStrategy { protected int startOfContiguousRun(int numHosts, List<Integer> hostIndexes) { int start = -1; for (int i = 0; i < hostIndexes.size(); i++) { int index = hostIndexes.get(i); if (!hostIndexes.contains((index + numHosts - 1) % numHosts)) { start = i; break; } } if (start >= 0) { for (int index = hostIndexes.get(start), j = 0; j < hostIndexes.size(); index++, j++) { if (!hostIndexes.contains(index % numHosts)) { start = -1; break; } } } return start; } CaterpillarSelectHostsStrategy(boolean caterpillar,
        int numberOfPlaces,
        boolean currentPartitionOnly); @Override boolean isCurrentPartitionOnly(); @Override List<MiruHost> selectHosts(MiruHost fromHost, List<MiruHost> allHosts, List<MiruPartition> partitions, int numberOfReplicas);  }### Answer:
@Test public void testStartOfContiguousRun() throws Exception { CaterpillarSelectHostsStrategy caterpillarSelectHostsStrategy = new CaterpillarSelectHostsStrategy(true, 1, false); assertEquals(0, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(0, 1, 2))); assertEquals(0, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(4, 5, 6))); assertEquals(0, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(7, 8, 9))); assertEquals(1, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(0, 8, 9))); assertEquals(2, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(0, 1, 9))); assertEquals(-1, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(0, 2, 3))); assertEquals(-1, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(0, 3, 4))); assertEquals(-1, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(6, 7, 9))); assertEquals(-1, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(6, 8, 9))); assertEquals(-1, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(1, 8, 9))); assertEquals(-1, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(0, 7, 8))); assertEquals(-1, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(0, 1, 8))); assertEquals(-1, caterpillarSelectHostsStrategy.startOfContiguousRun(10, Arrays.asList(1, 2, 9))); }