|
| 1 | +/* eslint-env mocha */ |
| 2 | +const { expect } = require('chai') |
| 3 | +const { parseRule } = require('./bagRules') |
| 4 | + |
| 5 | +const testData = { |
| 6 | + rules: [ |
| 7 | + 'light red bags contain 1 bright white bag, 2 muted yellow bags.', |
| 8 | + 'dark orange bags contain 3 bright white bags, 4 muted yellow bags.', |
| 9 | + 'bright white bags contain 1 shiny gold bag.', |
| 10 | + 'muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.', |
| 11 | + 'shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.', |
| 12 | + 'dark olive bags contain 3 faded blue bags, 4 dotted black bags.', |
| 13 | + 'vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.', |
| 14 | + 'faded blue bags contain no other bags.', |
| 15 | + 'dotted black bags contain no other bags.' |
| 16 | + ] |
| 17 | +} |
| 18 | + |
| 19 | +describe('--- Day 7: Handy Haversacks ---', () => { |
| 20 | + describe('Part 1', () => { |
| 21 | + describe('parseRule()', () => { |
| 22 | + it('converts a natural language rule into a useable object', () => { |
| 23 | + expect(parseRule(testData.rules[0])).to.deep.equal({ |
| 24 | + outer: 'light red bag', |
| 25 | + inner: [ |
| 26 | + { |
| 27 | + count: 1, |
| 28 | + color: 'bright white bag' |
| 29 | + }, { |
| 30 | + count: 2, |
| 31 | + color: 'muted yellow bag' |
| 32 | + } |
| 33 | + ] |
| 34 | + }) |
| 35 | + }) |
| 36 | + it('handles bags that do not accept children', () => { |
| 37 | + expect(parseRule(testData.rules[7])).to.deep.equal({ |
| 38 | + outer: 'faded blue bag' |
| 39 | + }) |
| 40 | + }) |
| 41 | + }) |
| 42 | + }) |
| 43 | +}) |
0 commit comments