-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
59 lines (51 loc) · 2.03 KB
/
index.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
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
import { expect } from 'chai';
import animalHash from '../src';
import compress from '../src/compress';
import adjectives from '../src/adjectives';
import colors from '../src/colors';
import animals from '../src/animals';
describe('animalHash', () => {
it('should turn arbitrary string input into an animal hash', () => {
const expectedVal = 'Rapid Grey Rattlesnake'
expect(animalHash('my ugly input string')).to.equal(expectedVal)
});
it('should use a specified separator', () => {
const expectedVal = 'Rapid-Grey-Rattlesnake'
expect(animalHash('my ugly input string', { separator: '-' })).to.equal(expectedVal)
});
it('should support lowercased style', () => {
const expectedVal = 'rapid grey rattlesnake'
expect(animalHash('my ugly input string', { style: 'lowercase' })).to.equal(expectedVal)
});
it('should support uppercased style', () => {
const expectedVal = 'RAPID GREY RATTLESNAKE'
expect(animalHash('my ugly input string', { style: 'uppercase' })).to.equal(expectedVal)
});
it('should throw an error if passed an unknown style', () => {
expect(() => animalHash('xyz', { style: 'garbage' })).to.throw(/Unknown style/);
});
});
describe('compress', () => {
it('compresses an md5 hash into an array of requested length integers', () => {
const bytes = [ 23, 45, 234, 111, 46, 165, 33, 58, 156, 140, 91, 138, 50, 245, 103, 210 ];
const compressed = [ 145, 174, 163 ];
expect(compress(bytes, 3)).to.eql(compressed);
});
it('should throw an error if given fewer bytes than requested output', () => {
expect(() => compress([ 23 ], 3)).to.throw(/Fewer input bytes/);
});
});
describe('wordlists', () => {
it('should contain no duplicate entries', () => {
const wordlist = adjectives.concat(colors).concat(animals);
const wordcount = wordlist.reduce((tally, word) => {
if(!tally[word]) {
tally[word] = 1;
} else {
tally[word] = tally[word] + 1;
}
return tally;
}, {});
expect(Object.keys(wordlist).length).to.equal(256 * 3);
})
})