Last active
October 22, 2021 09:50
-
-
Save Cst2989/705c83d3a2f1010005fd4594ed43639f to your computer and use it in GitHub Desktop.
Testing for invalid inputs
This file contains 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 = [ | |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, | |
22, 23, | |
]; // ARRANGE | |
const gameScore = bowlingScore(inputRolls); // ACT | |
expect(gameScore).toBe('Invalid rolls input'); // ASSERT | |
}); | |
test('it should return error message if negative numbers', () => { | |
const inputRolls = [ | |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, -19, 20, | |
]; // ARRANGE | |
const gameScore = bowlingScore(inputRolls); // ACT | |
expect(gameScore).toBe('Invalid rolls input'); // ASSERT | |
}); | |
test('it should return error message non-zero number after strike', () => { | |
const inputRolls = [ | |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 10, 2, 20, | |
]; | |
const gameScore = bowlingScore(inputRolls); | |
expect(gameScore).toBe(0); | |
}); | |
test('it should return error message sum in frame is bigger than 10', () => { | |
const inputRolls = [ | |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 10, 2, 20, | |
]; | |
const gameScore = bowlingScore(inputRolls); | |
expect(gameScore).toBe(0); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment