-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathSuffixAutomaton.test.js
More file actions
24 lines (20 loc) · 822 Bytes
/
SuffixAutomaton.test.js
File metadata and controls
24 lines (20 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { countDistinctSubstrings, longestCommonSubstring } from '../SuffixAutomaton'
describe('Suffix Automaton - distinct substrings', () => {
it('handles empty string', () => {
expect(countDistinctSubstrings('')).toBe(0)
})
it('counts distinct substrings correctly', () => {
expect(countDistinctSubstrings('aaa')).toBe(3)
expect(countDistinctSubstrings('abc')).toBe(6)
expect(countDistinctSubstrings('ababa')).toBe(9)
})
})
describe('Suffix Automaton - longest common substring', () => {
it('finds LCS of two strings', () => {
expect(longestCommonSubstring('xabcdxyz', 'xyzabcd')).toBe('abcd')
expect(longestCommonSubstring('hello', 'yellow')).toBe('ello')
})
it('returns empty when no common substring', () => {
expect(longestCommonSubstring('abc', 'def')).toBe('')
})
})