Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
test: expand APIUtils.find test
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerus committed Jul 27, 2019
1 parent 49317b6 commit 4116b5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/main/xerus/monstercat/api/APIUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fun String.splitTitle(): List<String> {
return matches.groupValues.subList(1, matches.groupValues.size).mapNotNull { it.trim().nullIfEmpty() }
}

val meaninglessTitleContents = arrayOf("feat.", "Remix")
val meaninglessTitleContents = arrayOf("", "feat.", "Remix")

fun String.splitTitleTrimmed() =
split(' ', ',', '[', ']', '(', ')', '&').filterNot { it in meaninglessTitleContents }
Expand All @@ -37,9 +37,8 @@ object APIUtils {
val splitTitleTrimmed = track.init().splitTitle
titleSplit.sumBy { splitTitleTrimmed.contains(it).toInt() }
.also {
if(it > loggingThreshold) {
logger.trace { "Rated $track with $it for \"$artists - $title\"" }
}
if(it > loggingThreshold)
logger.trace { "Rated $track with $it for \"$artists - $title\" - $splitTitleTrimmed $titleSplit" }
}
}
}
Expand Down
26 changes: 20 additions & 6 deletions src/test/xerus/monstercat/api/APIUtilsTest.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
package xerus.monstercat.api

import io.kotlintest.matchers.collections.shouldNotContain
import io.kotlintest.inspectors.forAll
import io.kotlintest.shouldBe
import io.kotlintest.specs.StringSpec
import xerus.monstercat.api.response.ArtistRel
import kotlinx.coroutines.runBlocking
import xerus.ktutil.printIt

data class SongSearch(val searchTerm: String, val expectedTerm: String? = null)

internal class APIUtilsTest: StringSpec({

"find Edge of the World by Karma Fields" {
val edge = APIUtils.find("Edge Of The World", "Karma Fields")!!
edge.artists shouldNotContain ArtistRel("Razihel")
edge.artistsTitle shouldBe "Karma Fields"
"APIUtils.find" {
arrayOf(
SongSearch("Karma Fields - Edge of the World"),
SongSearch("Julian Calor - Monster (feat. Trove)", "Julian Calor feat. Trove - Monster"),
SongSearch("Rootkit - Voyage (Kage Remix)")
).forAll {
runBlocking {
val search = it.searchTerm.split(" - ")
val result = APIUtils.find(search[1], search[0])
val expected = (it.expectedTerm ?: it.searchTerm).split(" - ", " (", ")")
result shouldBe Cache.getTracks().find {
it.artistsTitle == expected[0] && it.title == expected[1] && (expected.size < 3 || it.version == expected[2])
}.printIt()
}
}
}

})

0 comments on commit 4116b5c

Please sign in to comment.