Skip to content

Sheffield| May 2025| Mayowa Fadare| Structure testing sprint 3 #633

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
26 changes: 19 additions & 7 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,35 @@ const right = getAngleType(90);
assertEquals(right, "Right angle");

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

test("should identify acute angles (e.g., 45°)", () => {
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89.9)).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"
const obtuse = getAngleType(120);
// ====> write your test here, and then add a line to pass the test in the function above

test("should identify obtuse angles (e.g., 90.1° and 179.9°)", () => {
expect(getAngleType (90.1)).toEqual("Obtuse angle");
expect(getAngleType (179.9)).toEqual("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

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"
// ====> write your test here, and then add a line to pass the test in the function above

test("should identify reflex angles (180.1° and 359.9°)", () => {
expect(getAngleType(180.1)).toEqual("Reflex angle");
expect(getAngleType (359.9)).toEqual("Reflex angle");
});
15 changes: 15 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 @@ -40,6 +40,7 @@ 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);
assertEquals(properFraction, true);
// ====> complete with your assertion

// Equal Numerator and Denominator check:
Expand All @@ -51,3 +52,17 @@ const equalFraction = isProperFraction(3, 3);

// Stretch:
// What other scenarios could you test for?
// fraction is true because the absolute value of the numerator (0) is less than the denominator (5).
assertEquals(isProperFraction (0, 5), true)

// fraction is fa;se because the absolute value of the numerator (3) is greater than the denominator (0).
assertEquals(isProperFraction(3, 0), false);

// fraction is true because the absolute value of the numerator (2) is less than the denominator (-5).
assertEquals(isProperFraction(2, -5), true);

// fraction is false because the absolute value of the numerator (-3) is greater than the denominator (-4).
assertEquals(isProperFraction(-3, -4), false);

// fraction is true because the absolute value of the numerator (-9) is less than the denominator (5).
assertEquals(isProperFraction(-9, 5), false);
26 changes: 26 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 @@ -7,6 +7,7 @@
// 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
// if (rank === "A") return 11;
function getCardValue(card) {
if (rank === "A") return 11;
}
Expand All @@ -33,19 +34,44 @@ 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);
const sevenofspades = getCardValue("7♠");
assertEquals(sevenofspades , 7);
const eightofHearts = getCardValue("8♥");
assertEquals(eightofHearts, 8);
const nineofdiamonds = getCardValue("9♦");
assertEquals(nineofdiamonds, 9);

// ====> 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 tenofSpades = getCardValue("10♠");
assertEquals(tenofSpades("10♠"), 10);
const jackofspades = getCardValue("J♠");
assertEquals(jackofspades("J♠"), 10);
const Queenofhearts = getCardValue("Q♥");
assertEquals(Queenofhearts("Q♥"), 10);
const Kingofhearts = getCardValue("K♥");
assertEquals(Kingofhearts ("K♥"), 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 AceCard = getCardValue("A");
assertEquals(AceCard ("A"), 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 invalidCards = ["Z♠", "11", "Y♠", "1♣"];
for (const card of invalidCards) {
assertEquals(error.message, "Invalid card rank");
}
19 changes: 11 additions & 8 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (angle === 90) {
return "Right angle";
// replace with your completed function from key-implement

} 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";
}
}








// 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 @@ -11,14 +11,32 @@ test("should identify right angle (90°)", () => {
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"

test("should identify acute angles (e.g., 45°)", () => {
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89.9)).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 angles (e.g., 90.1° and 179.9°)", () => {
expect(getAngleType (90.1)).toEqual("Obtuse angle");
expect(getAngleType (179.9)).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 angles (180.1° and 359.9°)", () => {
expect(getAngleType(180.1)).toEqual("Reflex angle");
expect(getAngleType (359.9)).toEqual("Reflex angle");
});
14 changes: 11 additions & 3 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
}
if (numerator < denominator) return true;}
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
} { return false; }
if (numerator < denominator) {
return true;
} if (numerator === denominator) {
return false;
} if (denominator === 0) {
return false;
}

