diff --git a/src/main/xerus/monstercat/api/APIUtils.kt b/src/main/xerus/monstercat/api/APIUtils.kt index 362e67a..100c57b 100644 --- a/src/main/xerus/monstercat/api/APIUtils.kt +++ b/src/main/xerus/monstercat/api/APIUtils.kt @@ -20,7 +20,7 @@ fun String.splitTitle(): List { 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 } @@ -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" } } } } diff --git a/src/test/xerus/monstercat/api/APIUtilsTest.kt b/src/test/xerus/monstercat/api/APIUtilsTest.kt index 4ac3490..a21a910 100644 --- a/src/test/xerus/monstercat/api/APIUtilsTest.kt +++ b/src/test/xerus/monstercat/api/APIUtilsTest.kt @@ -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() + } + } } }) \ No newline at end of file