Skip to content

Commit cff0f91

Browse files
test(2023-02): validate game against limits
1 parent e17ca18 commit cff0f91

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

2023/day-02/game.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ const parseGame = (gameString) => {
2323
}
2424
}
2525

26+
const validateGame = () => {
27+
28+
}
29+
2630
module.exports = {
27-
parseGame
31+
parseGame,
32+
validateGame
2833
}

2023/day-02/game.test.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-env mocha */
22
const { expect } = require('chai')
3-
const { parseGame } = require('./game')
3+
const { parseGame, validateGame } = require('./game')
44

55
describe('--- Day 2: Cube Conundrum ---', () => {
66
describe('Part 1', () => {
@@ -56,5 +56,52 @@ describe('--- Day 2: Cube Conundrum ---', () => {
5656
})
5757
})
5858
})
59+
60+
describe('validateGame', () => {
61+
it.only('checks if the game is valid given the limits', () => {
62+
const limits = '0c0d0e' // 12 red cubes, 13 green cubes, and 14 blue cubes
63+
const data = [
64+
{
65+
id: 1,
66+
draws: [
67+
'040003',
68+
'010206',
69+
'000200'
70+
]
71+
}, {
72+
id: 2,
73+
draws: [
74+
'000201',
75+
'010304',
76+
'000101'
77+
]
78+
}, {
79+
id: 3,
80+
draws: [
81+
'140806',
82+
'040d05',
83+
'010500'
84+
]
85+
}, {
86+
id: 4,
87+
draws: [
88+
'030106',
89+
'060300',
90+
'0e030f'
91+
]
92+
}, {
93+
id: 5,
94+
draws: [
95+
'060301',
96+
'010202'
97+
]
98+
}
99+
]
100+
const result = [true, true, false, false, true]
101+
data.forEach((game, idx) => {
102+
expect(validateGame(game, limits)).to.equal(result[idx])
103+
})
104+
})
105+
})
59106
})
60107
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy