mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00

* Search: Rabin-Karp algorithm * Prettier Style * Search: Rabin-Karp adding reference * Search: Rabin-Karp styling and remove unecessary logging * Search: Rabin-Karp review notes * Simplify return * Updated Documentation in README.md --------- Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
31 lines
838 B
JavaScript
31 lines
838 B
JavaScript
import { rabinKarpSearch } from '../RabinKarp'
|
|
|
|
describe('Rabin-Karp Search', function () {
|
|
it('should find the pattern in the text', function () {
|
|
const text = 'ABABDABACDABABCABAB'
|
|
const pattern = 'DAB'
|
|
const expected = [4, 9]
|
|
|
|
const result = rabinKarpSearch(text, pattern)
|
|
expect(result).to.deep.equal(expected)
|
|
})
|
|
|
|
it('should handle multiple occurrences of the pattern', function () {
|
|
const text = 'ABABABABABAB'
|
|
const pattern = 'ABAB'
|
|
const expected = [2, 4, 6, 8]
|
|
|
|
const result = rabinKarpSearch(text, pattern)
|
|
expect(result).to.deep.equal(expected)
|
|
})
|
|
|
|
it('should handle pattern not found', function () {
|
|
const text = 'ABCD'
|
|
const pattern = 'XYZ'
|
|
const expected = []
|
|
|
|
const result = rabinKarpSearch(text, pattern)
|
|
expect(result).to.deep.equal(expected)
|
|
})
|
|
})
|