Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAWEL BROILO I STRUCTURING AND TESTING DATA TYPES I SPRINT 3 #440

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sprint 3/1. Key Implement/Angle Type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

function getAngleType(angle) {
if (angle === 90) return "Right angle";
console.log(90);
expect(getAngleType(90)).tobe("Right angle");
}
13 changes: 13 additions & 0 deletions Sprint 3/1. Key Implement/function getAngle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
expect(getAngleType(90)).toEqual("Right angle")
const angleType = 90 "Right angle";
}
function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (angle > 0 && angle < 90) return "Acute angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if (angle > 180 && angle < 360) return "Reflex angle";
if (angle === 360) return "Full rotation";
return "Invalid angle";
10 changes: 10 additions & 0 deletions Sprint 3/1. Key Implement/function getCardValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function getCardValue(card) {
if (rank === "A") return 11;
assertEquals(card, 11);
console.assert(A === 11);
}
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
91 changes: 91 additions & 0 deletions Sprint 3/1. Key Implement/get-card-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck

// You will need to implement a function getCardValue
// the function takes a single parameter, a string representing a playing card
// the function should return the numerical value of the card
// the first test and first case is written for you
// complete the rest of the tests and cases
// write one test at a time, and make it pass, build your solution up methodically
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
function getCardValue(card) {
if (rank === "A") return 11;
assertEquals(card, 11);
console.assert(A === 11);

// You need to write assertions for your function to check it works in different cases
// we're going to use this helper function to make our assertions easier to read
// if the actual output matches the target output, the test will pass
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
// Acceptance criteria:

// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A),
// When the function getCardValue is called with this card string as input,
// Then it should return the numerical card value
const aceofSpades = getCardValue("A♠");
assertEquals(aceofSpades, 11);
console.assert(A === 11);

function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

// Handle Number Cards (2-10):
// Given a card with a rank between "2" and "9",
// When the function is called with such a card,
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
const fiveofHearts = getCardValue("5♥");
assertEquals(fiveofHearts, 5);
console.assert(fiveofHearts === 5);

function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

// ====> write your test here, and then add a line to pass the test in the function above

function getCardValue(J, Q, K) {
assertEquals(J, Q, K, 10);
console.assert(J, Q, K === 10);
}

function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
const Ace = getCardValue(A);
assertEquals(Ace, 11);
console.assert(Ace === 11);
}

function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

function getCardValue(card) {
assertEquals(card, 52);
console.assert(card === 52);
console.log("Invalid card rank");
}

function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
81 changes: 81 additions & 0 deletions Sprint 3/1. Key Implement/getCardValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck
// You will need to implement a function getCardValue
// the function takes a single parameter, a string representing a playing card
// the function should return the numerical value of the card
// the first test and first case is written for you
// complete the rest of the tests and cases
// write one test at a time, and make it pass, build your solution up methodically
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
function getCardValue(card) {
if (rank === "A") return 11;
assertEquals(card, 11);
console.assert(A === 11);
}
// You need to write assertions for your function to check it works in different cases
// we're going to use this helper function to make our assertions easier to read
// if the actual output matches the target output, the test will pass
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
// Acceptance criteria:
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A),
// When the function getCardValue is called with this card string as input,
// Then it should return the numerical card value
const aceofSpades = getCardValue("A♠");
assertEquals(aceofSpades, 11);
console.assert(A === 11);
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
// Handle Number Cards (2-10):
// Given a card with a rank between "2" and "9",
// When the function is called with such a card,
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
const fiveofHearts = getCardValue("5♥");
assertEquals(fiveofHearts, 5);
console.assert(fiveofHearts === 5);
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
// ====> write your test here, and then add a line to pass the test in the function above
function getCardValue(J, Q, K) {
assertEquals(J, Q, K, "10");
console.assert(J, Q, K === 10);
}
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
const Ace = getCardValue("A");
{
assertEquals(Ace, "11");
console.assert(Ace === 11);
}
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
function getCardValue(card) {
assertEquals(card, 52);
console.assert(card === 52);
console.log("Invalid card rank");
}
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
53 changes: 53 additions & 0 deletions Sprint 3/1. Key Implement/is Proper Fraction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Implement a function isProperFraction
// Write assertions for your function to check it works in different cases
// Terms:
// Fractions: https://www.bbc.co.uk/bitesize/topics/zt9n6g8/articles/zjxpp4j
// Written here like this: 1/2 == Numerator/Denominator
// the first test and first case is written for you
// complete the rest of the tests and cases
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
}

// here's our helper again
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

// Acceptance criteria:

