Skip to content

Instantly share code, notes, and snippets.

View Cst2989's full-sized avatar
🎯
Focusing

Neciu Aurel Dan Cst2989

🎯
Focusing
View GitHub Profile
@Cst2989
Cst2989 / inputs.js
Last active October 22, 2021 09:41
Inputs for Bowling Kata
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
@Cst2989
Cst2989 / main.test.js
Last active October 22, 2021 09:50
Testing for invalid inputs
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 = [
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', () => {
});
export const bowlingScore = (inputRolls) => {
if (inputRolls.length < 20) {
return 'Invalid number of rolls'
}
let totalScore = 0;
return totalScore;
};
@Cst2989
Cst2989 / score-2.js
Created October 22, 2021 09:52
Validating inputs
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;
@Cst2989
Cst2989 / bowling.js
Created October 22, 2021 09:54
default state
export const bowlingScore = (inputRolls) => {
let totalScore = 0;
return totalScore;
};
@Cst2989
Cst2989 / calculateFrame-1.test.js
Created October 22, 2021 09:57
calculateFrame testing
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', () => {
@Cst2989
Cst2989 / calculateFrame-2.test.js
Last active October 22, 2021 10:00
Calculate frame invalid inputs
const calculateFrame = (firstRoll, secondRoll) => {
const rollSum = firstRoll + secondRoll;
if (rollSum > 10) {
return 'Invalid frame input';
}
return 0;
};
@Cst2989
Cst2989 / calculateFrame-3.test.js
Last active October 22, 2021 10:12
Adding happy path test
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', () => {
export const calculateFrame = (rollOne, rollTwo) => {
const score = rollOne + rollTwo;
if (score > 10) {
return 'Invalid frame input';
}
if (rollOne === 10) {
return 'X';
}