package main import ( "testing" "github.com/lithammer/fuzzysearch/fuzzy" "naviwatcher/internal/scanner" ) // TestFuzzySmoke verifies the fuzzysearch dependency and the Levenshtein-based // similarity primitive that the scanner engine actually uses (scanner.Similarity // delegates to fuzzy.LevenshteinDistance). This guards against the library // changing the distance semantics the engine relies on. func TestFuzzySmoke(t *testing.T) { // Identical strings: zero edit distance. if d := fuzzy.LevenshteinDistance("the wall", "the wall"); d != 0 { t.Errorf("expected LevenshteinDistance of identical strings to be 0, got %d", d) } // A small edit (remaster suffix) is closer than a wholly different title. near := fuzzy.LevenshteinDistance("the wall", "the wall remastered") far := fuzzy.LevenshteinDistance("the wall", "completely different album") if near >= far { t.Errorf("expected near match distance (%d) < far match distance (%d)", near, far) } // The scanner's similarity score should report the near match as more // similar than the far one, and the identical pair as a perfect match. if s := scanner.Similarity("the wall", "the wall"); s != 1.0 { t.Errorf("expected Similarity of identical strings to be 1.0, got %f", s) } if scanner.Similarity("the wall", "the wall remastered") <= scanner.Similarity("the wall", "completely different album") { t.Error("expected near match to score higher than far match") } }