Increase unit test coverage to like 0.000001%

This commit is contained in:
MM20 2022-10-15 16:41:13 +02:00
parent ee89f60e9c
commit fc74050c99
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 58 additions and 0 deletions

View File

@ -43,4 +43,6 @@ dependencies {
implementation(libs.bundles.androidx.lifecycle) implementation(libs.bundles.androidx.lifecycle)
implementation(libs.commons.text) implementation(libs.commons.text)
testImplementation(libs.bundles.tests)
} }

View File

@ -0,0 +1,52 @@
package de.mm20.launcher2.ktx
import org.junit.Assert
import org.junit.Test
internal class StringKtTest {
@Test
fun stringNormalizer_diacritics() {
Assert.assertEquals("a b c d e f g h i j", "À b ç d Ę F Ğ h ï j".normalize())
}
@Test
fun stringNormalizer_ligatures() {
Assert.assertEquals("aeoessss", "ÆŒßẞ".normalize())
}
@Test
fun stringNormalizer_search() {
val pairs = listOf(
"文件" to "jian",
"文件" to "jiàn",
"文件" to "",
"génération" to "Generation",
"Kvæsitso" to "kvaes",
"Übersetzer" to "uberset",
)
for ((str, q) in pairs) {
Assert.assertTrue(str.normalize().contains(q.normalize()))
}
}
/**
* Test that A.contains(B) -> A.normalize().contains(B.normalize())
*/
@Test
fun stringNormalize_substring_implication() {
val pairs = listOf(
"文件" to "",
"génération" to "énér",
"Kvæsitso" to "æ",
"Übersetzer" to "übe",
)
for ((str, q) in pairs) {
Assert.assertTrue(
if (str.contains(q)) str.normalize().contains(q.normalize())
else true
)
}
}
}

View File

@ -280,6 +280,10 @@ dependencyResolutionManagement {
library("lottie", "com.airbnb.android", "lottie-compose") library("lottie", "com.airbnb.android", "lottie-compose")
.version("5.2.0") .version("5.2.0")
version("junit", "4.13")
library("junit", "junit", "junit").versionRef("junit")
bundle("tests", listOf("junit"))
} }
} }
} }