Skip to content

Commit

Permalink
fix(2022-day-02): correctly register loss when opponent plays rock ag…
Browse files Browse the repository at this point in the history
…ainst scissors
  • Loading branch information
amclin committed Dec 2, 2022
1 parent d13ae6d commit 5b58961
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions 2022/day-02/rochambeau.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const scoreRound = (opponent, self) => {
// Win
if (
(selfScore - 1 === oppScore) ||
(selfScore === -1 && oppScore === 2)
(selfScore === 0 && oppScore === 2)
) {
return 6
}
// Lose
if (
(oppScore - 1 === selfScore) ||
(oppScore === -1 && selfScore === 2)
(oppScore === 0 && selfScore === 2)
) {
return 0
}
Expand Down
5 changes: 4 additions & 1 deletion 2022/day-02/rochambeau.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
const { expect } = require('chai')
const { scoreMatch, scoreRound } = require('./rochambeau')

describe.only('--- Day 2: Rock Paper Scissors ---', () => {
describe('--- Day 2: Rock Paper Scissors ---', () => {
describe('Part 1', () => {
describe('scoreRound', () => {
it('calculates the score of a round based on what the opponent played and what you played', () => {
// provided
expect(scoreRound('A', 'Y')).to.equal(8)
expect(scoreRound('B', 'X')).to.equal(1)
expect(scoreRound('C', 'Z')).to.equal(6)
// data from input
expect(scoreRound('A', 'Z')).to.equal(3) // loss and self played Z
})
})
describe('scoreMatch', () => {
Expand Down

0 comments on commit 5b58961

Please sign in to comment.