11import { afterEach , beforeEach , describe , expect , test , vi } from 'vitest'
22import { getUUID } from '../ids'
3- import {
4- isFuzzyMatch ,
5- levenshteinDistance ,
6- normalizeString ,
7- } from '../searchAlgorithm'
83
94describe ( 'ids' , ( ) => {
105 describe ( 'getUUID' , ( ) => {
@@ -25,55 +20,3 @@ describe('ids', () => {
2520 } )
2621 } )
2722} )
28-
29- describe ( 'fuzzySearch' , ( ) => {
30- describe ( 'normalizeString' , ( ) => {
31- test ( 'returns correct string' , ( ) => {
32- expect ( normalizeString ( 'île-de-France' ) ) . toBe ( 'ile de france' )
33- } )
34- } )
35-
36- describe ( 'levenshteinDistance' , ( ) => {
37- test ( 'returns correct lenvenshtein distance' , ( ) => {
38- expect ( levenshteinDistance ( 'test' , 'test' ) ) . toBe ( 0 )
39-
40- expect ( levenshteinDistance ( 'tests' , 'test' ) ) . toBe ( 1 )
41- expect ( levenshteinDistance ( 'test' , 'tests' ) ) . toBe ( 1 )
42-
43- expect ( levenshteinDistance ( 'tset' , 'test' ) ) . toBe ( 2 )
44-
45- expect ( levenshteinDistance ( 'hello' , 'test' ) ) . toBe ( 4 )
46-
47- expect ( levenshteinDistance ( '' , 'test' ) ) . toBe ( 4 )
48- expect ( levenshteinDistance ( 'test' , '0' ) ) . toBe ( 4 )
49- } )
50- } )
51- describe ( 'fuzzySearch' , ( ) => {
52- test ( 'with default distance (1)' , ( ) => {
53- expect ( isFuzzyMatch ( 'test' , 'test' ) ) . toBeTruthy ( )
54- expect ( isFuzzyMatch ( 'tests' , 'test' ) ) . toBeFalsy ( )
55- expect ( isFuzzyMatch ( 'test' , 'tests' ) ) . toBeTruthy ( )
56- expect ( isFuzzyMatch ( 'tset' , 'test' ) ) . toBeFalsy ( )
57- expect ( isFuzzyMatch ( 'hello' , 'test' ) ) . toBeFalsy ( )
58- expect ( isFuzzyMatch ( '' , 'test' ) ) . toBeTruthy ( )
59- } )
60-
61- test ( 'with distance = 0 (exact match)' , ( ) => {
62- expect ( isFuzzyMatch ( 'test' , 'test' , 0 ) ) . toBeTruthy ( )
63- expect ( isFuzzyMatch ( 'tests' , 'test' , 0 ) ) . toBeFalsy ( )
64- expect ( isFuzzyMatch ( 'test' , 'tests' , 0 ) ) . toBeTruthy ( )
65- expect ( isFuzzyMatch ( 'tset' , 'test' , 0 ) ) . toBeFalsy ( )
66- expect ( isFuzzyMatch ( 'hello' , 'test' , 0 ) ) . toBeFalsy ( )
67- expect ( isFuzzyMatch ( '' , 'test' ) ) . toBeTruthy ( )
68- } )
69-
70- test ( 'with distance = 2 (swap tolerant)' , ( ) => {
71- expect ( isFuzzyMatch ( 'test' , 'test' , 2 ) ) . toBeTruthy ( )
72- expect ( isFuzzyMatch ( 'tests' , 'test' , 2 ) ) . toBeFalsy ( )
73- expect ( isFuzzyMatch ( 'test' , 'tests' , 2 ) ) . toBeTruthy ( )
74- expect ( isFuzzyMatch ( 'tset' , 'test' , 2 ) ) . toBeTruthy ( )
75- expect ( isFuzzyMatch ( 'hello' , 'test' , 2 ) ) . toBeFalsy ( )
76- expect ( isFuzzyMatch ( '' , 'test' ) ) . toBeTruthy ( )
77- } )
78- } )
79- } )
0 commit comments