mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Fix unit tests
This commit is contained in:
parent
cd91ea9b77
commit
59f7d2273f
3 changed files with 83 additions and 83 deletions
|
@ -81,22 +81,22 @@ object ChapterRecognition {
|
|||
* @param alpha alpha value of regex
|
||||
* @return decimal/alpha float value
|
||||
*/
|
||||
private fun checkForDecimal(decimal: String?, alpha: String?): Float {
|
||||
private fun checkForDecimal(decimal: String?, alpha: String?): Double {
|
||||
if (!decimal.isNullOrEmpty()) {
|
||||
return decimal.toFloat()
|
||||
return decimal.toDouble()
|
||||
}
|
||||
|
||||
if (!alpha.isNullOrEmpty()) {
|
||||
if (alpha.contains("extra")) {
|
||||
return .99f
|
||||
return 0.99
|
||||
}
|
||||
|
||||
if (alpha.contains("omake")) {
|
||||
return .98f
|
||||
return 0.98
|
||||
}
|
||||
|
||||
if (alpha.contains("special")) {
|
||||
return .97f
|
||||
return 0.97
|
||||
}
|
||||
|
||||
val trimmedAlpha = alpha.trimStart('.')
|
||||
|
@ -105,15 +105,15 @@ object ChapterRecognition {
|
|||
}
|
||||
}
|
||||
|
||||
return .0f
|
||||
return 0.0
|
||||
}
|
||||
|
||||
/**
|
||||
* x.a -> x.1, x.b -> x.2, etc
|
||||
*/
|
||||
private fun parseAlphaPostFix(alpha: Char): Float {
|
||||
private fun parseAlphaPostFix(alpha: Char): Double {
|
||||
val number = alpha.code - ('a'.code - 1)
|
||||
if (number >= 10) return 0f
|
||||
return number / 10f
|
||||
if (number >= 10) return 0.0
|
||||
return number / 10.0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,152 +12,152 @@ class ChapterRecognitionTest {
|
|||
fun `Basic Ch prefix`() {
|
||||
val mangaTitle = "Mokushiroku Alice"
|
||||
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4: Misrepresentation", 4f)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4: Misrepresentation", 4.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Basic Ch prefix with space after period`() {
|
||||
val mangaTitle = "Mokushiroku Alice"
|
||||
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol. 1 Ch. 4: Misrepresentation", 4f)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol. 1 Ch. 4: Misrepresentation", 4.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Basic Ch prefix with decimal`() {
|
||||
val mangaTitle = "Mokushiroku Alice"
|
||||
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4.1: Misrepresentation", 4.1f)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4.4: Misrepresentation", 4.4f)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4.1: Misrepresentation", 4.1)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4.4: Misrepresentation", 4.4)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Basic Ch prefix with alpha postfix`() {
|
||||
val mangaTitle = "Mokushiroku Alice"
|
||||
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4.a: Misrepresentation", 4.1f)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4.b: Misrepresentation", 4.2f)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4.extra: Misrepresentation", 4.99f)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4.a: Misrepresentation", 4.1)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4.b: Misrepresentation", 4.2)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch.4.extra: Misrepresentation", 4.99)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Name containing one number`() {
|
||||
val mangaTitle = "Bleach"
|
||||
|
||||
assertChapter(mangaTitle, "Bleach 567 Down With Snowwhite", 567f)
|
||||
assertChapter(mangaTitle, "Bleach 567 Down With Snowwhite", 567.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Name containing one number and decimal`() {
|
||||
val mangaTitle = "Bleach"
|
||||
|
||||
assertChapter(mangaTitle, "Bleach 567.1 Down With Snowwhite", 567.1f)
|
||||
assertChapter(mangaTitle, "Bleach 567.4 Down With Snowwhite", 567.4f)
|
||||
assertChapter(mangaTitle, "Bleach 567.1 Down With Snowwhite", 567.1)
|
||||
assertChapter(mangaTitle, "Bleach 567.4 Down With Snowwhite", 567.4)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Name containing one number and alpha`() {
|
||||
val mangaTitle = "Bleach"
|
||||
|
||||
assertChapter(mangaTitle, "Bleach 567.a Down With Snowwhite", 567.1f)
|
||||
assertChapter(mangaTitle, "Bleach 567.b Down With Snowwhite", 567.2f)
|
||||
assertChapter(mangaTitle, "Bleach 567.extra Down With Snowwhite", 567.99f)
|
||||
assertChapter(mangaTitle, "Bleach 567.a Down With Snowwhite", 567.1)
|
||||
assertChapter(mangaTitle, "Bleach 567.b Down With Snowwhite", 567.2)
|
||||
assertChapter(mangaTitle, "Bleach 567.extra Down With Snowwhite", 567.99)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter containing manga title and number`() {
|
||||
val mangaTitle = "Solanin"
|
||||
|
||||
assertChapter(mangaTitle, "Solanin 028 Vol. 2", 28f)
|
||||
assertChapter(mangaTitle, "Solanin 028 Vol. 2", 28.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter containing manga title and number decimal`() {
|
||||
val mangaTitle = "Solanin"
|
||||
|
||||
assertChapter(mangaTitle, "Solanin 028.1 Vol. 2", 28.1f)
|
||||
assertChapter(mangaTitle, "Solanin 028.4 Vol. 2", 28.4f)
|
||||
assertChapter(mangaTitle, "Solanin 028.1 Vol. 2", 28.1)
|
||||
assertChapter(mangaTitle, "Solanin 028.4 Vol. 2", 28.4)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter containing manga title and number alpha`() {
|
||||
val mangaTitle = "Solanin"
|
||||
|
||||
assertChapter(mangaTitle, "Solanin 028.a Vol. 2", 28.1f)
|
||||
assertChapter(mangaTitle, "Solanin 028.b Vol. 2", 28.2f)
|
||||
assertChapter(mangaTitle, "Solanin 028.extra Vol. 2", 28.99f)
|
||||
assertChapter(mangaTitle, "Solanin 028.a Vol. 2", 28.1)
|
||||
assertChapter(mangaTitle, "Solanin 028.b Vol. 2", 28.2)
|
||||
assertChapter(mangaTitle, "Solanin 028.extra Vol. 2", 28.99)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Extreme case`() {
|
||||
val mangaTitle = "Onepunch-Man"
|
||||
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028", 28f)
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028", 28.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Extreme case with decimal`() {
|
||||
val mangaTitle = "Onepunch-Man"
|
||||
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028.1", 28.1f)
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028.4", 28.4f)
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028.1", 28.1)
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028.4", 28.4)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Extreme case with alpha`() {
|
||||
val mangaTitle = "Onepunch-Man"
|
||||
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028.a", 28.1f)
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028.b", 28.2f)
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028.extra", 28.99f)
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028.a", 28.1)
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028.b", 28.2)
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 028.extra", 28.99)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter containing dot v2`() {
|
||||
val mangaTitle = "random"
|
||||
|
||||
assertChapter(mangaTitle, "Vol.1 Ch.5v.2: Alones", 5f)
|
||||
assertChapter(mangaTitle, "Vol.1 Ch.5v.2: Alones", 5.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Number in manga title`() {
|
||||
val mangaTitle = "Ayame 14"
|
||||
|
||||
assertChapter(mangaTitle, "Ayame 14 1 - The summer of 14", 1f)
|
||||
assertChapter(mangaTitle, "Ayame 14 1 - The summer of 14", 1.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Space between ch x`() {
|
||||
val mangaTitle = "Mokushiroku Alice"
|
||||
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch. 4: Misrepresentation", 4f)
|
||||
assertChapter(mangaTitle, "Mokushiroku Alice Vol.1 Ch. 4: Misrepresentation", 4.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter title with ch substring`() {
|
||||
val mangaTitle = "Ayame 14"
|
||||
|
||||
assertChapter(mangaTitle, "Vol.1 Ch.1: March 25 (First Day Cohabiting)", 1f)
|
||||
assertChapter(mangaTitle, "Vol.1 Ch.1: March 25 (First Day Cohabiting)", 1.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter containing multiple zeros`() {
|
||||
val mangaTitle = "random"
|
||||
|
||||
assertChapter(mangaTitle, "Vol.001 Ch.003: Kaguya Doesn't Know Much", 3f)
|
||||
assertChapter(mangaTitle, "Vol.001 Ch.003: Kaguya Doesn't Know Much", 3.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter with version before number`() {
|
||||
val mangaTitle = "Onepunch-Man"
|
||||
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 086 : Creeping Darkness [3]", 86f)
|
||||
assertChapter(mangaTitle, "Onepunch-Man Punch Ver002 086 : Creeping Darkness [3]", 86.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Version attached to chapter number`() {
|
||||
val mangaTitle = "Ansatsu Kyoushitsu"
|
||||
|
||||
assertChapter(mangaTitle, "Ansatsu Kyoushitsu 011v002: Assembly Time", 11f)
|
||||
assertChapter(mangaTitle, "Ansatsu Kyoushitsu 011v002: Assembly Time", 11.0)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,99 +168,99 @@ class ChapterRecognitionTest {
|
|||
fun `Number after manga title with chapter in chapter title case`() {
|
||||
val mangaTitle = "Tokyo ESP"
|
||||
|
||||
assertChapter(mangaTitle, "Tokyo ESP 027: Part 002: Chapter 001", 027f)
|
||||
assertChapter(mangaTitle, "Tokyo ESP 027: Part 002: Chapter 001", 027.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Unparseable chapter`() {
|
||||
val mangaTitle = "random"
|
||||
|
||||
assertChapter(mangaTitle, "Foo", -1f)
|
||||
assertChapter(mangaTitle, "Foo", -1.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter with time in title`() {
|
||||
val mangaTitle = "random"
|
||||
|
||||
assertChapter(mangaTitle, "Fairy Tail 404: 00:00", 404f)
|
||||
assertChapter(mangaTitle, "Fairy Tail 404: 00:00", 404.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter with alpha without dot`() {
|
||||
val mangaTitle = "random"
|
||||
|
||||
assertChapter(mangaTitle, "Asu No Yoichi 19a", 19.1f)
|
||||
assertChapter(mangaTitle, "Asu No Yoichi 19a", 19.1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter title containing extra and vol`() {
|
||||
val mangaTitle = "Fairy Tail"
|
||||
|
||||
assertChapter(mangaTitle, "Fairy Tail 404.extravol002", 404.99f)
|
||||
assertChapter(mangaTitle, "Fairy Tail 404 extravol002", 404.99f)
|
||||
assertChapter(mangaTitle, "Fairy Tail 404.extravol002", 404.99)
|
||||
assertChapter(mangaTitle, "Fairy Tail 404 extravol002", 404.99)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter title containing omake (japanese extra) and vol`() {
|
||||
val mangaTitle = "Fairy Tail"
|
||||
|
||||
assertChapter(mangaTitle, "Fairy Tail 404.omakevol002", 404.98f)
|
||||
assertChapter(mangaTitle, "Fairy Tail 404 omakevol002", 404.98f)
|
||||
assertChapter(mangaTitle, "Fairy Tail 404.omakevol002", 404.98)
|
||||
assertChapter(mangaTitle, "Fairy Tail 404 omakevol002", 404.98)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter title containing special and vol`() {
|
||||
val mangaTitle = "Fairy Tail"
|
||||
|
||||
assertChapter(mangaTitle, "Fairy Tail 404.specialvol002", 404.97f)
|
||||
assertChapter(mangaTitle, "Fairy Tail 404 specialvol002", 404.97f)
|
||||
assertChapter(mangaTitle, "Fairy Tail 404.specialvol002", 404.97)
|
||||
assertChapter(mangaTitle, "Fairy Tail 404 specialvol002", 404.97)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter title containing commas`() {
|
||||
val mangaTitle = "One Piece"
|
||||
|
||||
assertChapter(mangaTitle, "One Piece 300,a", 300.1f)
|
||||
assertChapter(mangaTitle, "One Piece Ch,123,extra", 123.99f)
|
||||
assertChapter(mangaTitle, "One Piece the sunny, goes swimming 024,005", 24.005f)
|
||||
assertChapter(mangaTitle, "One Piece 300,a", 300.1)
|
||||
assertChapter(mangaTitle, "One Piece Ch,123,extra", 123.99)
|
||||
assertChapter(mangaTitle, "One Piece the sunny, goes swimming 024,005", 24.005)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapter title containing hyphens`() {
|
||||
val mangaTitle = "Solo Leveling"
|
||||
|
||||
assertChapter(mangaTitle, "ch 122-a", 122.1f)
|
||||
assertChapter(mangaTitle, "Solo Leveling Ch.123-extra", 123.99f)
|
||||
assertChapter(mangaTitle, "Solo Leveling, 024-005", 24.005f)
|
||||
assertChapter(mangaTitle, "Ch.191-200 Read Online", 191.200f)
|
||||
assertChapter(mangaTitle, "ch 122-a", 122.1)
|
||||
assertChapter(mangaTitle, "Solo Leveling Ch.123-extra", 123.99)
|
||||
assertChapter(mangaTitle, "Solo Leveling, 024-005", 24.005)
|
||||
assertChapter(mangaTitle, "Ch.191-200 Read Online", 191.200)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapters containing season`() {
|
||||
assertChapter("D.I.C.E", "D.I.C.E[Season 001] Ep. 007", 7f)
|
||||
assertChapter("D.I.C.E", "D.I.C.E[Season 001] Ep. 007", 7.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapters in format sx - chapter xx`() {
|
||||
assertChapter("The Gamer", "S3 - Chapter 20", 20f)
|
||||
assertChapter("The Gamer", "S3 - Chapter 20", 20.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapters ending with s`() {
|
||||
assertChapter("One Outs", "One Outs 001", 1f)
|
||||
assertChapter("One Outs", "One Outs 001", 1.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Chapters containing ordinals`() {
|
||||
val mangaTitle = "The Sister of the Woods with a Thousand Young"
|
||||
|
||||
assertChapter(mangaTitle, "The 1st Night", 1f)
|
||||
assertChapter(mangaTitle, "The 2nd Night", 2f)
|
||||
assertChapter(mangaTitle, "The 3rd Night", 3f)
|
||||
assertChapter(mangaTitle, "The 4th Night", 4f)
|
||||
assertChapter(mangaTitle, "The 1st Night", 1.0)
|
||||
assertChapter(mangaTitle, "The 2nd Night", 2.0)
|
||||
assertChapter(mangaTitle, "The 3rd Night", 3.0)
|
||||
assertChapter(mangaTitle, "The 4th Night", 4.0)
|
||||
}
|
||||
|
||||
private fun assertChapter(mangaTitle: String, name: String, expected: Float) {
|
||||
private fun assertChapter(mangaTitle: String, name: String, expected: Double) {
|
||||
ChapterRecognition.parseChapterNumber(mangaTitle, name) shouldBe expected
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,47 +11,47 @@ class MissingChaptersTest {
|
|||
|
||||
@Test
|
||||
fun `missingChaptersCount returns 0 when empty list`() {
|
||||
emptyList<Float>().missingChaptersCount() shouldBe 0
|
||||
emptyList<Double>().missingChaptersCount() shouldBe 0
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `missingChaptersCount returns 0 when all unknown chapter numbers`() {
|
||||
listOf(-1f, -1f, -1f).missingChaptersCount() shouldBe 0
|
||||
listOf(-1.0, -1.0, -1.0).missingChaptersCount() shouldBe 0
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `missingChaptersCount handles repeated base chapter numbers`() {
|
||||
listOf(1f, 1.0f, 1.1f, 1.5f, 1.6f, 1.99f).missingChaptersCount() shouldBe 0
|
||||
listOf(1.0, 1.0, 1.1, 1.5, 1.6, 1.99).missingChaptersCount() shouldBe 0
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `missingChaptersCount returns number of missing chapters`() {
|
||||
listOf(-1f, 1f, 2f, 2.2f, 4f, 6f, 10f, 11f).missingChaptersCount() shouldBe 5
|
||||
listOf(-1.0, 1.0, 2.0, 2.2, 4.0, 6.0, 10.0, 11.0).missingChaptersCount() shouldBe 5
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `calculateChapterGap returns difference`() {
|
||||
calculateChapterGap(chapter(10f), chapter(9f)) shouldBe 0f
|
||||
calculateChapterGap(chapter(10f), chapter(8f)) shouldBe 1f
|
||||
calculateChapterGap(chapter(10f), chapter(8.5f)) shouldBe 1f
|
||||
calculateChapterGap(chapter(10f), chapter(1.1f)) shouldBe 8f
|
||||
calculateChapterGap(chapter(10.0), chapter(9.0)) shouldBe 0f
|
||||
calculateChapterGap(chapter(10.0), chapter(8.0)) shouldBe 1f
|
||||
calculateChapterGap(chapter(10.0), chapter(8.5)) shouldBe 1f
|
||||
calculateChapterGap(chapter(10.0), chapter(1.1)) shouldBe 8f
|
||||
|
||||
calculateChapterGap(10f, 9f) shouldBe 0f
|
||||
calculateChapterGap(10f, 8f) shouldBe 1f
|
||||
calculateChapterGap(10f, 8.5f) shouldBe 1f
|
||||
calculateChapterGap(10f, 1.1f) shouldBe 8f
|
||||
calculateChapterGap(10.0, 9.0) shouldBe 0f
|
||||
calculateChapterGap(10.0, 8.0) shouldBe 1f
|
||||
calculateChapterGap(10.0, 8.5) shouldBe 1f
|
||||
calculateChapterGap(10.0, 1.1) shouldBe 8f
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `calculateChapterGap returns 0 if either are not valid chapter numbers`() {
|
||||
calculateChapterGap(chapter(-1f), chapter(10f)) shouldBe 0
|
||||
calculateChapterGap(chapter(99f), chapter(-1f)) shouldBe 0
|
||||
calculateChapterGap(chapter(-1.0), chapter(10.0)) shouldBe 0
|
||||
calculateChapterGap(chapter(99.0), chapter(-1.0)) shouldBe 0
|
||||
|
||||
calculateChapterGap(-1f, 10f) shouldBe 0
|
||||
calculateChapterGap(99f, -1f) shouldBe 0
|
||||
calculateChapterGap(-1.0, 10.0) shouldBe 0
|
||||
calculateChapterGap(99.0, -1.0) shouldBe 0
|
||||
}
|
||||
|
||||
private fun chapter(number: Float) = Chapter.create().copy(
|
||||
private fun chapter(number: Double) = Chapter.create().copy(
|
||||
chapterNumber = number,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue