Skip to content

Commit 5d31147

Browse files
feat(test): Add unit tests for FuzzyFinder
This commit introduces a new test file, `FuzzyFinderTest.kt`, to validate the string scoring logic of the `FuzzyFinder` utility. Two main test cases have been added: - `testAllFuzzyScenarios`: This test covers a range of matching scenarios, including exact, partial, consecutive, scattered, and acronym matches. It also tests handling of special characters and spacing. - `testComparativeHeuristics`: This test specifically verifies that a consecutive character match (e.g., "app" in "application") scores higher than a scattered match (e.g., "app" in "a_p_p_lication"), ensuring the scoring heuristic behaves as expected.
1 parent 56a076b commit 5d31147

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.github.codeworkscreativehub.fuzzywuzzy
2+
3+
import org.junit.Assert.assertTrue
4+
import org.junit.Test
5+
6+
class FuzzyFinderTest {
7+
8+
@Test
9+
fun testAllFuzzyScenarios() {
10+
// Define your arguments here: Target, Query, and an optional Label for the printout
11+
val testData = listOf(
12+
Triple("Hello", "Hello", "Exact Match"),
13+
Triple("Hello", "xyz", "No Match"),
14+
Triple("Hello World", "Hello", "Partial Match"),
15+
Triple("application", "app", "Consecutive"),
16+
Triple("a_p_p_lication", "app", "Scattered"),
17+
Triple("Settings", "Set", "Prefix/Boundary"),
18+
Triple("Assets", "Set", "Infix"),
19+
Triple("mLauncher", "mL", "Acronym"),
20+
Triple("App Name", "App Name", "Ignore Spaces"),
21+
Triple("App-Name", "App Name", "Ignore Dash in Target")
22+
)
23+
24+
println(String.format("\n%-20s | %-15s | %-10s | %s", "TEST CASE", "TARGET", "QUERY", "SCORE"))
25+
println("-".repeat(65))
26+
27+
for ((target, query, label) in testData) {
28+
val score = FuzzyFinder.scoreString(target, query, 1000)
29+
val normalizedScore = score / 1000.0f
30+
31+
// Print the result for every pair in the list
32+
println(String.format("%-20s | %-15s | %-10s | %.4f", label, target, query, normalizedScore))
33+
34+
// Basic validation
35+
assertTrue("Score for $label should be >= 0", normalizedScore >= 0f)
36+
}
37+
}
38+
39+
@Test
40+
fun testComparativeHeuristics() {
41+
// Keep these specific tests to ensure your logic rules stay intact
42+
val scoreConsecutive = FuzzyFinder.calculateFuzzyScore("application", "app")
43+
val scoreScattered = FuzzyFinder.calculateFuzzyScore("a_p_p_lication", "app")
44+
45+
println("\nComparison Test: $scoreConsecutive (Consecutive) vs $scoreScattered (Scattered)")
46+
assertTrue("Consecutive match should score higher", scoreConsecutive > scoreScattered)
47+
}
48+
}

0 commit comments

Comments
 (0)