Add KMP string searching algorithm

This commit is contained in:
Rahul Jain
2020-10-30 23:01:06 +05:30
parent 2190b92e1b
commit 2c5aaa3690
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,15 @@
import { KMPSearch } from '../KMPPatternSearching'
describe('KMP Matcher', () => {
it('TC1: expects to return matching indices for pattern in text', () => {
const text = 'ABC ABCDAB ABCDABCDABDE'
const pattern = 'ABCDABD'
expect(KMPSearch(text, pattern)).toStrictEqual([15])
})
it('TC2: expects to return matching indices for pattern in text', () => {
const text = 'ABC ABCDABD ABCDABCDABDE'
const pattern = 'ABCDABD'
expect(KMPSearch(text, pattern)).toStrictEqual([4, 16])
})
})