2017-11-01 02:10:25 +01:00
|
|
|
/* global describe, it */
|
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
const Generator = require('../../lib/key_generators/phonetic');
|
|
|
|
|
|
|
|
const vowels = 'aeiou';
|
|
|
|
const consonants = 'bcdfghjklmnpqrstvwxyz';
|
|
|
|
|
2022-02-14 18:59:14 +01:00
|
|
|
describe('PhoneticKeyGenerator', () => {
|
|
|
|
describe('generation', () => {
|
2017-11-01 02:10:25 +01:00
|
|
|
it('should return a key of the proper length', () => {
|
|
|
|
const gen = new Generator();
|
|
|
|
assert.equal(6, gen.createKey(6).length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should alternate consonants and vowels', () => {
|
|
|
|
const gen = new Generator();
|
|
|
|
|
|
|
|
const key = gen.createKey(3);
|
|
|
|
|
2022-02-14 18:59:14 +01:00
|
|
|
// if it starts with a consonant, we expect cvc
|
|
|
|
// if it starts with a vowel, we expect vcv
|
|
|
|
if(consonants.includes(key[0])) {
|
|
|
|
assert.ok(consonants.includes(key[0]));
|
|
|
|
assert.ok(consonants.includes(key[2]));
|
|
|
|
assert.ok(vowels.includes(key[1]));
|
|
|
|
} else {
|
|
|
|
assert.ok(vowels.includes(key[0]));
|
|
|
|
assert.ok(vowels.includes(key[2]));
|
|
|
|
assert.ok(consonants.includes(key[1]));
|
|
|
|
}
|
2017-11-01 02:10:25 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|