Skip to content

London|May-2025|KhilolaRustamova|Module-Structuring-&-Testing-Data|sprint 3 #636

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
14 changes: 13 additions & 1 deletion Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (angle < 90) return "Acute angle"
if (angle <180 && angle > 90) return "Obtuse angle"
if (angle === 180) return "Straight angle"
if (angle <360 && angle > 180) return "Reflex angle"
// read to the end, complete line 36, then pass your test here
}

Expand All @@ -33,24 +37,32 @@ function assertEquals(actualOutput, targetOutput) {
const right = getAngleType(90);
assertEquals(right, "Right angle");


// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
const acute = getAngleType(45);
assertEquals(acute, "Acute angle");


// Case 3: Identify Obtuse Angles:
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(obtuse, "Obtuse angle");


// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
// ====> write your test here, and then add a line to pass the test in the function above
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");

// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
// ====> write your test here, and then add a line to pass the test in the function above
// ====> write your test here, and then add a line to pass the test in the function above
const reflex = getAngleType(280);
assertEquals(reflex, "Reflex angle");
5 changes: 3 additions & 2 deletions Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

// here's our helper again
Expand Down Expand Up @@ -41,13 +42,13 @@ assertEquals(improperFraction, false);
// 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

assertEquals(negativeFraction, true);
// 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

assertEquals(equalFraction, false);
// Stretch:
// What other scenarios could you test for?
17 changes: 17 additions & 0 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
// 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) {

const rank = card.slice(0, -1); // remove the suit emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment explains clearly what's going on - nice comment!

if (rank === "A") return 11;
if (["K", "Q", "J", "10"].includes(rank)) return 10;

const num = parseInt(rank);
Comment on lines +14 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but: either of these lines of code could handle the value 10 - why did you decide to handle it in the K/Q/J case rather than the number case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By grouping "10" with "K", "Q", and "J", you make the intention clear:

"These are all cards that are worth 10 points, no matter what."

It also avoids need of extra range check (num === 10) in the number parsing block, which could make the logic more complex.


if (num >= 2 && num <= 9) return num;

throw new Error("Invalid card rank");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this exception is thrown, it may not be clear to the caller what the invalid rank was - can you think how to make this more clear?

}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -34,12 +43,20 @@ assertEquals(aceofSpades, 11);
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
const fiveofHearts = getCardValue("5♥");
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(fiveofHearts, 5);

// Handle Face Cards (J, Q, K):
// Given a card with a rank of "10," "J," "Q," or "K",
// When the function is called with such a card,
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
const jackOfDiamonds = getCardValue("J♦");
assertEquals(jackOfDiamonds, 10);

const queenOfClubs = getCardValue("Q♣");
assertEquals(queenOfClubs, 10);

const kingOfSpades = getCardValue("K♠");
assertEquals(kingOfSpades, 10);
// Handle Ace (A):
// Given a card with a rank of "A",
// When the function is called with an Ace,
Expand Down
11 changes: 4 additions & 7 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (angle < 90) return "Acute angle"
if (angle <180 && angle > 90) return "Obtuse angle"
if (angle === 180) return "Straight angle"
if (angle <360 && angle > 180) return "Reflex angle"
// replace with your completed function from key-implement

}








// Don't get bogged down in this detail
// Jest uses CommonJS module syntax by default as it's quite old
// We will upgrade our approach to ES6 modules in the next course module, so for now
Expand Down
18 changes: 18 additions & 0 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,34 @@ test("should identify right angle (90°)", () => {

// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
test("should identify acute angle (< 90°)", () => {
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(25)).toEqual("Acute angle");
expect(getAngleType(75)).toEqual("Acute angle");});
// Then the function should return "Acute angle"

// Case 3: Identify Obtuse Angles:
// When the angle is greater than 90 degrees and less than 180 degrees,
test("should identify obtuse angle (> 90° and < 180°)", () => {
expect(getAngleType(135)).toEqual("Obtuse angle");
expect(getAngleType(100)).toEqual("Obtuse angle");
expect(getAngleType(150)).toEqual("Obtuse angle");
});
// Then the function should return "Obtuse angle"

// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
test("should identify straight angle (180°)", () => {
expect(getAngleType(180)).toEqual("Straight angle");
});
// Then the function should return "Straight angle"

// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
test("should identify reflex angle (> 180° and < 360°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(300)).toEqual("Reflex angle");
expect(getAngleType(210)).toEqual("Reflex angle");
});

// Then the function should return "Reflex angle"
40 changes: 40 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (numerator >= denominator) return false;
// add your completed function from key-implement here
}

// 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
assertEquals(negativeFraction, true);
// 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
assertEquals(equalFraction, false);

module.exports = isProperFraction;
10 changes: 9 additions & 1 deletion Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ test("should return true for a proper fraction", () => {
});

// Case 2: Identify Improper Fractions:

test("should return false for an improper fraction", () => {
expect(isProperFraction(5, 2)).toEqual(false);
});
// Case 3: Identify Negative Fractions:
test("should return true for a negative proper fraction", () => {
expect(isProperFraction(-4, 7)).toEqual(true);
});

// Case 4: Identify Equal Numerator and Denominator:
test("should return false for equal numerator and denominator", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
34 changes: 32 additions & 2 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
const rank = card.slice(0, -1); // remove the suit emoji
if (rank === "A") return 11;
if (["K", "Q", "J", "10"].includes(rank)) return 10;

const num = parseInt(rank);

if (num >= 2 && num <= 9) return num;

throw new Error("Invalid card rank");
}
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

const aceofSpades = getCardValue("A♠");
assertEquals(aceofSpades, 11);
const fiveofHearts = getCardValue("5♥");
assertEquals(fiveofHearts, 5);
const jackOfDiamonds = getCardValue("J♦");
assertEquals(jackOfDiamonds, 10);

const queenOfClubs = getCardValue("Q♣");
assertEquals(queenOfClubs, 10);

const kingOfSpades = getCardValue("K♠");
assertEquals(kingOfSpades, 10);




module.exports = getCardValue;
24 changes: 24 additions & 0 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,27 @@ test("should return 11 for Ace of Spades", () => {
// Case 3: Handle Face Cards (J, Q, K):
// Case 4: Handle Ace (A):
// Case 5: Handle Invalid Cards:

test("should return the correct value for munber cards (2-10)", () => {
expect(getCardValue("3♣")).toEqual(3);
expect(getCardValue("7♠")).toEqual(7);
expect(getCardValue("10♦")).toEqual(10);
});

test("should return 10 for face cards (J, Q, K)", () => {
expect(getCardValue("Q♣")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
expect(getCardValue("J♦")).toEqual(10);
});
test("should return 11 for Ace cards (A)", () => {
expect(getCardValue("A♠")).toEqual(11);
expect(getCardValue("A♣")).toEqual(11);
expect(getCardValue("A♦")).toEqual(11);
});

test("should throw an error for invalid cards", () => {
expect(() => getCardValue("1♦")).toThrow("Invalid card rank");
expect(() => getCardValue("L♥")).toThrow("Invalid card rank");
expect(() => getCardValue("13♠")).toThrow("Invalid card rank");
expect(() => getCardValue("R♣")).toThrow("Invalid card rank");
});
Loading