module.exports = isProperFraction;
9 changes: 9 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,16 @@ test("should return true for a proper fraction", () => {
});

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

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

// Case 4: Identify Equal Numerator and Denominator:
test("should return false for equal numerator and denominator", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
14 changes: 13 additions & 1 deletion Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ function getCardValue(card) {
// replace with your code from key-implement
return 11;
}
module.exports = getCardValue;
function getCardValue(card) {
const rank = card.slice(0, -1); // strip off the suit emoji

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

const number = parseInt(rank);
if (!isNaN(number) && number >= 2 && number <= 9) {
return number;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does your function return the value you expected from each of the following function calls?

getCardValue("2A♠");
getCardValue("5.1♠");
getCardValue("0x02♠");

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you checked if the above function calls can return the expected value?


throw new Error("Invalid card rank");
}
39 changes: 35 additions & 4 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,39 @@ test("should return 11 for Ace of Spades", () => {
const aceofSpades = getCardValue("A♠");
expect(aceofSpades).toEqual(11);
});
// Case 2: Handle Number Cards (2-10)
test("should return 5 for 5 of Hearts", () => {
const five = getCardValue("5♥");
expect(five).toEqual(5);
});

test("should return 10 for 10 of Diamonds", () => {
const ten = getCardValue("10♦");
expect(ten).toEqual(10);
});

// Case 3: Handle Face Cards (J, Q, K)
test("should return 10 for Jack of Spades", () => {
const jack = getCardValue("J♠");
expect(jack).toEqual(10);
});

test("should return 10 for Queen of Clubs", () => {
const queen = getCardValue("Q♣");
expect(queen).toEqual(10);
});

test("should return 10 for King of Hearts", () => {
const king = getCardValue("K♥");
expect(king).toEqual(10);
});

// Case 4: Handle Ace
const AceCard = getCardValue("A");
assertEquals(AceCard ("A"), 11);

// Case 5: Handle Invalid Cards
test("should throw error for invalid card Z♠", () => {
expect(() => getCardValue("Z♠")).toThrow("Invalid card rank");
});

// 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: 13 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ function countChar(stringOfCharacters, findCharacter) {
return 5
}

module.exports = countChar;
module.exports = countChar;

function countChar(stringOfCharacters, findCharacter) {
let count = 0;
for (let char of stringOfCharacters) {
if (char === findCharacter) {
count++;
}
}
return count;
}

module.exports = countChar;
7 changes: 7 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ test("should count multiple occurrences of a character", () => {
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.

test("should return 0 if the character does not exist in the string", () => {
const str = "hello";
const char = "z";
const count = countChar(str, char);
expect(count).toEqual(0);
});
21 changes: 20 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
function getOrdinalNumber(num) {
return "1st";
}
function getOrdinalNumber(num) {
const lastDigit = num % 10;
const lastTwoDigits = num % 100;

if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
return num + "th";
}

switch (lastDigit) {
case 1:
return num + "st";
case 2:
return num + "nd";
case 3:
return num + "rd";
default:
return num + "th";
}
}

module.exports = getOrdinalNumber;
module.exports = getOrdinalNumber;
32 changes: 29 additions & 3 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@ const getOrdinalNumber = require("./get-ordinal-number");
// When the number is 1,
// Then the function should return "1st"

test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});
const getOrdinalNumber = require("./getOrdinalNumber");

test("should return 1st", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});

test("should return 2nd", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});

test("should return 3rd", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
});

test("should return 8th", () => {
expect(getOrdinalNumber(8)).toEqual("8th");
});

test("should return 19th", () => {
expect(getOrdinalNumber(19)).toEqual("19th");
});

test("should return 81st", () => {
expect(getOrdinalNumber(81)).toEqual("81st");
});

test("should return 125th", () => {
expect(getOrdinalNumber(125)).toEqual("125th");
});
8 changes: 7 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ function repeat() {
return "hellohellohello";
}

module.exports = repeat;
module.exports = repeat;

function repeat(word = "hello", times = 3) {
return word.repeat(times);
}

module.exports = repeat;
Loading