Skip to content

Manchester | ITP-May-2025 | Chukwuemeke Ajuebor | Module-Structuring-and-Testing-Data | Sprint 3 #674

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 10 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
11 changes: 10 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";
else if (angle > 0 && 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";
// read to the end, complete line 36, then pass your test here
}

Expand Down Expand Up @@ -44,13 +48,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"
const straight = getAngleType(180);
// ====> write your test here, and then add a line to pass the test in the function above
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
const reflex = getAngleType(270);
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(reflex, "Reflex angle");
40 changes: 37 additions & 3 deletions Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
// 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 (numerator === 0 && denominator === 0) return "put numbers above and below";

Choose a reason for hiding this comment

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

Stretch: if we re-order these if statements, could we reduce the number of conditions we need to check? Each condition adds complexity to our code

For example, if I check numerator === 0 first, will I need to check numerator !== 0 later?

//else if (numerator === 0) return "input non-zero above"; -- not needed as numerator can be zero
else if (denominator === 0) return "input non-zero below";
else if (numerator < denominator) return true;
else if (numerator > denominator) return false;
else if (numerator === denominator) return false;
//else if (numerator === 0 && denominator === 0) return "put numbers above and below";
// the above line of code did not work here it had to go to the top as it is a most specific case considering our function.
}

// here's our helper again
Expand Down Expand Up @@ -40,14 +47,41 @@ 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(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?
// We could test for if the numerator is zero

// Zero Numerator check:
// Input: numerator = 0, denominator = 3
// target output: true
// Explanation: Even though this gives a zero value it still returns true
//so we expect it to be true
/* const zeroNumeratorFraction = isProperFraction(0, 3);
assertEquals(zeroNumeratorFraction, "input non-zero above"); */
// test case commented out as 0/3 is not a mathematical error


// Zero Denominator check:
// Input: numerator = 3, denominator = 0
// target output: undefined
// Explanation: This gives an undefined value.
const zeroDenominatorFraction = isProperFraction(3, 0);
assertEquals(zeroDenominatorFraction, "input non-zero below");

// Zero Numerator and Zero Denominator check:
// Input: numerator = 0, denominator = 0
// target output: false
// Explanation: This will outputs false as the operation is practically impossible.
/* const zeroZeroFraction = isProperFraction(0, 0);
assertEquals(zeroZeroFraction, "put numbers above and below"); */
//we already check for zero denominator and that is enough
// as numerator can indeed be zero.
24 changes: 22 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,8 +8,19 @@
// 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;
}
let rank;
if (card.startsWith("10")) {
rank = 10;
} else {
rank = card[0];
}
if ((card.length > 3) || (card.length === 3 && !(card[0] === "1" && card[1] === "0" && isNaN(card[2]))))
return "Invalid card rank";
else if (rank === "A") return 11;
else if (rank === "K" || rank === "Q" || rank === "J" ) return 10;
else if (Number(rank) >= 2 && Number(rank) <= 10) return Number(rank);

}

// You need to write assertions for your function to check it works in different cases

Choose a reason for hiding this comment

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

Could you add this test case & see what it returns?

const tenOfHearts = getCardValue("10♥");
assertEquals(tenOfHearts, 10);

// we're going to use this helper function to make our assertions easier to read
Expand All @@ -33,12 +44,15 @@ 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♥");
assertEquals(fiveofHearts, 5);
// ====> write your test here, and then add a line to pass the test in the function above

// 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 QueenofDiamonds = getCardValue("Q♦");
assertEquals(QueenofDiamonds, 10);

// Handle Ace (A):
// Given a card with a rank of "A",
Expand All @@ -49,3 +63,9 @@ 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 seventySevenofDiamonds = getCardValue("77♦");
assertEquals(seventySevenofDiamonds, "Invalid card rank");

