package main import ( "testing" "github.com/lithammer/fuzzysearch/fuzzy" ) // TestFuzzySmoke verifies the fuzzysearch dependency is importable and that // its ranking API behaves as the scanner engine will expect. // // Note: this library does NOT expose a `fuzzy.Ratio` (0-100) function as the // plan's Technical Details assumed. The relevant signal here is RankMatch, // which returns 0 for an exact match, a small positive distance for near // matches, and -1 when source is not a subsequence of target. Task 3 will // convert this into a normalized 0.0-1.0 similarity score. func TestFuzzySmoke(t *testing.T) { // Exact match scores 0 (distance). if got := fuzzy.RankMatch("the wall", "the wall"); got != 0 { t.Errorf("expected RankMatch of identical strings to be 0, got %d", got) } // Similar strings score closer to 0 than dissimilar ones, and a real // subsequence match returns a non-negative distance. similar := fuzzy.RankMatch("the wall", "the wall remastered") dissimilar := fuzzy.RankMatch("the wall", "completely different album") if similar < 0 { t.Errorf("expected similar to be a valid match (>=0), got %d", similar) } if dissimilar >= 0 { t.Errorf("expected dissimilar to be a non-match (-1), got %d", dissimilar) } if dissimilar != -1 { t.Errorf("expected dissimilar to be -1 (no subsequence match), got %d", dissimilar) } // A near match (valid, >=0) is preferable to a total miss (-1). if similar < 0 { t.Errorf("expected similar to be a valid match (>=0), got %d", similar) } if dissimilar != -1 { t.Errorf("expected dissimilar to be a non-match (-1), got %d", dissimilar) } }