@Test public void testPositionToChapterIndex() { Assert.assertEquals(0, VerseHelper.positionToChapterIndex(0)); Assert.assertEquals(49, VerseHelper.positionToChapterIndex(49)); Assert.assertEquals(0, VerseHelper.positionToChapterIndex(50)); Assert.assertEquals(5, VerseHelper.positionToChapterIndex(55)); Assert.assertEquals(21, VerseHelper.positionToChapterIndex(1188)); }
static int positionToChapterIndex(int position) throws IllegalArgumentException { if (position < 0) { throw new IllegalArgumentException("Invalid position: " + position); } final int bookCount = Bible.getBookCount(); for (int bookIndex = 0; bookIndex < bookCount; ++bookIndex) { final int chapterCount = Bible.getChapterCount(bookIndex); if (position < chapterCount) { return position; } position -= chapterCount; } throw new IllegalArgumentException("Invalid position: " + position); }
VerseHelper { static int positionToChapterIndex(int position) throws IllegalArgumentException { if (position < 0) { throw new IllegalArgumentException("Invalid position: " + position); } final int bookCount = Bible.getBookCount(); for (int bookIndex = 0; bookIndex < bookCount; ++bookIndex) { final int chapterCount = Bible.getChapterCount(bookIndex); if (position < chapterCount) { return position; } position -= chapterCount; } throw new IllegalArgumentException("Invalid position: " + position); } }
VerseHelper { static int positionToChapterIndex(int position) throws IllegalArgumentException { if (position < 0) { throw new IllegalArgumentException("Invalid position: " + position); } final int bookCount = Bible.getBookCount(); for (int bookIndex = 0; bookIndex < bookCount; ++bookIndex) { final int chapterCount = Bible.getChapterCount(bookIndex); if (position < chapterCount) { return position; } position -= chapterCount; } throw new IllegalArgumentException("Invalid position: " + position); }  }
VerseHelper { static int positionToChapterIndex(int position) throws IllegalArgumentException { if (position < 0) { throw new IllegalArgumentException("Invalid position: " + position); } final int bookCount = Bible.getBookCount(); for (int bookIndex = 0; bookIndex < bookCount; ++bookIndex) { final int chapterCount = Bible.getChapterCount(bookIndex); if (position < chapterCount) { return position; } position -= chapterCount; } throw new IllegalArgumentException("Invalid position: " + position); }   }
VerseHelper { static int positionToChapterIndex(int position) throws IllegalArgumentException { if (position < 0) { throw new IllegalArgumentException("Invalid position: " + position); } final int bookCount = Bible.getBookCount(); for (int bookIndex = 0; bookIndex < bookCount; ++bookIndex) { final int chapterCount = Bible.getChapterCount(bookIndex); if (position < chapterCount) { return position; } position -= chapterCount; } throw new IllegalArgumentException("Invalid position: " + position); }    }