From 8bb5d724617d2483f55bebf409bc7c7d7f633635 Mon Sep 17 00:00:00 2001 From: Sad Ellie Date: Thu, 8 Dec 2022 12:37:58 +0400 Subject: [PATCH] Fixed Levenshtein Distance function. Needed lowercase to pass tests of the function. In app strings are passed in lowercase. --- app/src/main/java/com/sadellie/unitto/screens/Utils.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/sadellie/unitto/screens/Utils.kt b/app/src/main/java/com/sadellie/unitto/screens/Utils.kt index e3782559..089822ee 100644 --- a/app/src/main/java/com/sadellie/unitto/screens/Utils.kt +++ b/app/src/main/java/com/sadellie/unitto/screens/Utils.kt @@ -171,18 +171,19 @@ fun openLink(mContext: Context, url: String) { } /** - * Compute Levenshtein Distance between this string and [stringB]. Doesn't matter which string is + * Compute Levenshtein Distance between this string and [secondString]. Doesn't matter which string is * first. * * @return The amount of changes that are needed to transform one string into another */ -fun String.lev(stringB: String): Int { - val stringA = this +fun String.lev(secondString: String): Int { + val stringA = this.lowercase() + val stringB = secondString.lowercase() // Skipping computation for this cases if (stringA == stringB) return 0 if (stringA.isEmpty()) return stringB.length - // This case is basically unreal in this app, because stringB is a unit name and they are never empty + // This case is basically unreal in this app, because secondString is a unit name and they are never empty if (stringB.isEmpty()) return stringA.length var cost = IntArray(stringA.length + 1) { it }