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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
import { findContinuousChar1, findContinuousChar2 } from '../continuous-char.ts'
describe('连续字符和长度 嵌套循环 跳步', () => { it('正常情况', () => { const str = 'Hello World' const res = findContinuousChar1(str) expect(res).toEqual({ char: 'l', length: 2, }) }) it('空字符串', () => { const res = findContinuousChar1('') expect(res).toEqual({ char: '', length: 0, }) }) it('无连续字符', () => { const str = 'world' const res = findContinuousChar1(str) expect(res).toEqual({ char: 'w', length: 1, }) }) it('全部都是连续字符', () => { const str = 'www' const res = findContinuousChar1(str) expect(res).toEqual({ char: 'w', length: 3, }) }) })
describe('连续字符和长度 双指针', () => { it('正常情况', () => { const str = 'Hello World' const res = findContinuousChar2(str) expect(res).toEqual({ char: 'l', length: 2, }) }) it('空字符串', () => { const res = findContinuousChar2('') expect(res).toEqual({ char: '', length: 0, }) }) it('无连续字符', () => { const str = 'world' const res = findContinuousChar2(str) expect(res).toEqual({ char: 'w', length: 1, }) }) it('全部都是连续字符', () => { const str = 'www' const res = findContinuousChar2(str) expect(res).toEqual({ char: 'w', length: 3, }) }) })
|