2022-05-27 13:04:54 +00:00
|
|
|
/* eslint-disable jest/no-conditional-expect */
|
2022-06-06 17:38:20 +00:00
|
|
|
import Generator from 'src/lib/key-generators/phonetic'
|
2022-05-27 13:04:54 +00:00
|
|
|
|
2022-06-08 09:26:32 +00:00
|
|
|
const vowels = 'aeiou'
|
|
|
|
const consonants = 'bcdfghjklmnpqrstvwxyz'
|
2022-05-27 13:04:54 +00:00
|
|
|
|
|
|
|
describe('PhoneticKeyGenerator', () => {
|
|
|
|
describe('generation', () => {
|
|
|
|
it('should return a key of the proper length', () => {
|
2022-06-08 09:26:32 +00:00
|
|
|
const gen = new Generator({ type: 'phonetic' })
|
|
|
|
expect(gen.createKey(6).length).toEqual(6)
|
|
|
|
})
|
2022-05-27 13:04:54 +00:00
|
|
|
|
|
|
|
it('should alternate consonants and vowels', () => {
|
2022-06-08 09:26:32 +00:00
|
|
|
const gen = new Generator({ type: 'phonetic' })
|
|
|
|
const key = gen.createKey(3)
|
2022-05-27 13:04:54 +00:00
|
|
|
// if it starts with a consonant, we expect cvc
|
|
|
|
// if it starts with a vowel, we expect vcv
|
2022-06-08 09:26:32 +00:00
|
|
|
if (consonants.includes(key[0])) {
|
2022-05-27 13:04:54 +00:00
|
|
|
expect(consonants.includes(key[0])).toBeTruthy()
|
|
|
|
expect(consonants.includes(key[2])).toBeTruthy()
|
|
|
|
expect(vowels.includes(key[1])).toBeTruthy()
|
|
|
|
} else {
|
|
|
|
expect(vowels.includes(key[0])).toBeTruthy()
|
|
|
|
expect(vowels.includes(key[2])).toBeTruthy()
|
|
|
|
expect(consonants.includes(key[1])).toBeTruthy()
|
|
|
|
}
|
2022-06-08 09:26:32 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|