Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f839af2

Browse files
Add tests to longest common subsequence algorithm
1 parent c5486fc commit f839af2

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
var longestCommonSubsequence =
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+
});

0 commit comments

Comments
 (0)