Skip to content

Commit

Permalink
Refactor test
Browse files Browse the repository at this point in the history
- 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
solonovamax committed Sep 30, 2023
1 parent 583bec2 commit 29747f6
Show file tree
Hide file tree
Showing 34 changed files with 327 additions and 211 deletions.
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/kt-fuzzy.testing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ kotlin {
val commonTest by getting {
dependencies {
implementation(libs.bundles.kotest)

implementation(project(":common-test"))
}
}

Expand Down
30 changes: 30 additions & 0 deletions common-test/build.gradle.kts
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)
}
}
}
}
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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
* SOFTWARE.
*/

package ca.solostudios.stringsimilarity.utils
package ca.solostudios.fuzzykt.utils

const val DEFAULT_TOLERANCE = 0.00001
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
Expand All @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
Expand All @@ -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
}
}
}
10 changes: 0 additions & 10 deletions kt-fuzzy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ description = """
A dependency-less Kotlin Multiplatform library for fuzzy string matching
""".trimIndent()

repositories {
mavenCentral()
}

kotlin {
sourceSets {
val commonMain by getting {
Expand All @@ -56,11 +52,5 @@ kotlin {
api(projects.ktStringSimilarity)
}
}

val commonTest by getting {
dependencies {
implementation(libs.kotlin.test) // temporary
}
}
}
}

This file was deleted.

Loading

0 comments on commit 29747f6

Please sign in to comment.