-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move common test elements into common-test - Migrate kt-fuzzy to use kotest instead of kotlin.test - Clean buildscripts slightly Signed-off-by: solonovamax <[email protected]>
- Loading branch information
1 parent
583bec2
commit 29747f6
Showing
34 changed files
with
327 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
common-test/src/commonMain/kotlin/ca/solostudios/fuzzykt/PreComputed.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* kt-fuzzy - A Kotlin library for fuzzy string matching | ||
* Copyright (c) 2023-2023 solonovamax <[email protected]> | ||
* | ||
* 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<FuzzyTestData>, | ||
resultFunction: (String, String) -> Double, | ||
) | ||
|
||
expect fun <T, U, V> FunSpecRootScope.testPrecomputed( | ||
context: String, | ||
precomputed: List<Triple<T, U, V>>, | ||
resultFunction: (T, U) -> V, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Copyright (c) 2023-2023 solonovamax <[email protected]> | ||
* | ||
* 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Copyright (c) 2023-2023 solonovamax <[email protected]> | ||
* | ||
* 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<FuzzyTestData>, | ||
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 <T, U, V> FunSpecRootScope.testPrecomputed( | ||
context: String, | ||
precomputed: List<Triple<T, U, V>>, | ||
resultFunction: (T, U) -> V, | ||
) { | ||
context(context) { | ||
precomputed.forEach { | ||
withClue({ getStableIdentifier(it) }) { | ||
resultFunction(it.first, it.second) shouldBe it.third | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Copyright (c) 2023-2023 solonovamax <[email protected]> | ||
* | ||
* 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<FuzzyTestData>, | ||
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 <T, U, V> FunSpecRootScope.testPrecomputed( | ||
context: String, | ||
precomputed: List<Triple<T, U, V>>, | ||
resultFunction: (T, U) -> V, | ||
) { | ||
context(context) { | ||
withData(precomputed) { | ||
resultFunction(it.first, it.second) shouldBe it.third | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Copyright (c) 2023-2023 solonovamax <[email protected]> | ||
* | ||
* 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<FuzzyTestData>, | ||
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 <T, U, V> FunSpecRootScope.testPrecomputed( | ||
context: String, | ||
precomputed: List<Triple<T, U, V>>, | ||
resultFunction: (T, U) -> V, | ||
) { | ||
context(context) { | ||
withData(precomputed) { | ||
resultFunction(it.first, it.second) shouldBe it.third | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 0 additions & 81 deletions
81
kt-fuzzy/src/commonTest/kotlin/ca.solostudios.fuzzykt/FuzzyKtTest.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.