-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
Copy pathAbbreviation.test.js
30 lines (27 loc) · 1.07 KB
/
Abbreviation.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
import { isAbbreviation } from '../Abbreviation.js'
const expectPositive = (word, abbr) =>
expect(isAbbreviation(word, abbr)).toBe(true)
const expectNegative = (word, abbr) =>
expect(isAbbreviation(word, abbr)).toBe(false)
describe('Abbreviation - Positive Tests', () => {
test('it should correctly abbreviate or transform the source string to match the target string', () => {
expectPositive('', '')
expectPositive('a', '')
expectPositive('a', 'A')
expectPositive('abcDE', 'ABCDE')
expectPositive('ABcDE', 'ABCDE')
expectPositive('abcde', 'ABCDE')
expectPositive('abcde', 'ABC')
expectPositive('abcXYdefghijKLmnopqrs', 'XYKL')
expectPositive('abc123', 'ABC')
expectPositive('abc123', 'ABC123')
expectPositive('abc!@#def', 'ABC')
})
})
describe('Abbreviation - Negative Tests', () => {
test('it should fail to abbreviate or transform the source string when it is not possible to match the target string', () => {
expectNegative('', 'A')
expectNegative('a', 'ABC')
expectNegative('aBcXYdefghijKLmnOpqrs', 'XYKLOP')
})
})