Skip to content

West Midlands | 25-ITP-May | Mustaf Asani | Module-Structuring-and -Testing-Data | Sprint 3 #679

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 4 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
20 changes: 17 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,8 +8,17 @@
// 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 === 90) {
return "Right angle";
} else if (angle < 90){// read to the end, complete line 36, then pass your test here
return "Acute angle";
} else if (angle > 90 && angle < 180) {
return "Obtuse angle";
} else if (angle === 180) {
return "Straight angle";
} else if (angle > 180 && angle < 360) {
return "Reflex angle";
}
}

// we're going to use this helper function to make our assertions easier to read
Expand Down Expand Up @@ -44,13 +53,18 @@ assertEquals(acute, "Acute angle");
// 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 straignt = getAngleType(180);
assertEquals(straignt, "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(270);
assertEquals(reflex, "Reflex angle");
18 changes: 18 additions & 0 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,11 @@

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

Choose a reason for hiding this comment

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

What happens if I give it a negative improper fraction, like -20/2?

if (numerator >= denominator) return false;
// Handle edge cases
if (denominator === 0) return false; // Denominator cannot be zero
if (numerator === 0) return true; // Zero numerator is a proper fraction
return false; // Default case for any other conditions
}

// here's our helper again
Expand Down Expand Up @@ -41,13 +46,26 @@ 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?
const zeroNumerator = isProperFraction(0, 5);
// ====> complete with your assertion
assertEquals(zeroNumerator, true);

const zeroDenominator = isProperFraction(5, 0);
// ====> complete with your assertion
assertEquals(zeroDenominator, false);

const negativeDenominator = isProperFraction(3, -2);
// ====> complete with your assertion
assertEquals(negativeDenominator, false);
16 changes: 15 additions & 1 deletion 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) {
if (rank === "A") return 11;
const rank = card.slice(0, -1); // Get the rank part of the card (everything except the last character)
if (rank === "A") {
return 11;
} else if (rank === "K" || rank === "Q" || rank === "J" || rank === "10") {
return 10;
}else if (rank >= "2" && rank <= "9") {

Choose a reason for hiding this comment

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

If I give it a strange value like "222♥" what would you expect the output to be? What actually happens?

return parseInt(rank);
}else {
return "Invalid card rank.";
}
}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -34,11 +43,14 @@ 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 kingOfDiamonds = getCardValue("K♦");
assertEquals(kingOfDiamonds, 10);

// Handle Ace (A):
// Given a card with a rank of "A",
Expand All @@ -49,3 +61,5 @@ const fiveofHearts = getCardValue("5♥");
// 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 invalidCard = getCardValue("Z♣");
assertEquals(invalidCard, "Invalid card rank.");
14 changes: 11 additions & 3 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

if (angle === 90) {
return "Right angle";
} else if (angle < 90){
return "Acute angle";
} else if (angle > 90 && angle < 180) {
return "Obtuse angle";
} else if (angle === 180) {
return "Straight angle";
} else if (angle > 180 && angle < 360) {
return "Reflex angle";
}
}


Expand Down
12 changes: 12 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 @@ -10,15 +10,27 @@ test("should identify right angle (90°)", () => {
// 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 (270°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
});
8 changes: 7 additions & 1 deletion Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (Math.abs(numerator) < Math.abs(denominator)) return true;

Choose a reason for hiding this comment

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

This is a more correct solution - you may want to use it in your earlier task

// add your completed function from key-implement here
if (Math.abs(numerator) >= Math.abs(denominator)) return false;
// Handle edge cases
if (denominator === 0) return false; // Denominator cannot be zero
if (numerator === 0) return true; // Zero numerator is a proper fraction
return false; // Default case for any other conditions
}


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 @@ -5,7 +5,20 @@ test("should return true for a proper fraction", () => {
});

// Case 2: Identify Improper Fractions:
test("should return false for an improper fraction", () => {
expect(isProperFraction(5, 3)).toEqual(false);
})

// Case 3: Identify Negative Fractions:
test("Should return true for a negative proper fraction", () => {
expect(isProperFraction(-1, 2)).toEqual(true);
})

test("Should return false for a negative improper fraction", () => {
expect(isProperFraction(-3, 2)).toEqual(false);
})

// Case 4: Identify Equal Numerator and Denominator:
test("Should return false for equal numerator and denominator", () => {
expect(isProperFraction(3, 3)).toEqual(false);
})
11 changes: 10 additions & 1 deletion Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
const rank = card.slice(0, -1); // Get the rank part of the card (everything except the last character)
if (rank === "A") {
return 11;
} else if (rank === "K" || rank === "Q" || rank === "J" || rank === "10") {
return 10;
}else if (rank >= "2" && rank <= "9") {
return parseInt(rank);
}else {
return "Invalid card rank.";
}
}
module.exports = getCardValue;
16 changes: 16 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,22 @@ test("should return 11 for Ace of Spades", () => {
});

// Case 2: Handle Number Cards (2-10):
test("Should return 5 for 5 of Hearts", () => {
const fiveofHearts = getCardValue("5♥");
expect(fiveofHearts).toEqual(5);
})
// Case 3: Handle Face Cards (J, Q, K):
test("Should return 10 for King of Diamonds", () => {
const kingOfDiamonds = getCardValue("K♦");
expect(kingOfDiamonds).toEqual(10);
});
// Case 4: Handle Ace (A):
test("Should return 11 for Ace", () => {
const aceOfClubs = getCardValue("A♣");
expect(aceOfClubs).toEqual(11);
});
// Case 5: Handle Invalid Cards:
test("Should return 'Invalid card rank.' for invalid card", () => {
const invalidCard = getCardValue("Z♣");
expect(invalidCard).toEqual("Invalid card rank.");
});
Loading