@Test public void testPositionToBookIndex() { Assert.assertEquals(0, VerseHelper.positionToBookIndex(0)); Assert.assertEquals(0, VerseHelper.positionToBookIndex(49)); Assert.assertEquals(1, VerseHelper.positionToBookIndex(50)); Assert.assertEquals(1, VerseHelper.positionToBookIndex(55)); Assert.assertEquals(65, VerseHelper.positionToBookIndex(1188)); }
static int positionToBookIndex(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); position -= chapterCount; if (position < 0) { return bookIndex; } } throw new IllegalArgumentException("Invalid position: " + position); }
VerseHelper { static int positionToBookIndex(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); position -= chapterCount; if (position < 0) { return bookIndex; } } throw new IllegalArgumentException("Invalid position: " + position); } }
VerseHelper { static int positionToBookIndex(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); position -= chapterCount; if (position < 0) { return bookIndex; } } throw new IllegalArgumentException("Invalid position: " + position); }  }
VerseHelper { static int positionToBookIndex(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); position -= chapterCount; if (position < 0) { return bookIndex; } } throw new IllegalArgumentException("Invalid position: " + position); }   }
VerseHelper { static int positionToBookIndex(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); position -= chapterCount; if (position < 0) { return bookIndex; } } throw new IllegalArgumentException("Invalid position: " + position); }    }