tests: Levenshtein Distance (dynamic programming solution) (#1114)

This commit is contained in:
JCarlos
2022-10-05 14:08:23 -05:00
committed by GitHub
parent 9528c71107
commit ea7d06ad57
3 changed files with 28 additions and 5 deletions

View File

@ -0,0 +1,19 @@
import { calculateLevenshteinDp } from '../LevenshteinDistance'
test('Should return the distance counting additions and removals', () => {
const from = 'kitten'
const to = 'sitting'
expect(calculateLevenshteinDp(from, to)).toBe(3)
})
test('Should return the distance based on replacements in the middle of the strings', () => {
const from = 'book'
const to = 'back'
expect(calculateLevenshteinDp(from, to)).toBe(2)
})
test('Should return the distance for strings with different length', () => {
const from = 'sunday'
const to = 'saturday'
expect(calculateLevenshteinDp(from, to)).toBe(3)
})