Add tests for MissingChapters function

(cherry picked from commit 8ab7e632936a008d31a87acd335fbd5fb21d818b)

# Conflicts:
#	domain/build.gradle.kts
This commit is contained in:
arkon
2023-04-15 09:51:52 -04:00
committed by Jobobby04
parent 18546e0410
commit 4d1244daef
8 changed files with 51 additions and 25 deletions
@@ -1,23 +1,21 @@
package tachiyomi.domain.chapter.service
import kotlin.math.floor
fun countMissingChapters(chaptersInput: List<Float>): Int? {
if (chaptersInput.isEmpty()) {
fun List<Float>.missingChaptersCount(): Int {
if (this.isEmpty()) {
return 0
}
val chapters = chaptersInput
// Remove any invalid chapters
.filter { it != -1f }
val chapters = this
// Ignore unknown chapter numbers
.filterNot { it == -1f }
// Convert to integers, as we cannot check if 16.5 is missing
.map { floor(it.toDouble()).toInt() }
.map(Float::toInt)
// Only keep unique chapters so that -1 or 16 are not counted multiple times
.distinct()
.sorted()
if (chapters.isEmpty()) {
return null
return 0
}
var missingChaptersCount = 0