Skip to content

Commit fd758c9

Browse files
committed
Minor changes to test names; added comments on shortcomings
1 parent d01aa9b commit fd758c9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/helpers/lookupUtils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* @return {Object} the lookup table, with all keys and values inverted
55
*/
66
function createInvertedLookup(lookup) {
7+
// NOTE: This will produce collisions if values aren't unique
8+
// and unspecified behavior if values are non-strings
79
return Object.entries(lookup).reduce((ret, entry) => {
810
const [key, value] = entry;
911
// eslint-disable-next-line no-param-reassign
@@ -18,6 +20,7 @@ function createInvertedLookup(lookup) {
1820
* @return {Object} the lookup table, with all keys lowercased
1921
*/
2022
function createLowercaseLookup(lookup) {
23+
// NOTE: This will produce collisions if keys aren't unique w/r/t case
2124
return Object.entries(lookup).reduce((ret, entry) => {
2225
const [k, v] = entry;
2326
// eslint-disable-next-line no-param-reassign

test/helpers/lookupUtils.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ describe('lookupUtils', () => {
2020
expect(Object.keys(lowercaseLookup)).toEqual(lowercasedExampleKeys);
2121
});
2222

23-
test('values should remain unchanged after lowercasing', () => {
23+
test('given a lookup with unique keys, values should remain unchanged after lowercasing', () => {
2424
const originalValues = Object.values(exampleLookup);
2525
expect(Object.values(lowercaseLookup)).toEqual(originalValues);
2626
});
2727

28-
test('# of keys should stay the same', () => {
28+
test('given a lookup with unique keys, # of keys should stay the same', () => {
2929
expect(Object.keys(lowercaseLookup).length).toEqual(Object.keys(exampleLookup).length);
3030
});
3131
});
@@ -52,11 +52,11 @@ describe('lookupUtils', () => {
5252
expect(Object.values(invertedLookup)).toEqual(expect.arrayContaining(Object.keys(exampleLookup)));
5353
});
5454

55-
test('# of new keys should match the # of values in the old object', () => {
55+
test('given a lookup with unique values, # of new keys should match the # of values in the old object', () => {
5656
expect(Object.keys(invertedLookup).length).toEqual(Object.values(exampleLookup).length);
5757
});
5858

59-
test('# of new values should match the # of keys in the old object', () => {
59+
test('given a lookup with unique values, # of new values should match the # of keys in the old object', () => {
6060
expect(Object.values(invertedLookup).length).toEqual(Object.keys(exampleLookup).length);
6161
});
6262
});

0 commit comments

Comments
 (0)