10000 fix(2022-day-02): correctly register loss when opponent plays rock ag… · developher-net/advent-of-code@5b58961 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b58961

Browse files
fix(2022-day-02): correctly register loss when opponent plays rock against scissors
1 parent d13ae6d commit 5b58961

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

2022/day-02/rochambeau.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ const scoreRound = (opponent, self) => {
1414
// Win
1515
if (
1616
(selfScore - 1 === oppScore) ||
17-
(selfScore === -1 && oppScore === 2)
17+
(selfScore === 0 && oppScore === 2)
1818
) {
1919
return 6
2020
}
2121
// Lose
2222
if (
2323
(oppScore - 1 === selfScore) ||
24-
(oppScore === -1 && selfScore === 2)
24+
(oppScore === 0 && selfScore === 2)
2525
) {
2626
return 0
2727
}

2022/day-02/rochambeau.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
const { expect } = require('chai')
33
const { scoreMatch, scoreRound } = require('./rochambeau')
44

5-
describe.only('--- Day 2: Rock Paper Scissors ---', () => {
5+
describe('--- Day 2: Rock Paper Scissors ---', () => {
66
describe('Part 1', () => {
77
describe('scoreRound', () => {
88
it('calculates the score of a round based on what the opponent played and what you played', () => {
9+
// provided
910
expect(scoreRound('A', 'Y')).to.equal(8)
1011
expect(scoreRound('B', 'X')).to.equal(1)
1112
expect(scoreRound('C', 'Z')).to.equal(6)
13+
// data from input
14+
expect(scoreRound('A', 'Z')).to.equal(3) // loss and self played Z
1215
})
1316
})
1417
describe('scoreMatch', () => {

0 commit comments

Comments
 (0)
0