1+ import { levenshteinDistance , getSimilarity } from "../utils"
2+
3+ describe ( "levenshteinDistance" , ( ) => {
4+ it ( "should return 0 for identical strings" , ( ) => {
5+ expect ( levenshteinDistance ( "hello" , "hello" ) ) . toBe ( 0 )
6+ } )
7+
8+ it ( "should handle single character differences" , ( ) => {
9+ expect ( levenshteinDistance ( "hello" , "hallo" ) ) . toBe ( 1 )
10+ } )
11+
12+ it ( "should handle insertions" , ( ) => {
13+ expect ( levenshteinDistance ( "hello" , "hello!" ) ) . toBe ( 1 )
14+ } )
15+
16+ it ( "should handle deletions" , ( ) => {
17+ expect ( levenshteinDistance ( "hello!" , "hello" ) ) . toBe ( 1 )
18+ } )
19+
20+ it ( "should handle completely different strings" , ( ) => {
21+ expect ( levenshteinDistance ( "hello" , "world" ) ) . toBe ( 4 )
22+ } )
23+
24+ it ( "should handle empty strings" , ( ) => {
25+ expect ( levenshteinDistance ( "" , "" ) ) . toBe ( 0 )
26+ expect ( levenshteinDistance ( "hello" , "" ) ) . toBe ( 5 )
27+ expect ( levenshteinDistance ( "" , "hello" ) ) . toBe ( 5 )
28+ } )
29+ } )
30+
31+ describe ( "getSimilarity" , ( ) => {
32+ it ( "should return 1 for identical strings" , ( ) => {
33+ expect ( getSimilarity ( "hello world" , "hello world" ) ) . toBe ( 1 )
34+ } )
35+
36+ it ( "should handle empty search string" , ( ) => {
37+ expect ( getSimilarity ( "hello world" , "" ) ) . toBe ( 1 )
38+ } )
39+
40+ it ( "should normalize whitespace" , ( ) => {
41+ expect ( getSimilarity ( "hello world" , "hello world" ) ) . toBe ( 1 )
42+ expect ( getSimilarity ( "hello\tworld" , "hello world" ) ) . toBe ( 1 )
43+ expect ( getSimilarity ( "hello\nworld" , "hello world" ) ) . toBe ( 1 )
44+ } )
45+
46+ it ( "should preserve case sensitivity" , ( ) => {
47+ expect ( getSimilarity ( "Hello World" , "hello world" ) ) . toBeLessThan ( 1 )
48+ } )
49+
50+ it ( "should handle partial matches" , ( ) => {
51+ const similarity = getSimilarity ( "hello world" , "hello there" )
52+ expect ( similarity ) . toBeGreaterThan ( 0 )
53+ expect ( similarity ) . toBeLessThan ( 1 )
54+ } )
55+
56+ it ( "should handle completely different strings" , ( ) => {
57+ const similarity = getSimilarity ( "hello world" , "goodbye universe" )
58+ expect ( similarity ) . toBeGreaterThan ( 0 )
59+ expect ( similarity ) . toBeLessThan ( 0.5 )
60+ } )
61+ } )
0 commit comments