Skip to content

LONDON | MAY2025 | JESUS DEL MORAL | STRUCTURING AND TESTING DATA SPRINT 3 #581

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 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
28 changes: 25 additions & 3 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
// Then, write the next test! :) Go through this process until all the cases are implemented

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


// read to the end, complete line 36, then pass your test here


// 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) {
Expand All @@ -21,6 +29,9 @@ function assertEquals(actualOutput, targetOutput) {
);
}




// Acceptance criteria:

// Given an angle in degrees,
Expand All @@ -30,9 +41,11 @@ function assertEquals(actualOutput, targetOutput) {
// Case 1: Identify Right Angles:
// When the angle is exactly 90 degrees,
// Then the function should return "Right angle"

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"
Expand All @@ -43,14 +56,23 @@ assertEquals(acute, "Acute angle");
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
assertEquals(obtuse, "Obtuse angle");

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

// 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(220);
assertEquals(reflex, "Reflex angle");
23 changes: 18 additions & 5 deletions Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
// write one test at a time, and make it pass, build your solution up methodically

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

// here's our helper again
function assertEquals(actualOutput, targetOutput) {
Expand All @@ -19,6 +22,7 @@ function assertEquals(actualOutput, targetOutput) {
);
}


// Acceptance criteria:

// Proper Fraction check:
Expand All @@ -28,6 +32,7 @@ function assertEquals(actualOutput, targetOutput) {
const properFraction = isProperFraction(2, 3);
assertEquals(properFraction, true);


// Improper Fraction check:
// Input: numerator = 5, denominator = 2
// target output: false
Expand All @@ -40,14 +45,22 @@ assertEquals(improperFraction, false);
// 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(improperFraction, 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?
// denominator == 0
// Input: numerator = 3, denominator = 0
// target output: false
// Explanation: The fraction 3/0 is not a proper fraction because the denominator is equal to 0. The function should return false.

const equalToCero = isProperFraction(3, 0);
assertEquals(equalToCero, false);
30 changes: 28 additions & 2 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,22 @@
// 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) {

Choose a reason for hiding this comment

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

Your function is written quite well. There are a few tests I ran that didn't return the result I would expect. Can you figure out what is missing in your implementation?

const tenOfDiamonds = getCardValue("10♦");
assertEquals(tenOfDiamonds, 10,)

const twentytwo = getCardValue("22");
assertEquals(twentytwo, 'Invalid card rank.');

const nothing = getCardValue("");
assertEquals(nothing, 'Invalid card rank.');

Choose a reason for hiding this comment

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

Can you review the above☝️failing tests and implement something within your function to ensure that they don't fail!

Copy link
Member

Choose a reason for hiding this comment

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

@delmorallopez I don't see all of the suggested tests here in your PR.

How are you tracking whether you're completed comments? I recommend clicking "Resolve conversation" when you've completed something, so that any unresolved conversations still show up and you know you need to complete them.

if (rank === "A") return 11;
let rank = card.charAt(0);
console.log(rank);

if (rank === "A") {
return 11;
} else if (!isNaN(rank)) {
// Convert rank to number
let numericRank = Number(rank);
if (numericRank >= 2 && numericRank <= 10) {
return numericRank;
}
} else if (rank === 'J' || rank === 'Q' || rank === 'K') {
return 10;
}

return 'Invalid card rank.';
}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -33,19 +48,30 @@ assertEquals(aceofSpades, 11);
// 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♥");
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(fiveofHearts, 5);


const sevenofHearts = getCardValue("7♥");
assertEquals(sevenofHearts, 7);
// 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 qofHearts = getCardValue("Q♥");
assertEquals(qofHearts, 10);

// Handle Ace (A):
// Given a card with a rank of "A",
// When the function is called with an Ace,
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
const aceofHeart = getCardValue("A♥");
assertEquals(aceofHeart, 11);



// Handle Invalid Cards:
// Given a card with an invalid rank (neither a number nor a recognized face card),
// When the function is called with such a card,
// Then it should throw an error indicating "Invalid card rank."
const invalid = getCardValue("-1");
assertEquals(invalid, 'Invalid card rank.');
13 changes: 6 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,15 @@

function getAngleType(angle) {
if (angle > 0 && angle < 90) return "Acute angle";
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if (angle > 180 && angle < 360) return "Reflex angle";
return "Wrong angle";
}








// 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
26 changes: 26 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 @@ -7,18 +7,44 @@ test("should identify right angle (90°)", () => {
// REPLACE the comments with the tests
// make your test descriptions as clear and readable as possible


// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
test("should identify Acute angle (45°)", () => {
expect(getAngleType(45)).toEqual("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"


test("should identify Obtuse angle (120°)", () => {
expect(getAngleType(120)).toEqual("Obtuse angle");
});


// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"

test("should identify Straight angle (180°)", () => {
expect(getAngleType(180)).toEqual("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"

test("should identify Reflex angle (greater 180° and less 360°)", () => {
expect(getAngleType(220)).toEqual("Reflex angle");
});

// "Wrong angle"
// when the angle is below 0 or above 360

test("should identify wrong angle (below 0 or above 360 )", () => {
expect(getAngleType(400)).toEqual("Wrong angle");
});
10 changes: 6 additions & 4 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
}
if (denominator == 0){
return false
}
return numerator < denominator;
}

module.exports = isProperFraction;
module.exports = isProperFraction;
13 changes: 13 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ test("should return true for a proper fraction", () => {

// Case 2: Identify Improper Fractions:

test("should return False for a improper fraction", () => {
expect(isProperFraction(5, 2)).toEqual(false);
});

// Case 3: Identify Negative Fractions:

test("should return True for a proper fraction", () => {
expect(isProperFraction(-4, 7)).toEqual(true);
});

// Case 4: Identify Equal Numerator and Denominator:


test("should return False for a proper fraction", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
27 changes: 25 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,28 @@
function getCardValue(card) {
// replace with your code from key-implement
if (typeof card !== 'string' || card.length < 2) {
return 'Invalid card rank.';
}

const validSuits = ['♠', '♥', '♦', '♣'];
const suit = card.slice(-1); // Last character
const rank = card.slice(0, -1); // Everything before last character

if (!validSuits.includes(suit)) {
return 'Invalid card rank.';
}

if (rank === 'A') {
return 11;
} else if (['J', 'Q', 'K'].includes(rank)) {
return 10;
} else if (!isNaN(rank)) {
const numericRank = Number(rank);
if (numericRank >= 2 && numericRank <= 10) {
return numericRank;
}
}

return 'Invalid card rank.';
}
module.exports = getCardValue;

module.exports = getCardValue;
33 changes: 33 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 @@ -6,6 +6,39 @@ test("should return 11 for Ace of Spades", () => {
});

// Case 2: Handle Number Cards (2-10):

test("should return the numeric value corresponding to the rank ", () => {
const fiveofHearts = getCardValue("5♥");
expect(fiveofHearts).toEqual(5);
});

// Case 3: Handle Face Cards (J, Q, K):

test("should return the value 10 ", () => {
const qofHearts = getCardValue("Q♥");
expect(qofHearts).toEqual(10);
});

// Case 4: Handle Ace (A):

test("should return the value 11 ", () => {
const aceofHeart = getCardValue("A♥");
expect(aceofHeart).toEqual(11);
});

// Case 5: Handle Invalid Cards:

test("should return Invalid card rank ", () => {
const invalid = getCardValue("-1");
expect(invalid).toEqual('Invalid card rank.');
});

test("should return the value 10 for 10 of hearts ", () => {
const tenOfHearts = getCardValue("10♥");
expect(tenOfHearts).toEqual(10);
});

test("should return the value Invalid card rank for value of 22", () => {
const twentyTwo = getCardValue("22");
expect(twentyTwo).toEqual("Invalid card rank.");
});
Loading