diff --git a/buildSrc/src/main/kotlin/kt-fuzzy.testing.gradle.kts b/buildSrc/src/main/kotlin/kt-fuzzy.testing.gradle.kts index da60d1e..b9f28da 100644 --- a/buildSrc/src/main/kotlin/kt-fuzzy.testing.gradle.kts +++ b/buildSrc/src/main/kotlin/kt-fuzzy.testing.gradle.kts @@ -41,6 +41,8 @@ kotlin { val commonTest by getting { dependencies { implementation(libs.bundles.kotest) + + implementation(project(":common-test")) } } diff --git a/common-test/build.gradle.kts b/common-test/build.gradle.kts new file mode 100644 index 0000000..2cfeea2 --- /dev/null +++ b/common-test/build.gradle.kts @@ -0,0 +1,30 @@ +@file:Suppress("KotlinRedundantDiagnosticSuppress", "UNUSED_VARIABLE") + +import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode + + +plugins { + `kt-fuzzy`.repositories + `kt-fuzzy`.compilation + `kt-fuzzy`.tasks + `kt-fuzzy`.testing + `kt-fuzzy`.versioning +} + +group = "ca.solo-studios" +description = """ + Common test sources for kt-fuzzy and kt-string-similarity +""".trimIndent() + +kotlin { + explicitApi = ExplicitApiMode.Disabled + + sourceSets { + val commonMain by getting { + dependencies { + implementation(libs.kotlin.stdlib) + implementation(libs.bundles.kotest) + } + } + } +} diff --git a/common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/PreComputed.kt b/common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/PreComputed.kt new file mode 100644 index 0000000..34939e5 --- /dev/null +++ b/common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/PreComputed.kt @@ -0,0 +1,53 @@ +/* + * kt-fuzzy - A Kotlin library for fuzzy string matching + * Copyright (c) 2023-2023 solonovamax + * + * The file PreComputed.kt is part of kotlin-fuzzy + * Last modified on 29-09-2023 08:01 p.m. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * KT-FUZZY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package ca.solostudios.fuzzykt + +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import io.kotest.core.spec.style.scopes.FunSpecRootScope + +/** + * Tests a precomputed value with a context. + * + * This has to be platform-specific because js hates nested tests, so on js it does a hack to not be nested. + * + * @param context The context name + * @param precomputed The precomputed data + * @param resultFunction The similarity function + */ +expect fun FunSpecRootScope.testPrecomputed( + context: String, + precomputed: List, + resultFunction: (String, String) -> Double, +) + +expect fun FunSpecRootScope.testPrecomputed( + context: String, + precomputed: List>, + resultFunction: (T, U) -> V, +) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/kotest/KotestConfig.kt b/common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/kotest/KotestConfig.kt similarity index 97% rename from kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/kotest/KotestConfig.kt rename to common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/kotest/KotestConfig.kt index 4d96ae5..5b69994 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/kotest/KotestConfig.kt +++ b/common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/kotest/KotestConfig.kt @@ -26,7 +26,7 @@ * SOFTWARE. */ -package ca.solostudios.stringsimilarity.kotest +package ca.solostudios.fuzzykt.kotest import io.kotest.common.ExperimentalKotest import io.kotest.core.config.AbstractProjectConfig diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/utils/FuzzyTestData.kt b/common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/utils/FuzzyTestData.kt similarity index 92% rename from kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/utils/FuzzyTestData.kt rename to common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/utils/FuzzyTestData.kt index 8212ebf..526bce0 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/utils/FuzzyTestData.kt +++ b/common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/utils/FuzzyTestData.kt @@ -3,7 +3,7 @@ * Copyright (c) 2023-2023 solonovamax * * The file FuzzyTestData.kt is part of kotlin-fuzzy - * Last modified on 17-07-2023 03:46 p.m. + * Last modified on 29-09-2023 07:54 p.m. * * MIT License * @@ -26,6 +26,6 @@ * SOFTWARE. */ -package ca.solostudios.stringsimilarity.utils +package ca.solostudios.fuzzykt.utils -data class FuzzyTestData(val first: String, val second: String, val similarity: Double) +data class FuzzyTestData(val first: String, val second: String, val result: Double) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/utils/Tolerance.kt b/common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/utils/Tolerance.kt similarity index 96% rename from kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/utils/Tolerance.kt rename to common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/utils/Tolerance.kt index 0d161cc..47f4fc7 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/utils/Tolerance.kt +++ b/common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/utils/Tolerance.kt @@ -26,6 +26,6 @@ * SOFTWARE. */ -package ca.solostudios.stringsimilarity.utils +package ca.solostudios.fuzzykt.utils const val DEFAULT_TOLERANCE = 0.00001 diff --git a/kt-string-similarity/src/jsTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.js.kt b/common-test/src/jsMain/kotlin/ca/solostudios/fuzzykt/PreComputed.js.kt similarity index 71% rename from kt-string-similarity/src/jsTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.js.kt rename to common-test/src/jsMain/kotlin/ca/solostudios/fuzzykt/PreComputed.js.kt index b610aae..9e0835f 100644 --- a/kt-string-similarity/src/jsTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.js.kt +++ b/common-test/src/jsMain/kotlin/ca/solostudios/fuzzykt/PreComputed.js.kt @@ -3,7 +3,7 @@ * Copyright (c) 2023-2023 solonovamax * * The file PreComputed.js.kt is part of kotlin-fuzzy - * Last modified on 21-07-2023 02:52 p.m. + * Last modified on 29-09-2023 08:01 p.m. * * MIT License * @@ -26,10 +26,10 @@ * SOFTWARE. */ -package ca.solostudios.stringsimilarity +package ca.solostudios.fuzzykt -import ca.solostudios.stringsimilarity.utils.DEFAULT_TOLERANCE -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.DEFAULT_TOLERANCE +import ca.solostudios.fuzzykt.utils.FuzzyTestData import io.kotest.assertions.withClue import io.kotest.core.spec.style.scopes.FunSpecRootScope import io.kotest.datatest.getStableIdentifier @@ -39,12 +39,26 @@ import io.kotest.matchers.shouldBe actual fun FunSpecRootScope.testPrecomputed( context: String, precomputed: List, - similarityFunction: (String, String) -> Double, + resultFunction: (String, String) -> Double, ) { context(context) { precomputed.forEach { withClue({ getStableIdentifier(it) }) { - similarityFunction(it.first, it.second) shouldBe (it.similarity plusOrMinus DEFAULT_TOLERANCE) + resultFunction(it.first, it.second) shouldBe (it.result plusOrMinus DEFAULT_TOLERANCE) + } + } + } +} + +actual fun FunSpecRootScope.testPrecomputed( + context: String, + precomputed: List>, + resultFunction: (T, U) -> V, +) { + context(context) { + precomputed.forEach { + withClue({ getStableIdentifier(it) }) { + resultFunction(it.first, it.second) shouldBe it.third } } } diff --git a/kt-string-similarity/src/jvmTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.jvm.kt b/common-test/src/jvmMain/kotlin/ca/solostudios/fuzzykt/PreComputed.jvm.kt similarity index 71% rename from kt-string-similarity/src/jvmTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.jvm.kt rename to common-test/src/jvmMain/kotlin/ca/solostudios/fuzzykt/PreComputed.jvm.kt index e2b635c..a7445c0 100644 --- a/kt-string-similarity/src/jvmTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.jvm.kt +++ b/common-test/src/jvmMain/kotlin/ca/solostudios/fuzzykt/PreComputed.jvm.kt @@ -3,7 +3,7 @@ * Copyright (c) 2023-2023 solonovamax * * The file PreComputed.jvm.kt is part of kotlin-fuzzy - * Last modified on 21-07-2023 02:52 p.m. + * Last modified on 29-09-2023 08:01 p.m. * * MIT License * @@ -26,10 +26,10 @@ * SOFTWARE. */ -package ca.solostudios.stringsimilarity +package ca.solostudios.fuzzykt -import ca.solostudios.stringsimilarity.utils.DEFAULT_TOLERANCE -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.DEFAULT_TOLERANCE +import ca.solostudios.fuzzykt.utils.FuzzyTestData import io.kotest.core.spec.style.scopes.FunSpecRootScope import io.kotest.datatest.withData import io.kotest.matchers.doubles.plusOrMinus @@ -38,11 +38,24 @@ import io.kotest.matchers.shouldBe actual fun FunSpecRootScope.testPrecomputed( context: String, precomputed: List, - similarityFunction: (String, String) -> Double, + resultFunction: (String, String) -> Double, ) { context(context) { withData(precomputed) { - similarityFunction(it.first, it.second) shouldBe (it.similarity plusOrMinus DEFAULT_TOLERANCE) + resultFunction(it.first, it.second) shouldBe (it.result plusOrMinus DEFAULT_TOLERANCE) + } + } +} + +@JvmName("testPrecomputed\$generic") +actual fun FunSpecRootScope.testPrecomputed( + context: String, + precomputed: List>, + resultFunction: (T, U) -> V, +) { + context(context) { + withData(precomputed) { + resultFunction(it.first, it.second) shouldBe it.third } } } diff --git a/kt-string-similarity/src/nativeTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.native.kt b/common-test/src/nativeMain/kotlin/ca/solostudios/fuzzykt/PreComputed.native.kt similarity index 72% rename from kt-string-similarity/src/nativeTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.native.kt rename to common-test/src/nativeMain/kotlin/ca/solostudios/fuzzykt/PreComputed.native.kt index d44b10d..6d58729 100644 --- a/kt-string-similarity/src/nativeTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.native.kt +++ b/common-test/src/nativeMain/kotlin/ca/solostudios/fuzzykt/PreComputed.native.kt @@ -3,7 +3,7 @@ * Copyright (c) 2023-2023 solonovamax * * The file PreComputed.native.kt is part of kotlin-fuzzy - * Last modified on 04-08-2023 04:08 p.m. + * Last modified on 29-09-2023 08:01 p.m. * * MIT License * @@ -26,10 +26,10 @@ * SOFTWARE. */ -package ca.solostudios.stringsimilarity +package ca.solostudios.fuzzykt -import ca.solostudios.stringsimilarity.utils.DEFAULT_TOLERANCE -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.DEFAULT_TOLERANCE +import ca.solostudios.fuzzykt.utils.FuzzyTestData import io.kotest.core.spec.style.scopes.FunSpecRootScope import io.kotest.datatest.withData import io.kotest.matchers.doubles.plusOrMinus @@ -38,11 +38,23 @@ import io.kotest.matchers.shouldBe actual fun FunSpecRootScope.testPrecomputed( context: String, precomputed: List, - similarityFunction: (String, String) -> Double, + resultFunction: (String, String) -> Double, ) { context(context) { withData(precomputed) { - similarityFunction(it.first, it.second) shouldBe (it.similarity plusOrMinus DEFAULT_TOLERANCE) + resultFunction(it.first, it.second) shouldBe (it.result plusOrMinus DEFAULT_TOLERANCE) + } + } +} + +actual fun FunSpecRootScope.testPrecomputed( + context: String, + precomputed: List>, + resultFunction: (T, U) -> V, +) { + context(context) { + withData(precomputed) { + resultFunction(it.first, it.second) shouldBe it.third } } } diff --git a/kt-fuzzy/build.gradle.kts b/kt-fuzzy/build.gradle.kts index 6dd7287..41ae9c5 100644 --- a/kt-fuzzy/build.gradle.kts +++ b/kt-fuzzy/build.gradle.kts @@ -43,10 +43,6 @@ description = """ A dependency-less Kotlin Multiplatform library for fuzzy string matching """.trimIndent() -repositories { - mavenCentral() -} - kotlin { sourceSets { val commonMain by getting { @@ -56,11 +52,5 @@ kotlin { api(projects.ktStringSimilarity) } } - - val commonTest by getting { - dependencies { - implementation(libs.kotlin.test) // temporary - } - } } } diff --git a/kt-fuzzy/src/commonTest/kotlin/ca.solostudios.fuzzykt/FuzzyKtTest.kt b/kt-fuzzy/src/commonTest/kotlin/ca.solostudios.fuzzykt/FuzzyKtTest.kt deleted file mode 100644 index 5d40938..0000000 --- a/kt-fuzzy/src/commonTest/kotlin/ca.solostudios.fuzzykt/FuzzyKtTest.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * kt-fuzzy - A Kotlin library for fuzzy string matching - * Copyright (c) 2021-2023 solonovamax - * - * The file FuzzyKtTest.kt is part of kotlin-fuzzy - * Last modified on 22-07-2023 05:11 p.m. - * - * MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * KT-FUZZY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package ca.solostudios.fuzzykt - -import kotlin.test.Test -import kotlin.test.assertEquals - -class FuzzyKtTest { - @Test - fun testRatio() { - val ratioTests = - listOf( // s1, s2, expected - Triple("this is a test", "this is a test!", 0.9333333333333333), - Triple("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear", 0.9130434782608696), - Triple("abcd", "abcd", 1.0), - Triple("mysmilarstring", "myawfullysimilarstirng", 0.5652173913043479), - Triple("mysmilarstring", "mysimilarstring", 0.9333333333333333) - ) - for ((s1, s2, expected) in ratioTests) { - assertEquals(expected = expected, actual = FuzzyKt.ratio(s1, s2), absoluteTolerance = 0.001) - } - } - - @Test - fun testPartialRatio() { - val partialRatioTests = - listOf( // s1, s2, expected - Triple("this is a test", "this is a test!", 1.0), - Triple("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear", 0.9130434782608696), - Triple("abcd", "abcd", 1.0), - Triple("mysmilarstring", "myawfullysimilarstirng", 0.4358974358974359), - Triple("mysmilarstring", "mysimilarstring", 0.8666666666666667), - Triple("similar", "somewhresimlrbetweenthisstring", 0.5555555555555556) - ) - for ((s1, s2, expected) in partialRatioTests) { - assertEquals(expected = expected, actual = FuzzyKt.partialRatio(s1, s2), absoluteTolerance = 0.001) - } - } - - @Test - fun testLongestCommonSubstring() { - val substringTests = - listOf( // s1, s2, expected result - Triple("abcd", "bc", 1 to 3), - Triple("abcd", "123", 0 to 0), - Triple("abcd", "cdef", 2 to 4), - Triple("aaaa", "a", 0 to 1), - Triple("aabbaaa", "aaa", 4 to 7) - ) - - for ((s1, s2, expected) in substringTests) { - assertEquals(expected = expected, actual = FuzzyKt.longestCommonSubstring(s1, s2)) - } - } -} diff --git a/kt-fuzzy/src/commonTest/kotlin/ca/solostudios/fuzzykt/FuzzyKtTest.kt b/kt-fuzzy/src/commonTest/kotlin/ca/solostudios/fuzzykt/FuzzyKtTest.kt new file mode 100644 index 0000000..5d55423 --- /dev/null +++ b/kt-fuzzy/src/commonTest/kotlin/ca/solostudios/fuzzykt/FuzzyKtTest.kt @@ -0,0 +1,72 @@ +/* + * kt-fuzzy - A Kotlin library for fuzzy string matching + * Copyright (c) 2021-2023 solonovamax + * + * The file FuzzyKtTest.kt is part of kotlin-fuzzy + * Last modified on 29-09-2023 07:53 p.m. + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * KT-FUZZY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package ca.solostudios.fuzzykt + +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import io.kotest.core.spec.style.FunSpec + +class FuzzyKtTest : FunSpec({ + val precomputedRatios = + listOf( + FuzzyTestData("this is a test", "this is a test!", 0.93333), + FuzzyTestData("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear", 0.91304), + FuzzyTestData("abcd", "abcd", 1.0), + FuzzyTestData("mysmilarstring", "myawfullysimilarstirng", 0.56521), + FuzzyTestData("mysmilarstring", "mysimilarstring", 0.93333) + ) + testPrecomputed("Ratio should match all pre-computed results", precomputedRatios) { s1, s2 -> + FuzzyKt.ratio(s1, s2) + } + + val precomputedPartialRatios = + listOf( + FuzzyTestData("this is a test", "this is a test!", 1.0), + FuzzyTestData("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear", 0.91304), + FuzzyTestData("abcd", "abcd", 1.0), + FuzzyTestData("mysmilarstring", "myawfullysimilarstirng", 0.43589), + FuzzyTestData("mysmilarstring", "mysimilarstring", 0.86666), + FuzzyTestData("similar", "somewhresimlrbetweenthisstring", 0.55555) + ) + testPrecomputed("Partial ratio should match all pre-computed results", precomputedPartialRatios) { s1, s2 -> + FuzzyKt.partialRatio(s1, s2) + } + + val precomputedSubstrings = + listOf( + Triple("abcd", "bc", 1 to 3), + Triple("abcd", "123", 0 to 0), + Triple("abcd", "cdef", 2 to 4), + Triple("aaaa", "a", 0 to 1), + Triple("aabbaaa", "aaa", 4 to 7) + ) + + testPrecomputed("Longest common substrings should match all pre-computed results", precomputedSubstrings) { s1, s2 -> + FuzzyKt.longestCommonSubstring(s1, s2) + } +}) diff --git a/kt-string-similarity/build.gradle.kts b/kt-string-similarity/build.gradle.kts index 969ab5c..02e0e8d 100644 --- a/kt-string-similarity/build.gradle.kts +++ b/kt-string-similarity/build.gradle.kts @@ -44,10 +44,6 @@ description = """ Various string similarity and distance measures for Kotlin Multiplatform """.trimIndent() -repositories { - mavenCentral() -} - kotlin { sourceSets { val commonMain by getting { diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/CosineTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/CosineTest.kt index 71b830a..1161193 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/CosineTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/CosineTest.kt @@ -27,8 +27,12 @@ */ package ca.solostudios.stringsimilarity -import ca.solostudios.stringsimilarity.utils.DEFAULT_TOLERANCE -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.DEFAULT_TOLERANCE +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.normalizedDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedSimilarityTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.doubles.plusOrMinus import io.kotest.matchers.shouldBe @@ -45,7 +49,7 @@ class CosineTest : FunSpec({ ) include(precomputedSimilarityTests(precomputed, cosine)) - include(precomputedDistanceTests(precomputed.map { it.copy(similarity = 1 - it.similarity) }, cosine)) + include(precomputedDistanceTests(precomputed.map { it.copy(result = 1 - it.result) }, cosine)) test("should be 0 for strings smaller than k") { cosineSmallK.similarity("AB", "ABCE") shouldBe (0.0 plusOrMinus DEFAULT_TOLERANCE) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/JaccardTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/JaccardTest.kt index c9df8b7..345d40b 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/JaccardTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/JaccardTest.kt @@ -27,7 +27,12 @@ */ package ca.solostudios.stringsimilarity -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.metricDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedSimilarityTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests import io.kotest.core.spec.style.FunSpec class JaccardTest : FunSpec({ @@ -52,5 +57,5 @@ class JaccardTest : FunSpec({ ) include(precomputedSimilarityTests(precomputed, jaccard)) - include(precomputedDistanceTests(precomputed.map { it.copy(similarity = 1 - it.similarity) }, jaccard)) + include(precomputedDistanceTests(precomputed.map { it.copy(result = 1 - it.result) }, jaccard)) }) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/JaroWinklerTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/JaroWinklerTest.kt index 8789d57..3608d16 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/JaroWinklerTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/JaroWinklerTest.kt @@ -27,7 +27,11 @@ */ package ca.solostudios.stringsimilarity -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.normalizedDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedSimilarityTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests import io.kotest.core.spec.style.FunSpec class JaroWinklerTest : FunSpec({ @@ -52,5 +56,5 @@ class JaroWinklerTest : FunSpec({ ) include(precomputedSimilarityTests(precomputed, jaroWinkler)) - include(precomputedDistanceTests(precomputed.map { it.copy(similarity = 1 - it.similarity) }, jaroWinkler)) + include(precomputedDistanceTests(precomputed.map { it.copy(result = 1 - it.result) }, jaroWinkler)) }) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/NGramTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/NGramTest.kt index 06a87e6..6dffeb6 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/NGramTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/NGramTest.kt @@ -27,7 +27,11 @@ */ package ca.solostudios.stringsimilarity -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.normalizedDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedSimilarityTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests import io.kotest.core.spec.style.FunSpec class NGramTest : FunSpec({ @@ -49,5 +53,5 @@ class NGramTest : FunSpec({ ) include(precomputedSimilarityTests(precomputed, ngram)) - include(precomputedDistanceTests(precomputed.map { it.copy(similarity = 1 - it.similarity) }, ngram)) + include(precomputedDistanceTests(precomputed.map { it.copy(result = 1 - it.result) }, ngram)) }) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/QGramTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/QGramTest.kt index 8823542..c79fea9 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/QGramTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/QGramTest.kt @@ -27,7 +27,9 @@ */ package ca.solostudios.stringsimilarity -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.distanceTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests import io.kotest.core.spec.style.FunSpec class QGramTest : FunSpec({ diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/RatcliffObershelpTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/RatcliffObershelpTest.kt index dcac032..a435ef0 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/RatcliffObershelpTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/RatcliffObershelpTest.kt @@ -27,7 +27,11 @@ */ package ca.solostudios.stringsimilarity -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.normalizedDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedSimilarityTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests import io.kotest.core.spec.style.FunSpec class RatcliffObershelpTest : FunSpec({ @@ -48,5 +52,5 @@ class RatcliffObershelpTest : FunSpec({ ) include(precomputedSimilarityTests(precomputed, ratcliffObershelp)) - include(precomputedDistanceTests(precomputed.map { it.copy(similarity = 1 - it.similarity) }, ratcliffObershelp)) + include(precomputedDistanceTests(precomputed.map { it.copy(result = 1 - it.result) }, ratcliffObershelp)) }) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/Sift4Test.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/Sift4Test.kt index 5644d2f..f19d92e 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/Sift4Test.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/Sift4Test.kt @@ -27,8 +27,10 @@ */ package ca.solostudios.stringsimilarity +import ca.solostudios.fuzzykt.utils.FuzzyTestData import ca.solostudios.stringsimilarity.annotations.ExperimentalStringMeasure -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.distanceTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests import io.kotest.core.spec.style.FunSpec @OptIn(ExperimentalStringMeasure::class) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/SorensenDiceTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/SorensenDiceTest.kt index 66fcc42..39b7a5b 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/SorensenDiceTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/SorensenDiceTest.kt @@ -27,7 +27,11 @@ */ package ca.solostudios.stringsimilarity -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.normalizedDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedSimilarityTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests import io.kotest.core.spec.style.FunSpec class SorensenDiceTest : FunSpec({ @@ -53,5 +57,5 @@ class SorensenDiceTest : FunSpec({ ) include(precomputedSimilarityTests(precomputed, sorensenDice)) - include(precomputedDistanceTests(precomputed.map { it.copy(similarity = 1 - it.similarity) }, sorensenDice)) + include(precomputedDistanceTests(precomputed.map { it.copy(result = 1 - it.result) }, sorensenDice)) }) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/DamerauLevenshteinTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/DamerauLevenshteinTest.kt index 0a9b643..938503c 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/DamerauLevenshteinTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/DamerauLevenshteinTest.kt @@ -27,11 +27,11 @@ */ package ca.solostudios.stringsimilarity.edit -import ca.solostudios.stringsimilarity.metricDistanceTests -import ca.solostudios.stringsimilarity.precomputedDistanceTests -import ca.solostudios.stringsimilarity.precomputedSimilarityTests -import ca.solostudios.stringsimilarity.similarityTests -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.metricDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests +import ca.solostudios.stringsimilarity.factories.similarityTests import io.kotest.core.spec.style.FunSpec class DamerauLevenshteinTest : FunSpec({ @@ -56,7 +56,7 @@ class DamerauLevenshteinTest : FunSpec({ include(precomputedDistanceTests(precomputed, damerauLevenshtein)) include( precomputedSimilarityTests( - precomputed.map { it.copy(similarity = ((it.first.length + it.second.length) - it.similarity) / 2) }, + precomputed.map { it.copy(result = ((it.first.length + it.second.length) - it.result) / 2) }, damerauLevenshtein ) ) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/LCSTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/LCSTest.kt index 86db766..983184f 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/LCSTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/LCSTest.kt @@ -27,11 +27,11 @@ */ package ca.solostudios.stringsimilarity.edit -import ca.solostudios.stringsimilarity.metricDistanceTests -import ca.solostudios.stringsimilarity.precomputedDistanceTests -import ca.solostudios.stringsimilarity.precomputedSimilarityTests -import ca.solostudios.stringsimilarity.similarityTests -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.metricDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests +import ca.solostudios.stringsimilarity.factories.similarityTests import io.kotest.core.spec.style.FunSpec class LCSTest : FunSpec({ @@ -59,7 +59,7 @@ class LCSTest : FunSpec({ include(precomputedDistanceTests(precomputed, lcs)) include( precomputedSimilarityTests( - precomputed.map { it.copy(similarity = ((it.first.length + it.second.length) - it.similarity) / 2) }, + precomputed.map { it.copy(result = ((it.first.length + it.second.length) - it.result) / 2) }, lcs ) ) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/LevenshteinTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/LevenshteinTest.kt index 51e9d97..ec9e2c1 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/LevenshteinTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/LevenshteinTest.kt @@ -27,11 +27,11 @@ */ package ca.solostudios.stringsimilarity.edit -import ca.solostudios.stringsimilarity.metricDistanceTests -import ca.solostudios.stringsimilarity.precomputedDistanceTests -import ca.solostudios.stringsimilarity.precomputedSimilarityTests -import ca.solostudios.stringsimilarity.similarityTests -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.metricDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests +import ca.solostudios.stringsimilarity.factories.similarityTests import io.kotest.core.spec.style.FunSpec class LevenshteinTest : FunSpec({ @@ -55,7 +55,7 @@ class LevenshteinTest : FunSpec({ include(precomputedDistanceTests(precomputed, levenshtein)) include( precomputedSimilarityTests( - precomputed.map { it.copy(similarity = ((it.first.length + it.second.length) - it.similarity) / 2) }, + precomputed.map { it.copy(result = ((it.first.length + it.second.length) - it.result) / 2) }, levenshtein ) ) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedDamerauLevenshteinTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedDamerauLevenshteinTest.kt index 1af852a..b5d20e0 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedDamerauLevenshteinTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedDamerauLevenshteinTest.kt @@ -27,12 +27,12 @@ */ package ca.solostudios.stringsimilarity.edit -import ca.solostudios.stringsimilarity.metricDistanceTests -import ca.solostudios.stringsimilarity.normalizedDistanceTests -import ca.solostudios.stringsimilarity.normalizedSimilarityTests -import ca.solostudios.stringsimilarity.precomputedDistanceTests -import ca.solostudios.stringsimilarity.precomputedSimilarityTests -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.metricDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedSimilarityTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests import io.kotest.core.spec.style.FunSpec class NormalizedDamerauLevenshteinTest : FunSpec({ @@ -61,7 +61,7 @@ class NormalizedDamerauLevenshteinTest : FunSpec({ include(precomputedDistanceTests(precomputed, normalizedDamerauLevenshtein)) include( precomputedSimilarityTests( - precomputed.map { it.copy(similarity = 1 - it.similarity) }, + precomputed.map { it.copy(result = 1 - it.result) }, normalizedDamerauLevenshtein ) ) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedLCSTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedLCSTest.kt index 737570c..79ff907 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedLCSTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedLCSTest.kt @@ -28,12 +28,12 @@ package ca.solostudios.stringsimilarity.edit -import ca.solostudios.stringsimilarity.metricDistanceTests -import ca.solostudios.stringsimilarity.normalizedDistanceTests -import ca.solostudios.stringsimilarity.normalizedSimilarityTests -import ca.solostudios.stringsimilarity.precomputedDistanceTests -import ca.solostudios.stringsimilarity.precomputedSimilarityTests -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.metricDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedSimilarityTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests import io.kotest.core.spec.style.FunSpec class NormalizedLCSTest : FunSpec({ @@ -60,5 +60,5 @@ class NormalizedLCSTest : FunSpec({ ) include(precomputedDistanceTests(precomputed, normalizedLCS)) - include(precomputedSimilarityTests(precomputed.map { it.copy(similarity = 1 - it.similarity) }, normalizedLCS)) + include(precomputedSimilarityTests(precomputed.map { it.copy(result = 1 - it.result) }, normalizedLCS)) }) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedLevenshteinTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedLevenshteinTest.kt index 970fa46..fe45dae 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedLevenshteinTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedLevenshteinTest.kt @@ -28,12 +28,12 @@ package ca.solostudios.stringsimilarity.edit -import ca.solostudios.stringsimilarity.metricDistanceTests -import ca.solostudios.stringsimilarity.normalizedDistanceTests -import ca.solostudios.stringsimilarity.normalizedSimilarityTests -import ca.solostudios.stringsimilarity.precomputedDistanceTests -import ca.solostudios.stringsimilarity.precomputedSimilarityTests -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.metricDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedSimilarityTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests import io.kotest.core.spec.style.FunSpec class NormalizedLevenshteinTest : FunSpec({ @@ -60,5 +60,5 @@ class NormalizedLevenshteinTest : FunSpec({ ) include(precomputedDistanceTests(precomputed, normalizedLevenshtein)) - include(precomputedSimilarityTests(precomputed.map { it.copy(similarity = 1 - it.similarity) }, normalizedLevenshtein)) + include(precomputedSimilarityTests(precomputed.map { it.copy(result = 1 - it.result) }, normalizedLevenshtein)) }) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedOptimalStringAlignmentTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedOptimalStringAlignmentTest.kt index 76a28a9..174a6e9 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedOptimalStringAlignmentTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/NormalizedOptimalStringAlignmentTest.kt @@ -27,12 +27,12 @@ */ package ca.solostudios.stringsimilarity.edit -import ca.solostudios.stringsimilarity.metricDistanceTests -import ca.solostudios.stringsimilarity.normalizedDistanceTests -import ca.solostudios.stringsimilarity.normalizedSimilarityTests -import ca.solostudios.stringsimilarity.precomputedDistanceTests -import ca.solostudios.stringsimilarity.precomputedSimilarityTests -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.metricDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedDistanceTests +import ca.solostudios.stringsimilarity.factories.normalizedSimilarityTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests import io.kotest.core.spec.style.FunSpec class NormalizedOptimalStringAlignmentTest : FunSpec({ @@ -61,7 +61,7 @@ class NormalizedOptimalStringAlignmentTest : FunSpec({ include(precomputedDistanceTests(precomputed, normalizedOptimalStringAlignment)) include( precomputedSimilarityTests( - precomputed.map { it.copy(similarity = 1 - it.similarity) }, + precomputed.map { it.copy(result = 1 - it.result) }, normalizedOptimalStringAlignment ) ) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/OptimalStringAlignmentTest.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/OptimalStringAlignmentTest.kt index 9535162..69b4443 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/OptimalStringAlignmentTest.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/edit/OptimalStringAlignmentTest.kt @@ -27,11 +27,11 @@ */ package ca.solostudios.stringsimilarity.edit -import ca.solostudios.stringsimilarity.metricDistanceTests -import ca.solostudios.stringsimilarity.precomputedDistanceTests -import ca.solostudios.stringsimilarity.precomputedSimilarityTests -import ca.solostudios.stringsimilarity.similarityTests -import ca.solostudios.stringsimilarity.utils.FuzzyTestData +import ca.solostudios.fuzzykt.utils.FuzzyTestData +import ca.solostudios.stringsimilarity.factories.metricDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedDistanceTests +import ca.solostudios.stringsimilarity.factories.precomputedSimilarityTests +import ca.solostudios.stringsimilarity.factories.similarityTests import io.kotest.core.spec.style.FunSpec class OptimalStringAlignmentTest : FunSpec({ @@ -58,7 +58,7 @@ class OptimalStringAlignmentTest : FunSpec({ include(precomputedDistanceTests(precomputed, optimalStringAlignment)) include( precomputedSimilarityTests( - precomputed.map { it.copy(similarity = ((it.first.length + it.second.length) - it.similarity) / 2) }, + precomputed.map { it.copy(result = ((it.first.length + it.second.length) - it.result) / 2) }, optimalStringAlignment ) ) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/MetricTests.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/MetricTests.kt similarity index 95% rename from kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/MetricTests.kt rename to kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/MetricTests.kt index 94642df..eaa4143 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/MetricTests.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/MetricTests.kt @@ -3,7 +3,7 @@ * Copyright (c) 2023-2023 solonovamax * * The file MetricTests.kt is part of kotlin-fuzzy - * Last modified on 01-09-2023 11:07 p.m. + * Last modified on 29-09-2023 08:00 p.m. * * MIT License * @@ -26,10 +26,10 @@ * SOFTWARE. */ -package ca.solostudios.stringsimilarity +package ca.solostudios.stringsimilarity.factories import ca.solostudios.stringsimilarity.interfaces.MetricStringDistance -import ca.solostudios.stringsimilarity.utils.DEFAULT_TOLERANCE +import ca.solostudios.fuzzykt.utils.DEFAULT_TOLERANCE import io.kotest.assertions.withClue import io.kotest.core.spec.style.funSpec import io.kotest.matchers.doubles.plusOrMinus diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/NormalizedTests.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/NormalizedTests.kt similarity index 96% rename from kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/NormalizedTests.kt rename to kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/NormalizedTests.kt index 86faa9a..957a45e 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/NormalizedTests.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/NormalizedTests.kt @@ -3,7 +3,7 @@ * Copyright (c) 2023-2023 solonovamax * * The file NormalizedTests.kt is part of kotlin-fuzzy - * Last modified on 02-08-2023 06:33 p.m. + * Last modified on 29-09-2023 08:00 p.m. * * MIT License * @@ -26,7 +26,7 @@ * SOFTWARE. */ -package ca.solostudios.stringsimilarity +package ca.solostudios.stringsimilarity.factories import ca.solostudios.stringsimilarity.interfaces.NormalizedStringDistance import ca.solostudios.stringsimilarity.interfaces.NormalizedStringSimilarity diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/Precomputed.kt similarity index 72% rename from kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.kt rename to kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/Precomputed.kt index 7fd870a..dd10253 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/PreComputed.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/Precomputed.kt @@ -2,8 +2,8 @@ * kt-fuzzy - A Kotlin library for fuzzy string matching * Copyright (c) 2023-2023 solonovamax * - * The file PreComputed.kt is part of kotlin-fuzzy - * Last modified on 17-07-2023 06:18 p.m. + * The file Precomputed.kt is part of kotlin-fuzzy + * Last modified on 29-09-2023 08:01 p.m. * * MIT License * @@ -26,13 +26,13 @@ * SOFTWARE. */ -package ca.solostudios.stringsimilarity +package ca.solostudios.stringsimilarity.factories +import ca.solostudios.fuzzykt.testPrecomputed +import ca.solostudios.fuzzykt.utils.FuzzyTestData import ca.solostudios.stringsimilarity.interfaces.StringDistance import ca.solostudios.stringsimilarity.interfaces.StringSimilarity -import ca.solostudios.stringsimilarity.utils.FuzzyTestData import io.kotest.core.spec.style.funSpec -import io.kotest.core.spec.style.scopes.FunSpecRootScope fun precomputedSimilarityTests(precomputed: List, similarity: StringSimilarity) = funSpec { testPrecomputed("Similarity should match all pre-computed similarities", precomputed) { s1, s2 -> similarity.similarity(s1, s2) } @@ -41,18 +41,3 @@ fun precomputedSimilarityTests(precomputed: List, similarity: Str fun precomputedDistanceTests(precomputed: List, distance: StringDistance) = funSpec { testPrecomputed("Distance should match all pre-computed distances", precomputed) { s1, s2 -> distance.distance(s1, s2) } } - -/** - * Tests a precomputed value with a context. - * - * This has to be platform-specific because js hates nested tests, so on js it does a hack to not be nested. - * - * @param context The context name - * @param precomputed The precomputed data - * @param similarityFunction The similarity function - */ -expect fun FunSpecRootScope.testPrecomputed( - context: String, - precomputed: List, - similarityFunction: (String, String) -> Double, -) diff --git a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/StandardTests.kt b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/StandardTests.kt similarity index 98% rename from kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/StandardTests.kt rename to kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/StandardTests.kt index 957e78d..bd2be70 100644 --- a/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/StandardTests.kt +++ b/kt-string-similarity/src/commonTest/kotlin/ca/solostudios/stringsimilarity/factories/StandardTests.kt @@ -26,7 +26,7 @@ * SOFTWARE. */ -package ca.solostudios.stringsimilarity +package ca.solostudios.stringsimilarity.factories import ca.solostudios.stringsimilarity.interfaces.StringDistance import ca.solostudios.stringsimilarity.interfaces.StringSimilarity diff --git a/settings.gradle.kts b/settings.gradle.kts index aa42b15..cbbd3dc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -30,5 +30,6 @@ rootProject.name = "kotlin-fuzzy" include("kt-string-similarity") include("kt-fuzzy") +include("common-test") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")