|
| 1 | +/* eslint-env mocha */ |
| 2 | +const expect = require('chai').expect |
| 3 | +const { |
| 4 | + parseLine |
| 5 | +} = require('./helpers') |
| 6 | +const { |
| 7 | + Beacon |
| 8 | +} = require('./beacons') |
| 9 | + |
| 10 | +const testData = `position=< 9, 1> velocity=< 0, 2> |
| 11 | +position=< 7, 0> velocity=<-1, 0> |
| 12 | +position=< 3, -2> velocity=<-1, 1> |
| 13 | +position=< 6, 10> velocity=<-2, -1> |
| 14 | +position=< 2, -4> velocity=< 2, 2> |
| 15 | +position=<-6, 10> velocity=< 2, -2> |
| 16 | +position=< 1, 8> velocity=< 1, -1> |
| 17 | +position=< 1, 7> velocity=< 1, 0> |
| 18 | +position=<-3, 11> velocity=< 1, -2> |
| 19 | +position=< 7, 6> velocity=<-1, -1> |
| 20 | +position=<-2, 3> velocity=< 1, 0> |
| 21 | +position=<-4, 3> velocity=< 2, 0> |
| 22 | +position=<10, -3> velocity=<-1, 1> |
| 23 | +position=< 5, 11> velocity=< 1, -2> |
| 24 | +position=< 4, 7> velocity=< 0, -1> |
| 25 | +position=< 8, -2> velocity=< 0, 1> |
| 26 | +position=<15, 0> velocity=<-2, 0> |
| 27 | +position=< 1, 6> velocity=< 1, 0> |
| 28 | +position=< 8, 9> velocity=< 0, -1> |
| 29 | +position=< 3, 3> velocity=<-1, 1> |
| 30 | +position=< 0, 5> velocity=< 0, -1> |
| 31 | +position=<-2, 2> velocity=< 2, 0> |
| 32 | +position=< 5, -2> velocity=< 1, 2> |
| 33 | +position=< 1, 4> velocity=< 2, 1> |
| 34 | +position=<-2, 7> velocity=< 2, -2> |
| 35 | +position=< 3, 6> velocity=<-1, -1> |
| 36 | +position=< 5, 0> velocity=< 1, 0> |
| 37 | +position=<-6, 0> velocity=< 2, 0> |
| 38 | +position=< 5, 9> velocity=< 1, -2> |
| 39 | +position=<14, 7> velocity=<-2, 0> |
| 40 | +position=<-3, 6> velocity=< 2, -1>`.split('\n').map(parseLine) |
| 41 | + |
| 42 | +describe('--- Day 10: The Stars Align ---', () => { |
| 43 | + describe('Beacons:', () => { |
| 44 | + describe('new Beacons()', () => { |
| 45 | + it('initializes a beacon tracker object, cacheing the input data', () => { |
| 46 | + const expected = [ |
| 47 | + { position: { x: 9, y: 1 }, velocity: { x: 0, y: 2 } }, |
| 48 | + { position: { x: 7, y: 0 }, velocity: { x: -1, y: 0 } }, |
| 49 | + { position: { x: 3, y: -2 }, velocity: { x: -1, y: 1 } }, |
| 50 | + { position: { x: 6, y: 10 }, velocity: { x: -2, y: -1 } }, |
| 51 | + { position: { x: 2, y: -4 }, velocity: { x: 2, y: 2 } }, |
| 52 | + { position: { x: -6, y: 10 }, velocity: { x: 2, y: -2 } }, |
| 53 | + { position: { x: 1, y: 8 }, velocity: { x: 1, y: -1 } }, |
| 54 | + { position: { x: 1, y: 7 }, velocity: { x: 1, y: 0 } }, |
| 55 | + { position: { x: -3, y: 11 }, velocity: { x: 1, y: -2 } }, |
| 56 | + { position: { x: 7, y: 6 }, velocity: { x: -1, y: -1 } }, |
| 57 | + { position: { x: -2, y: 3 }, velocity: { x: 1, y: 0 } }, |
| 58 | + { position: { x: -4, y: 3 }, velocity: { x: 2, y: 0 } }, |
| 59 | + { position: { x: 10, y: -3 }, velocity: { x: -1, y: 1 } }, |
| 60 | + { position: { x: 5, y: 11 }, velocity: { x: 1, y: -2 } }, |
| 61 | + { position: { x: 4, y: 7 }, velocity: { x: 0, y: -1 } }, |
| 62 | + { position: { x: 8, y: -2 }, velocity: { x: 0, y: 1 } }, |
| 63 | + { position: { x: 15, y: 0 }, velocity: { x: -2, y: 0 } }, |
| 64 | + { position: { x: 1, y: 6 }, velocity: { x: 1, y: 0 } }, |
| 65 | + { position: { x: 8, y: 9 }, velocity: { x: 0, y: -1 } }, |
| 66 | + { position: { x: 3, y: 3 }, velocity: { x: -1, y: 1 } }, |
| 67 | + { position: { x: 0, y: 5 }, velocity: { x: 0, y: -1 } }, |
| 68 | + { position: { x: -2, y: 2 }, velocity: { x: 2, y: 0 } }, |
| 69 | + { position: { x: 5, y: -2 }, velocity: { x: 1, y: 2 } }, |
| 70 | + { position: { x: 1, y: 4 }, velocity: { x: 2, y: 1 } }, |
| 71 | + { position: { x: -2, y: 7 }, velocity: { x: 2, y: -2 } }, |
| 72 | + { position: { x: 3, y: 6 }, velocity: { x: -1, y: -1 } }, |
| 73 | + { position: { x: 5, y: 0 }, velocity: { x: 1, y: 0 } }, |
| 74 | + { position: { x: -6, y: 0 }, velocity: { x: 2, y: 0 } }, |
| 75 | + { position: { x: 5, y: 9 }, velocity: { x: 1, y: -2 } }, |
| 76 | + { position: { x: 14, y: 7 }, velocity: { x: -2, y: 0 } }, |
| 77 | + { position: { x: -3, y: 6 }, velocity: { x: 2, y: -1 } } |
| 78 | + ] |
| 79 | + const beaconTracker = new Beacon(testData) |
| 80 | + const actual = beaconTracker.start |
| 81 | + expect(actual).to.deep.equal(expected) |
| 82 | + }) |
| 83 | + }) |
| 84 | + describe('get(frame)', () => { |
| 85 | + it('Calculates the positions of the beacons for the specified frame', () => { |
| 86 | + const expected = [ |
| 87 | + { x: 9, y: 13 }, |
| 88 | + { x: 1, y: 0 }, |
| 89 | + { x: -3, y: 4 }, |
| 90 | + { x: -6, y: 4 }, |
| 91 | + { x: 14, y: 8 }, |
| 92 | + { x: 6, y: -2 }, |
| 93 | + { x: 7, y: 2 }, |
| 94 | + { x: 7, y: 7 }, |
| 95 | + { x: 3, y: -1 }, |
| 96 | + { x: 1, y: 0 }, |
| 97 | + { x: 4, y: 3 }, |
| 98 | + { x: 8, y: 3 }, |
| 99 | + { x: 4, y: 3 }, |
| 100 | + { x: 11, y: -1 }, |
| 101 | + { x: 4, y: 1 }, |
| 102 | + { x: 8, y: 4 }, |
| 103 | + { x: 3, y: 0 }, |
| 104 | + { x: 7, y: 6 }, |
| 105 | + { x: 8, y: 3 }, |
| 106 | + { x: -3, y: 9 }, |
| 107 | + { x: 0, y: -1 }, |
| 108 | + { x: 10, y: 2 }, |
| 109 | + { x: 11, y: 10 }, |
| 110 | + { x: 13, y: 10 }, |
| 111 | + { x: 10, y: -5 }, |
| 112 | + { x: -3, y: 0 }, |
| 113 | + { x: 11, y: 0 }, |
| 114 | + { x: 6, y: 0 }, |
| 115 | + { x: 11, y: -3 }, |
| 116 | + { x: 2, y: 7 }, |
| 117 | + { x: 9, y: 0 } |
| 118 | + ] |
| 119 | + const beaconTracker = new Beacon(testData) |
| 120 | + const actual = beaconTracker.getFrame(6).contents |
| 121 | + expect(actual).to.deep.equal(expected) |
| 122 | + }) |
| 123 | + it('Calculates the focus value for the frame', () => { |
| 124 | + const expected = 756 |
| 125 | + const beaconTracker = new Beacon(testData) |
| 126 | + const actual = beaconTracker.getFrame(8).meta.focus |
| 127 | + expect(actual).to.equal(expected) |
| 128 | + }) |
| 129 | + }) |
| 130 | + }) |
| 131 | +}) |
0 commit comments