Skip to content

Commit 32c9987

Browse files
test(2020-day-07): stub out tests for counting child bags
1 parent 5142768 commit 32c9987

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

2020/day-7/bagRules.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ const findAllowedOuter = (rules, color) => {
4747
Object.assign(allowed, temp)
4848
}
4949
})
50-
console.log(allowed)
50+
5151
return allowed
5252
}
5353

54+
const countInner = (rules, color) => {
55+
return {
56+
[color]: 5
57+
}
58+
}
59+
5460
module.exports = {
5561
parseRule,
56-
findAllowedOuter
62+
findAllowedOuter,
63+
countInner
5764
}

2020/day-7/bagRules.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-env mocha */
22
const { expect } = require('chai')
3-
const { parseRule, findAllowedOuter } = require('./bagRules')
3+
const { parseRule, findAllowedOuter, countInner } = require('./bagRules')
44

55
const testData = {
66
rules: [
@@ -58,4 +58,14 @@ describe('--- Day 7: Handy Haversacks ---', () => {
5858
})
5959
})
6060
})
61+
describe('Part 2', () => {
62+
describe('countInner()', () => {
63+
it('provides a list of child bags and with quantity of each', () => {
64+
const result = Object.keys(
65+
countInner(testData.rules.map(parseRule), 'shiny gold bag')
66+
).reduce((total, colorSubTotal) => total + colorSubTotal, 0)
67+
expect(result).to.equal(126)
68+
})
69+
})
70+
})
6171
})

0 commit comments

Comments
 (0)