Consolidate missing chapters functions to domain module and add tests

This commit is contained in:
arkon
2023-04-22 11:34:51 -04:00
parent 94c94b2d88
commit 26f3995595
6 changed files with 67 additions and 65 deletions

View File

@@ -1,5 +1,8 @@
package tachiyomi.domain.chapter.service
import tachiyomi.domain.chapter.model.Chapter
import kotlin.math.floor
fun List<Float>.missingChaptersCount(): Int {
if (this.isEmpty()) {
return 0
@@ -33,3 +36,14 @@ fun List<Float>.missingChaptersCount(): Int {
return missingChaptersCount
}
fun calculateChapterGap(higherChapter: Chapter?, lowerChapter: Chapter?): Int {
if (higherChapter == null || lowerChapter == null) return 0
if (!higherChapter.isRecognizedNumber || !lowerChapter.isRecognizedNumber) return 0
return calculateChapterGap(higherChapter.chapterNumber, lowerChapter.chapterNumber)
}
fun calculateChapterGap(higherChapterNumber: Float, lowerChapterNumber: Float): Int {
if (higherChapterNumber < 0f || lowerChapterNumber < 0f) return 0
return floor(higherChapterNumber).toInt() - floor(lowerChapterNumber).toInt() - 1
}