From fc74050c99bdf3d4cc7dd13ae45ef9ebb5aa64d9 Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sat, 15 Oct 2022 16:41:13 +0200 Subject: [PATCH] Increase unit test coverage to like 0.000001% --- ktx/build.gradle.kts | 2 + .../de/mm20/launcher2/ktx/StringKtTest.kt | 52 +++++++++++++++++++ settings.gradle.kts | 4 ++ 3 files changed, 58 insertions(+) create mode 100644 ktx/src/test/java/de/mm20/launcher2/ktx/StringKtTest.kt diff --git a/ktx/build.gradle.kts b/ktx/build.gradle.kts index 5a9a0a93..945545a5 100644 --- a/ktx/build.gradle.kts +++ b/ktx/build.gradle.kts @@ -43,4 +43,6 @@ dependencies { implementation(libs.bundles.androidx.lifecycle) implementation(libs.commons.text) + testImplementation(libs.bundles.tests) + } \ No newline at end of file diff --git a/ktx/src/test/java/de/mm20/launcher2/ktx/StringKtTest.kt b/ktx/src/test/java/de/mm20/launcher2/ktx/StringKtTest.kt new file mode 100644 index 00000000..27946792 --- /dev/null +++ b/ktx/src/test/java/de/mm20/launcher2/ktx/StringKtTest.kt @@ -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 + ) + } + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index c4eab86d..456b07a3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -280,6 +280,10 @@ dependencyResolutionManagement { library("lottie", "com.airbnb.android", "lottie-compose") .version("5.2.0") + + version("junit", "4.13") + library("junit", "junit", "junit").versionRef("junit") + bundle("tests", listOf("junit")) } } }