1
1
/* eslint-env mocha */
2
2
const { expect } = require ( 'chai' )
3
- const { run, parseCommand, logEvent, displayLog } = require ( './runProgram' )
3
+ const { run, getPosition , getAccumulator , execInstruction , parseCommand, logEvent, displayLog } = require ( './runProgram' )
4
4
5
5
const exampleLog = `
6
6
nop +0 | 1
@@ -21,28 +21,36 @@ describe('--- Day 8: Handheld Halting ---', () => {
21
21
expect ( false ) . to . equal ( true )
22
22
} )
23
23
} )
24
- // xdescribe('execInstruction()', () => {
25
- // it('executes a specified command', () => {
26
- // execInstruction()
27
- // expect(false).to.equal(true)
28
- // })
29
- // it('steps to the next sequential command', () => {
30
- // logEvent()
31
- // expect(false).to.equal(true)
32
- // })
33
- // it('can execute a `nop` command which does nothing', () => {
34
- // execInstruction('nop')
35
- // expect(false).to.equal(true)
36
- // })
37
- // it('can execute a `acc` command which increments the accumulator', () => {
38
- // execInstruction('acc')
39
- // expect(false).to.equal(true)
40
- // })
41
- // it('can execute a `jmp` command which jumps to a different command in the instruction set', () => {
42
- // execInstruction('jmp')
43
- // expect(false).to.equal(true)
44
- // })
45
- // })
24
+ describe ( 'execInstruction()' , ( ) => {
25
+ it ( 'executes a specified command' , ( ) => {
26
+ expect ( getPosition ( ) ) . to . equal ( 1 )
27
+ expect ( execInstruction ( 'acc +3' , 300 , 600 ) ) . to . equal ( 301 )
28
+ expect ( getAccumulator ( ) ) . to . equal ( 3 )
29
+ expect ( getPosition ( ) ) . to . equal ( 301 )
30
+ } )
31
+ xit ( 'steps to the next sequential command' , ( ) => {
32
+ // logEvent()
33
+ // expect(false).to.equal(true)
34
+ } )
35
+ it ( 'can execute a `nop` command which does nothing' , ( ) => {
36
+ const acc = getAccumulator ( )
37
+ expect ( execInstruction ( 'nop +3' , 999 , 600 ) ) . to . equal ( 1000 )
38
+ expect ( getPosition ( ) ) . to . equal ( 1000 )
39
+ expect ( getAccumulator ( ) ) . to . equal ( acc )
40
+ } )
41
+ it ( 'can execute a `acc` command which increments the accumulator' , ( ) => {
42
+ const acc = getAccumulator ( )
43
+ expect ( execInstruction ( 'acc +100' , 1234 , 600 ) ) . to . equal ( 1235 )
44
+ expect ( getPosition ( ) ) . to . equal ( 1235 )
45
+ expect ( getAccumulator ( ) ) . to . equal ( acc + 100 )
46
+ } )
47
+ it ( 'can execute a `jmp` command which jumps to a different command in the instruction set' , ( ) => {
48
+ const acc = getAccumulator ( )
49
+ expect ( execInstruction ( 'jmp -23' , 400 , 600 ) ) . to . equal ( 377 )
50
+ expect ( getPosition ( ) ) . to . equal ( 377 )
51
+ expect ( getAccumulator ( ) ) . to . equal ( acc )
52
+ } )
53
+ } )
46
54
describe ( 'parseCommand()' , ( ) => {
47
55
it ( 'parses an instruction string into a structured command object' , ( ) => {
48
56
const instructions = [
0 commit comments