|
| 1 | +/* eslint-env mocha */ |
| 2 | +const { expect } = require('chai') |
| 3 | +const { isValid } = require('./xmasEncryption') |
| 4 | + |
| 5 | +const range = (i) => { return i ? range(i - 1).concat(i) : [] } |
| 6 | + |
| 7 | +describe('--- Day 9: Encoding Error ---', () => { |
| 8 | + describe('Part 1', () => { |
| 9 | + describe('isValid()', () => { |
| 10 | + it('checks if an entry is valid', () => { |
| 11 | + // first example |
| 12 | + const preamble = range(25) |
| 13 | + expect(isValid(26, preamble), '26 is valid').to.equal(true) |
| 14 | + expect(isValid(49, preamble), '49 is valid').to.equal(true) |
| 15 | + expect(isValid(100, preamble), '100 is larger than any sum').to.equal(false) |
| 16 | + expect(isValid(50, preamble), '50 not valid because cannot use the same number (25) twice').to.equal(false) |
| 17 | + // 2nd example |
| 18 | + // move 20 to start of the list, and then pop it off |
| 19 | + preamble.splice(preamble.indexOf(20), 1) |
| 20 | + // add 45 to the list |
| 21 | + preamble.push(45) |
| 22 | + expect(isValid(26, preamble), '26 is valid').to.equal(true) |
| 23 | + expect(isValid(65, preamble), '65 doesnt match any 2 values').to.equal(false) |
| 24 | + expect(isValid(64, preamble), '64 is valid').to.equal(true) |
| 25 | + expect(isValid(66, preamble), '65 is valid').to.equal(true) |
| 26 | + }) |
| 27 | + }) |
| 28 | + }) |
| 29 | +}) |
0 commit comments