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
2 changes: 1 addition & 1 deletion Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let carPrice = "10,000";
let priceAfterOneYear = "8,543";

carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ,""));

const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
Expand Down
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");
}
26 changes: 18 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,26 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

// Ensure angle is a number and within valid bounds
if (typeof angle !== "number" || angle <= 0 || angle >= 360) {
return "Invalid angle";
}
if (angle < 90) {
return "Acute angle";
}
if (angle === 90) {
return "Right angle";
}
if (angle < 180) {
return "Obtuse angle";
}
if (angle === 180) {
return "Straight angle";
}
// Any remaining angle must be between 180 and 360 (exclusive)
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");
});
11 changes: 8 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,11 @@

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
// Check for invalid fraction (denominator cannot be zero)
if (denominator === 0) {
return false;
}
// Check if the absolute value of the numerator is less than the absolute value of the denominator
return Math.abs(numerator) < Math.abs(denominator);
}

module.exports = isProperFraction;
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);
});
15 changes: 12 additions & 3 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;
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;

// Accept only exact digits 2 through 9
if (/^[2-9]$/.test(rank)) {
return Number(rank);
}
throw new Error("Invalid card rank");
}
module.exports = getCardValue;
module.exports = getCardValue;

34 changes: 30 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 @@ -5,7 +5,33 @@ test("should return 11 for Ace of Spades", () => {
expect(aceofSpades).toEqual(11);
});

// 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:

// Case 2: Handle Number Cards (2-10)
test("should return the value of number cards (2-10)", () => {
const testCases = [
["2♣", 2],
["5♠", 5],
["10♦", 10]
];
testCases.forEach(([card, expected]) => {
expect(getCardValue(card)).toEqual(expected);
});
});

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 face cards J, Q, K", () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♣")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
});

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

10 changes: 8 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
let count = 0;
for (let char of stringOfCharacters) {
if (char === findCharacter) {
count++;
}
}
return count;
}

module.exports = countChar;
module.exports = countChar;
10 changes: 9 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/count.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// implement a function countChar that counts the number of times a character occurs in a string
const countChar = require("./count");

// Given a string str and a single character char to search for,
// When the countChar function is called with these inputs,
// Then it should:
Expand All @@ -9,6 +9,7 @@ const countChar = require("./count");
// And a character char that may occur multiple times with overlaps within str (e.g., 'a' in 'aaaaa'),
// When the function is called with these inputs,
// Then it should correctly count overlapping occurrences of char (e.g., 'a' appears five times in 'aaaaa').
const countChar = require("./count");

test("should count multiple occurrences of a character", () => {
const str = "aaaaa";
Expand All @@ -22,3 +23,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);
});
5 changes: 0 additions & 5 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js

This file was deleted.

36 changes: 29 additions & 7 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
const getOrdinalNumber = require("./get-ordinal-number");
// In this week's prep, we started implementing getOrdinalNumber

// continue testing and implementing getOrdinalNumber for additional cases
// Write your tests using Jest - remember to run your tests often for continual feedback

// Case 1: Identify the ordinal number for 1
// When the number is 1,
// Then the function should return "1st"
const getOrdinalNumber = require("./getOrdinalNumber");

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

test("returns 2nd for 2", () => {
expect(getOrdinalNumber(2)).toBe("2nd");
});

test("returns 3rd for 3", () => {
expect(getOrdinalNumber(3)).toBe("3rd");
});

test("returns 4th for 4", () => {
expect(getOrdinalNumber(4)).toBe("4th");
});

test("Handle the special case for teens (11, 12, 13)", () => {
expect(getOrdinalNumber(11)).toBe("11th");
expect(getOrdinalNumber(12)).toBe("12th");
expect(getOrdinalNumber(13)).toBe("13th");
});

test("Get the last digit to determine suffix", () => {
expect(getOrdinalNumber(21)).toBe("21st");
expect(getOrdinalNumber(22)).toBe("22nd");
expect(getOrdinalNumber(23)).toBe("23rd");
expect(getOrdinalNumber(101)).toBe("101st");
});
Loading