|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var mod = require('../../src/others/levenshtein-distance.js'); |
| 4 | +var levenshteinDistance = mod.levenshteinDistance; |
| 5 | + |
| 6 | +describe('Levenstein\'s minimum edit distance algorithm', function () { |
| 7 | + it('should be defined', function () { |
| 8 | + expect(levenshteinDistance).toBeDefined(); |
| 9 | + }); |
| 10 | + |
| 11 | + it('"" -> "" should return 0.', function () { |
| 12 | + expect(levenshteinDistance('', '')).toBe(0); |
| 13 | + }); |
| 14 | + |
| 15 | + it('"T" -> "" should return 1.', function () { |
| 16 | + expect(levenshteinDistance('T', '')).toBe(1); |
| 17 | + }); |
| 18 | + |
| 19 | + it('"cake" -> "rake" should return 1.', function () { |
| 20 | + expect(levenshteinDistance('cake', 'rake')).toBe(1); |
| 21 | + }); |
| 22 | + |
| 23 | + it('"Sofia" -> "Sof" should return 2.', function () { |
| 24 | + expect(levenshteinDistance('Sofia', 'Sof')).toBe(2); |
| 25 | + }); |
| 26 | + |
| 27 | + it('"kitten" -> "sitting" should return 3', function () { |
| 28 | + expect(levenshteinDistance('kitten', 'sitting')).toBe(3); |
| 29 | + }); |
| 30 | + |
| 31 | + it('"google" -> "lookat" should return 4.', function () { |
| 32 | + expect(levenshteinDistance('google', 'lookat')).toBe(4); |
| 33 | + }); |
| 34 | + |
| 35 | + it('"emacs" -> "vim" should return 5.', function () { |
| 36 | + expect(levenshteinDistance('emacs', 'vim')).toBe(5); |
| 37 | + }); |
| 38 | + |
| 39 | + it('"coffee" -> "cocoa" should return 4.', function () { |
| 40 | + expect(levenshteinDistance('coffee', 'cocoa')).toBe(4); |
| 41 | + }); |
| 42 | + |
| 43 | + it('"Munich" -> "Muenchen" should return 4.', function () { |
| 44 | + expect(levenshteinDistance('Munich', 'Muenchen')).toBe(4); |
| 45 | + }); |
| 46 | + |
| 47 | + it('"rosebud" -> "budrose" should return 6.', function () { |
| 48 | + expect(levenshteinDistance('rosebud', 'budrose')).toBe(6); |
| 49 | + }); |
| 50 | + |
| 51 | + it('"decided" -> "decisive" should return 4.', function () { |
| 52 | + expect(levenshteinDistance('decided', 'decisive')).toBe(4); |
| 53 | + }); |
| 54 | + |
| 55 | + it('"similar" -> "simile" should return 2.', function () { |
| 56 | + expect(levenshteinDistance('similar', 'simile')).toBe(2); |
| 57 | + }); |
| 58 | +}); |
0 commit comments