-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
Copy pathWordBreak.test.js
34 lines (30 loc) · 1.02 KB
/
WordBreak.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { describe, it, expect } from 'vitest'
import { WordBreakSolution } from '../WordBreak'
describe('Word Break Algorithm', () => {
it('should return true for valid word segmentation', () => {
const solution = new WordBreakSolution()
const result = solution.wordBreak('leetcode', ['leet', 'code'])
expect(result).toBe(true)
})
it('should return false for invalid word segmentation', () => {
const solution = new WordBreakSolution()
const result = solution.wordBreak('applepenapple', ['apple', 'pen'])
expect(result).toBe(true)
})
it('should handle edge cases with empty strings', () => {
const solution = new WordBreakSolution()
const result = solution.wordBreak('', ['leet', 'code'])
expect(result).toBe(true)
})
it('should return false when no word break is possible', () => {
const solution = new WordBreakSolution()
const result = solution.wordBreak('catsandog', [
'cats',
'dog',
'sand',
'and',
'cat'
])
expect(result).toBe(false)
})
})