1
1
/* eslint-env mocha */
2
2
const { expect } = require ( 'chai' )
3
- const { run, executeStep , logEvent, displayLog } = require ( './runProgram' )
3
+ const { run, parseCommand , logEvent, displayLog } = require ( './runProgram' )
4
4
5
5
const exampleLog = `
6
6
nop +0 | 1
@@ -21,26 +21,40 @@ describe('--- Day 8: Handheld Halting ---', () => {
21
21
expect ( false ) . to . equal ( true )
22
22
} )
23
23
} )
24
- xdescribe ( 'executeStep()' , ( ) => {
25
- it ( 'executes a specified command' , ( ) => {
26
- executeStep ( )
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
- executeStep ( 'nop' )
35
- expect ( false ) . to . equal ( true )
36
- } )
37
- it ( 'can execute a `acc` command which increments the accumulator' , ( ) => {
38
- executeStep ( '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
- executeStep ( 'jmp' )
43
- expect ( false ) . to . equal ( true )
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
+ // })
46
+ describe ( 'parseCommand()' , ( ) => {
47
+ it ( 'parses an instruction string into a structured command object' , ( ) => {
48
+ const instructions = [
49
+ 'jmp +4' ,
50
+ 'acc +3' ,
51
+ 'jmp -3' ,
52
+ 'acc -99'
53
+ ]
54
+ instructions . forEach ( ( inst ) => {
55
+ const { cmd, arg } = parseCommand ( inst )
56
+ expect ( `${ cmd } ${ arg } ` ) . to . equal ( inst )
57
+ } )
44
58
} )
45
59
} )
46
60
describe ( 'logEvent()' , ( ) => {
0 commit comments