Abbreviation (#1547)

* Abbreviation

* Updates from code review
This commit is contained in:
Rob Simpson
2023-11-15 08:55:30 -05:00
committed by GitHub
parent e9e3ea4684
commit 39d01138ec
2 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,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')
})
})