Skip to content

Commit

Permalink
Moving similarity feature to kotest-assertions-core (#4006)
Browse files Browse the repository at this point in the history
I believe it was accidentally misplaced in kotest-assertions-shared,
which should only contain assertion stuff required by both
kotest-assertions and kotest-framework.

<!-- 
If this PR updates documentation, please update all relevant versions of
the docs, see:
https://github.com/kotest/kotest/tree/master/documentation/versioned_docs
The documentation at
https://github.com/kotest/kotest/tree/master/documentation/docs is the
documentation for the next minor or major version _TO BE RELEASED_
-->
  • Loading branch information
Kantis committed May 9, 2024
1 parent f9b587c commit 237d7f6
Show file tree
Hide file tree
Showing 26 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2519,3 +2519,11 @@ public final class io/kotest/matchers/url/MatchersKt {
public static final fun shouldNotHaveRef (Ljava/net/URL;Ljava/lang/String;)V
}

public final class io/kotest/similarity/PossibleMatchesForSetKt {
public static final fun possibleMatchesForSet (ZLjava/util/Set;Ljava/util/Set;Lio/kotest/equals/Equality;)Ljava/lang/String;
}

public final class io/kotest/similarity/PossibleMatchesKt {
public static final fun possibleMatchesDescription (Ljava/util/Set;Ljava/lang/Object;)Ljava/lang/String;
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ internal fun<T> closestMatches(expected: Set<T>, actual: T): List<PairComparison
return expected.asSequence().mapNotNull { candidate ->
val comparisonResult = VanillaDistanceCalculator.compare("", candidate, actual)
if (comparisonResult is MismatchByField &&
comparisonResult.distance.distance > Distance.COMPLETE_MISMATCH_VALUE) {
comparisonResult.distance.distance > Distance.COMPLETE_MISMATCH_VALUE
) {
PairComparison(actual, candidate, comparisonResult)
} else null
}.topWithTiesBy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ internal data class AtomicMismatch(
}

internal data class MismatchByField(
val field: String,
val expected: Any,
val actual: Any,
val comparisonResults: List<ComparisonResult>,
val distance: Distance
val field: String,
val expected: Any,
val actual: Any,
val comparisonResults: List<ComparisonResult>,
val distance: Distance
): ComparisonResult {
override fun description() = """$field expected: $expected,
| but was: $actual,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal fun matchByFields(field: String, expected: Any, actual: Any): Compariso
val comparisons = expectedFields.mapIndexed{
index, expectedField ->
val actualField = actualFields[index]
VanillaDistanceCalculator.compare(expectedField.name, expectedField.value, actualField.value)
VanillaDistanceCalculator.compare(expectedField.name, expectedField.value, actualField.value)
}
val matches = comparisons.count { it is Match }
val distance = Distance(BigDecimal(matches)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ internal data class IndexedElement(
)

internal data class PossibleMatch(
val matchInExpected: IndexedElement,
val actual: IndexedElement,
val comparisonResult: ComparisonResult
val matchInExpected: IndexedElement,
val actual: IndexedElement,
val comparisonResult: ComparisonResult
)

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MatchByFieldsTest: StringSpec() {
expected = redCircle,
actual = blueCircle,
comparisonResults = listOf(
AtomicMismatch(field="color", expected="red", actual="blue", distance=Distance(BigDecimal.ZERO)),
AtomicMismatch(field="color", expected="red", actual="blue", distance= Distance(BigDecimal.ZERO)),
Match(field="shape", value="circle")
),
distance = Distance(BigDecimal("0.5"))
Expand All @@ -36,16 +36,17 @@ class MatchByFieldsTest: StringSpec() {
field="color",
expected="red",
actual="blue",
distance=Distance(BigDecimal.ZERO)
distance= Distance(BigDecimal.ZERO)
),
AtomicMismatch(
field="shape",
expected="circle",
actual="triangle",
distance=Distance(BigDecimal.ZERO)
distance= Distance(BigDecimal.ZERO)
),
),
distance = Distance(BigDecimal.ZERO))
distance = Distance(BigDecimal.ZERO)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3063,11 +3063,3 @@ public final class io/kotest/matchers/ShouldKt {
public static final fun shouldNotHave (Ljava/lang/Object;Lio/kotest/matchers/Matcher;)V
}

public final class io/kotest/similarity/PossibleMatchesForSetKt {
public static final fun possibleMatchesForSet (ZLjava/util/Set;Ljava/util/Set;Lio/kotest/equals/Equality;)Ljava/lang/String;
}

public final class io/kotest/similarity/PossibleMatchesKt {
public static final fun possibleMatchesDescription (Ljava/util/Set;Ljava/lang/Object;)Ljava/lang/String;
}

0 comments on commit 237d7f6

Please sign in to comment.