|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +varlongestCommonSubsequence= |
| 4 | +require('../../src/searching/'+ |
| 5 | +'longest-common-subsequence') |
| 6 | +.longestCommonSubsequence; |
| 7 | + |
| 8 | +describe('longest common subsequence',function(){ |
| 9 | + |
| 10 | +it('should work with empty strings',function(){ |
| 11 | +expect(longestCommonSubsequence('','')).toBe(''); |
| 12 | +}); |
| 13 | + |
| 14 | +it('should work with first string empty',function(){ |
| 15 | +expect(longestCommonSubsequence('','abcd')).toBe(''); |
| 16 | +}); |
| 17 | + |
| 18 | +it('should work with second string empty',function(){ |
| 19 | +expect(longestCommonSubsequence('abcd','')).toBe(''); |
| 20 | +}); |
| 21 | + |
| 22 | +it('should work if there is no lcs',function(){ |
| 23 | +expect(longestCommonSubsequence('qtwer','zvxcv')).toBe(''); |
| 24 | +}); |
| 25 | + |
| 26 | +it('should work if lcs is whole first string',function(){ |
| 27 | +expect(longestCommonSubsequence('abc','abcdefghi')).toBe('abc'); |
| 28 | +}); |
| 29 | + |
| 30 | +it('should work if lcs is whole second string',function(){ |
| 31 | +expect(longestCommonSubsequence('qwerty','rty')).toBe('rty'); |
| 32 | +}); |
| 33 | + |
| 34 | +it('should work with repeated letter',function(){ |
| 35 | +expect(longestCommonSubsequence('AAATC','GGTAGGC')).toBe('AC'); |
| 36 | +}); |
| 37 | + |
| 38 | +it('should work with custom characters',function(){ |
| 39 | +expect(longestCommonSubsequence(':-)','B-)')).toBe('-)'); |
| 40 | +}); |
| 41 | + |
| 42 | +it('should work with long strings',function(){ |
| 43 | +expect(longestCommonSubsequence('this is the first string','that is second')).toBe('tht is sn'); |
| 44 | +}); |
| 45 | + |
| 46 | +it('should work with very long strings',function(){ |
| 47 | +expect(longestCommonSubsequence('giiiiiiit1huuuuuu2bbb','zzxxcvasdfgmntplpliiggggu2b222')).toBe('giiu2b'); |
| 48 | +}); |
| 49 | +}); |