//Handle cards with value of ten
const tenOfHearts = getCardValue("10♥");
assertEquals(tenOfHearts, 10);
5 changes: 4 additions & 1 deletion Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement
else if (angle > 0 && 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
20 changes: 12 additions & 8 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ test("should identify right angle (90°)", () => {
// 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 (where angle < 90°)", () => {
expect(getAngleType(40)).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 (where angle > 90°)", () => {
expect(getAngleType(125)).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 (where 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 (where angle > 180°)", () => {
expect(getAngleType(225)).toEqual("Reflex angle");
});
10 changes: 8 additions & 2 deletions 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;
// add your completed function from key-implement here
if (numerator === 0 && denominator === 0) return "put numbers above and below";
//else if (numerator === 0) return "input non-zero above"; -- not needed as numerator can be zero
else if (denominator === 0) return "input non-zero below";
else if (numerator < denominator) return true;
else if (numerator > denominator) return false;
else if (numerator === denominator) return false;
//else if (numerator === 0 && denominator === 0) return "put numbers above and below";
// the above line of code did not work here it had to go to the top as it is a most specific case considering our function.
}

module.exports = isProperFraction;
19 changes: 19 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 @@ -4,8 +4,27 @@ test("should return true for a proper fraction", () => {
expect(isProperFraction(2, 3)).toEqual(true);
});

//we can write the functions that we expect to out true using .toBeTruthy()
test("should return true for a proper fraction", () => {
expect(isProperFraction(7, 11)).toBeTruthy();
});

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

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

Choose a reason for hiding this comment

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

Stretch question: this library also has .toBeTruthy() - why might we not want to use this?

Doc

});

//This type of case that outputs true can also use .toBeTruthy()
test("should return true for a negative fraction", () => {
expect(isProperFraction(-4, 9)).toBeTruthy();
});

// Case 4: Identify Equal Numerator and Denominator:
test("should return false if numerator and denominator are equal", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
13 changes: 11 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,14 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
let rank;
if (card.startsWith("10")) {
rank = "10";
} else {
rank = card[0];
}
if ((card.length > 3) || (card.length === 3 && !card.startsWith("10")) || (isNaN(rank) && !"AKQJ".includes(rank)) || rank === "0")
return "Invalid card rank";
else if (rank === "A") return 11;
else if (rank === "K" || rank === "Q" || rank === "J" ) return 10;
else if (Number(rank) >= 2 && Number(rank) <= 10) return Number(rank);
}
module.exports = getCardValue;
37 changes: 37 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,43 @@ test("should return 11 for Ace of Spades", () => {
});

// Case 2: Handle Number Cards (2-10):
test("should return number value for card 2-10", () => {

Choose a reason for hiding this comment

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

What would you expect for the input 0♦? Or X♦?

const sevenofHearts = getCardValue("7♥");
expect(sevenofHearts).toEqual(7);
});

// Case 3: Handle Face Cards (J, Q, K):
test(" should return 10 for JQK cards", () => {
const kingofDiamonds = getCardValue("K♦");
expect(kingofDiamonds).toEqual(10);
});

// Case 4: Handle Ace (A):
test(" should return 11 for Ace cards", () => {
const aceofSpades = getCardValue("A♠");
expect(aceofSpades).toEqual(11);
});

// Case 5: Handle Invalid Cards:
test(" should return a message that card is not valid", () => {
const ninetynineLove = getCardValue("99♥");
expect(ninetynineLove).toEqual("Invalid card rank");
});

// Case 6: Handle Ten Cards:
test(" should return 10", () => {
const tenOfHearts = getCardValue("10♥");
expect(tenOfHearts).toEqual(10);
});

//Case 7: more invalid cards:
test(" should return a message that card not valid", () => {
const zeroOfHearts = getCardValue("0♥");
expect(zeroOfHearts).toEqual("Invalid card rank");
});

//Case 8: more invalid cards:
test(" should return a message that card not valid", () => {
const xOfHearts = getCardValue("X♥");
expect(xOfHearts).toEqual("Invalid card rank");
});
Loading