// Proper Fraction check:
// Input: numerator = 2, denominator = 3
// target output: true
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
const properFraction = isProperFraction(2, 3);
assertEquals(properFraction, true);

// Improper Fraction check:
// Input: numerator = 5, denominator = 2
// target output: false
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false.
const improperFraction = isProperFraction(5, 2);
assertEquals(improperFraction, false);

// Negative Fraction check:
// Input: numerator = -4, denominator = 7
// target output: true
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
const negativeFraction = isProperFraction(-4, 7);
// ====> complete with your assertion

// Equal Numerator and Denominator check:
// Input: numerator = 3, denominator = 3
// target output: false
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
const equalFraction = isProperFraction(3, 3);
// ====> complete with your assertion

// Stretch:
// What other scenarios could you test for?
23 changes: 23 additions & 0 deletions Sprint 3/1. Key Implement/proper fraction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) {
return true;
} else {
console.assert(
'Expected numerator to be less than denominator'
);
return false;
}

}

function assertEquals(actualOutput, targetOutput) {
console.assert(
`Expected ${actualOutput} to equal ${targetOutput}`
);
}


module.exports = isProperFraction;

Test

17 changes: 17 additions & 0 deletions Sprint 3/2-mandatory-rewrite/Function Get Card Value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const getCardValue = require("./3-get-card-value");

test("should return 11 for Ace of Spades", () => {
const aceofSpades = getCardValue("A♠");
expect(aceofSpades).toEqual(11);
});
case 2
test("should return 10 for King of Hears", () => {
const king of Hearts = get card getCardValue('K');
expect(king of Hearts).toEqual(10);
}
case 3

// Case 2: Handle Number Cards (2-10):
// Case 3: Handle Face Cards (J, Q, K):
// Case 4: Handle Ace (A):
// Case 5: Handle Invalid Cards:
14 changes: 14 additions & 0 deletions Sprint 3/2-mandatory-rewrite/Rewrite Angle Types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const getAngleType = require("./1-get-angle-type");

test("should identify right angle (90°)", () => {
expect(getAngleType(90)).toEqual("Right angle");
});

const getAngleType = require("./Rewrite Angle Types");

const getAngleType = require("./1-get-angle-type");

test("should identify right angle (90°)", () => {
expect(getAngleType(90)).toEqual("Right angle");
});

Empty file.
14 changes: 14 additions & 0 deletions Sprint 3/2-mandatory-rewrite/RewriteTestProperFraction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const isProperFraction = require("./Rewrite Proper Fraction");

// Test cases
test("should return true for numerator < denominator", () => {
expect(isProperFraction(1, 2)).toBe(true);
});

test("should return false for numerator == denominator", () => {
expect(isProperFraction(2, 2)).toBe(false);
});

test("should return false for numerator > denominator", () => {
expect(isProperFraction(3, 2)).toBe(false);
});
21 changes: 21 additions & 0 deletions Sprint 3/2-mandatory-rewrite/Test Angles Types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const getAngleType = require("./1-get-angle-type");

test("should identify right angle (90°)", () => {
expect(getAngleType(90)).toEqual("Right angle");
});

test("should identify acute angle (< 90°)", () => {
expect(getAngleType(45)).toEqual("Acute angle");
});

test("should identify obtuse angle (> 90° and < 180°)", () => {
expect(getAngleType(135)).toEqual("Obtuse angle");
});

test("should identify straight angle (180°)", () => {
expect(getAngleType(180)).toEqual("Straight angle");
});

test("should identify reflex angle (> 180°)", () => {
expect(getAngleType(225)).toEqual("Reflex angle");
});
14 changes: 14 additions & 0 deletions Sprint 3/2-mandatory-rewrite/Test Rewrite Get Card Value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function getCardValue(card) {
switch (card) {
case 'A':
return 1;
case 'J':
case 'Q':
case 'K':
return 10;
default:
return parseInt(card);
}
}

module.exports = getCardValue;
Empty file.
17 changes: 17 additions & 0 deletions Sprint 3/3.Mandatory Practice Implement/count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function countChar(stringOfCharacters, findCharacter) {
console.assert(typeof stringOfCharacters === 'string', 'The first argument must be a string');
console.assert(typeof findCharacter === 'string', 'The second argument must be a string');

let countChar = 0;
stringOfCharacters = stringOfCharacters.toLowerCase();
findCharacter = findCharacter.toLowerCase();
for (let i = 0; i < stringOfCharacters.length; i++) {
if (stringOfCharacters[i] === findCharacter) {
countChar++;
}
}
return countChar;
}

// Export the function
module.exports = countChar;
Loading