Add new test cases for KMP algorithm.

This commit is contained in:
Oleksii Trekhleb 2018-07-23 18:00:54 +03:00
parent 76c172b20b
commit 6a3a4b8697

View File

@ -2,6 +2,9 @@ import knuthMorrisPratt from '../knuthMorrisPratt';
describe('knuthMorrisPratt', () => { describe('knuthMorrisPratt', () => {
it('should find word position in given text', () => { it('should find word position in given text', () => {
expect(knuthMorrisPratt('', '')).toBe(-1);
expect(knuthMorrisPratt('a', '')).toBe(-1);
expect(knuthMorrisPratt('a', 'a')).toBe(0);
expect(knuthMorrisPratt('abcbcglx', 'abca')).toBe(-1); expect(knuthMorrisPratt('abcbcglx', 'abca')).toBe(-1);
expect(knuthMorrisPratt('abcbcglx', 'bcgl')).toBe(3); expect(knuthMorrisPratt('abcbcglx', 'bcgl')).toBe(3);
expect(knuthMorrisPratt('abcxabcdabxabcdabcdabcy', 'abcdabcy')).toBe(15); expect(knuthMorrisPratt('abcxabcdabxabcdabcdabcy', 'abcdabcy')).toBe(15);