UNPKG

@dxzmpk/js-algorithms-data-structures

Version:

Algorithms and data-structures implemented on JavaScript

30 lines (22 loc) 1.14 kB
import levenshteinDistance from '../levenshteinDistance'; describe('levenshteinDistance', () => { it('should calculate edit distance between two strings', () => { expect(levenshteinDistance('', '')).toBe(0); expect(levenshteinDistance('a', '')).toBe(1); expect(levenshteinDistance('', 'a')).toBe(1); expect(levenshteinDistance('abc', '')).toBe(3); expect(levenshteinDistance('', 'abc')).toBe(3); // Should just add I to the beginning. expect(levenshteinDistance('islander', 'slander')).toBe(1); // Needs to substitute M by K, T by M and add an A to the end expect(levenshteinDistance('mart', 'karma')).toBe(3); // Substitute K by S, E by I and insert G at the end. expect(levenshteinDistance('kitten', 'sitting')).toBe(3); // Should add 4 letters FOOT at the beginning. expect(levenshteinDistance('ball', 'football')).toBe(4); // Should delete 4 letters FOOT at the beginning. expect(levenshteinDistance('football', 'foot')).toBe(4); // Needs to substitute the first 5 chars: INTEN by EXECU expect(levenshteinDistance('intention', 'execution')).toBe(5); }); });