Skip to content
Prev Previous commit
Next Next commit
test(2023-02): validate game against limits
  • Loading branch information
developher-net committed Dec 15, 2023
commit cff0f915c3cc407a41c9c79dfd29bb32c22be9ca
7 changes: 6 additions & 1 deletion 2023/day-02/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const parseGame = (gameString) => {
}
}

const validateGame = () => {

}

module.exports = {
parseGame
parseGame,
validateGame
}
49 changes: 48 additions & 1 deletion 2023/day-02/game.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */
const { expect } = require('chai')
const { parseGame } = require('./game')
const { parseGame, validateGame } = require('./game')

describe('--- Day 2: Cube Conundrum ---', () => {
describe('Part 1', () => {
Expand Down Expand Up @@ -56,5 +56,52 @@ describe('--- Day 2: Cube Conundrum ---', () => {
})
})
})

describe('validateGame', () => {
it.only('checks if the game is valid given the limits', () => {
const limits = '0c0d0e' // 12 red cubes, 13 green cubes, and 14 blue cubes
const data = [
{
id: 1,
draws: [
'040003',
'010206',
'000200'
]
}, {
id: 2,
draws: [
'000201',
'010304',
'000101'
]
}, {
id: 3,
draws: [
'140806',
'040d05',
'010500'
]
}, {
id: 4,
draws: [
'030106',
'060300',
'0e030f'
]
}, {
id: 5,
draws: [
'060301',
'010202'
]
}
]
const result = [true, true, false, false, true]
data.forEach((game, idx) => {
expect(validateGame(game, limits)).to.equal(result[idx])
})
})
})
})
})