This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const input = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; // output = 20 | |
| const inputWithStrike = [ | |
| 10, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
| ]; // output = 30 | |
| const inputWithConsecutiveStrikes = [ | |
| 10, 0, 10, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
| ]; // output = 49 | |
| const inputWithPerfectScore = [ | |
| 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 10, 10, | |
| ]; // output = 300 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe('bowlingScore error boundaries', () => { | |
| test('it should return error message for too few rolls', () => { | |
| const inputRolls = [1, 2, 3]; // ARRANGE | |
| const gameScore = bowlingScore(inputRolls); // ACT | |
| expect(gameScore).toBe('Invalid rolls input'); // ASSERT | |
| }); | |
| test('it should return error message for too many rolls', () => { | |
| const inputRolls = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test.only('this will be the only test that runs', () => { | |
| expect(true).toBe(false); | |
| }); | |
| // or | |
| describe.only('This will run only this block of tests', () => { | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const bowlingScore = (inputRolls) => { | |
| if (inputRolls.length < 20) { | |
| return 'Invalid number of rolls' | |
| } | |
| let totalScore = 0; | |
| return totalScore; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const bowlingScore = (inputRolls) => { | |
| if ( | |
| inputRolls.length < 20 || | |
| inputRolls.length > 21 || | |
| inputRolls.some((roll) => roll < 0) | |
| ) { | |
| return 'Invalid rolls input'; | |
| } | |
| let totalScore = 0; | |
| return totalScore; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const bowlingScore = (inputRolls) => { | |
| let totalScore = 0; | |
| return totalScore; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe('calculateFrame function', () => { | |
| test('it should return error message for non-zero number after strike', () => { | |
| const firstRoll = 10; // strike | |
| const secondRoll = 1; // invalid input | |
| const frameScore = calculateFrame(firstRoll, secondRoll); | |
| expect(frameScore).toBe('Invalid frame input'); | |
| }); | |
| test('it should return error message sum in frame is bigger than 10', () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const calculateFrame = (firstRoll, secondRoll) => { | |
| const rollSum = firstRoll + secondRoll; | |
| if (rollSum > 10) { | |
| return 'Invalid frame input'; | |
| } | |
| return 0; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test('it should return the sum of the rolls', () => { | |
| const firstRoll = 7 | |
| const secondRoll = 2 | |
| const frameScore = calculateFrame(firstRoll, secondRoll); | |
| expect(frameScore).toBe(9); | |
| }); | |
| test('it should return the / sign if the players hit a spare', () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const calculateFrame = (rollOne, rollTwo) => { | |
| const score = rollOne + rollTwo; | |
| if (score > 10) { | |
| return 'Invalid frame input'; | |
| } | |
| if (rollOne === 10) { | |
| return 'X'; | |
| } | |
OlderNewer