Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1b080b7
I implemented the getAngleType function using if.....elseif
Mona-Eltantawy Mar 14, 2026
95c31a0
I wrote a test to cover all cases include boundary and out of the ra…
Mona-Eltantawy Mar 14, 2026
6051722
I implemented the isProperFraction function using if...else statement.
Mona-Eltantawy Mar 14, 2026
ab68b5a
I wrote case tests to cover proper and inproper fractions include neg…
Mona-Eltantawy Mar 14, 2026
573b24f
I implimented the getCardVlue function, wrote assert tests and execut…
Mona-Eltantawy Mar 14, 2026
f0d0324
wrapped all invalid cards in try-catch
Mona-Eltantawy Mar 14, 2026
0ab5c67
I wrote tests in jest syntax to cover all the angle cases including b…
Mona-Eltantawy Mar 14, 2026
d4bdddd
added special case fration 1,0 to the assert test cases.
Mona-Eltantawy Mar 15, 2026
447f5f2
added assert test for both negative numbers.
Mona-Eltantawy Mar 15, 2026
b215ef8
I wrote tests for the diffrent fraction cases using Jest in this file
Mona-Eltantawy Mar 15, 2026
d466014
I Wrote tests in Jest syntax to cover all possible outcomes for the g…
Mona-Eltantawy Mar 15, 2026
17f285a
implemented the function countChar that counts the number of times a …
Mona-Eltantawy Mar 15, 2026
665ebca
I implimented a function to get ordinal number for different ordinal …
Mona-Eltantawy Mar 15, 2026
ecc3f99
created extra test cass for the getOrdinalNumber fraction
Mona-Eltantawy Mar 15, 2026
f265055
I implemented a function for the ordinal number cases
Mona-Eltantawy Mar 17, 2026
f012a52
I implemented repeatStr function.
Mona-Eltantawy Mar 17, 2026
5d0e895
I wrote different test cases to handel repeating string for times mor…
Mona-Eltantawy Mar 17, 2026
866a426
reedited the function.
Mona-Eltantawy Mar 17, 2026
c8ef645
I removed the console.log (greetingStr) code because it is unreachabl…
Mona-Eltantawy Mar 17, 2026
2b00771
I removed the capitalisedPets variable as it unused code.
Mona-Eltantawy Mar 17, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
if (angle > 0 && angle < 90) {
return 'Acute angle';
}
else if (angle===90) {
return 'Right angle';
}
else if ( angle > 90 && angle < 180){
return 'Obtuse angle';
}
else if( angle === 180) {
return 'Stright angle';
}
else if (angle > 180 && angle < 360) {
return 'Reflex angle';
}
else {return 'Invalid angle';}

// TODO: Implement this function
}

Expand All @@ -33,5 +50,33 @@ function assertEquals(actualOutput, targetOutput) {

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
// const right = getAngleType(90);
// assertEquals(right, "Right angle");
assertEquals (getAngleType(90), "Right angle");

// const acute = getAngleType(45);
// assertEquals(acute, "Acute angle");
assertEquals (getAngleType(45),"Acute angle");

// const obtuse = getAngleType(120);
// assertEquals(obtuse, "Obtuse angle");
assertEquals (getAngleType(120),"Obtuse angle");

// const stright = getAngleType(180);
// assertEquals(stright, "Stright angle");
assertEquals (getAngleType(180),"Stright angle");
// const reflex = getAngleType(270);
// assertEquals(reflex, "Reflex angle");
assertEquals (getAngleType(270),"Reflex angle");

// const invalid = getAngleType(360);
// assertEquals(invalid, "Invalid angle");
assertEquals (getAngleType(360),"Invalid angle");
//Boundary cases
// const invalid = getAngleType(0);
// assertEquals(invalid, "Invalid angle");
assertEquals (getAngleType(0),"Invalid angle");
//Outside range
// const invalid = getAngleType(-10 , 400);
// assertEquals(invalid, "Invalid angle");
assertEquals (getAngleType(-10 , 400),"Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
// execute the code to ensure all tests pass.

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

// TODO: Implement this function
}

Expand All @@ -31,3 +36,19 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
// inproper fraction:
assertEquals (isProperFraction(5, 3), false );

// equal numbers
assertEquals (isProperFraction(4, 4), false );

// negative numbers
assertEquals (isProperFraction(-2, 4), true );
assertEquals (isProperFraction(5, -4), false );
assertEquals (isProperFraction (-3,-5), false);

// special case
assertEquals(isProperFraction(1,0) , false);

assertEquals (isProperFraction (0,5), true);

Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,31 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
const suit = card.slice(-1);
const rank = card.slice(0, -1);

if (suit !== "♠" && suit !== "♥" && suit !== "♦" && suit !== "♣") {
throw new Error("Invalid card");
}

if (rank === "A") {
return 11;
}

if (rank === "J" || rank === "Q" || rank === "K") {
return 10;
}

if (rank >= "2" && rank <= "10") {
return Number(rank);
}

throw new Error("Invalid card");
}

// TODO: Implement this function


// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getCardValue;
Expand All @@ -40,6 +62,16 @@ function assertEquals(actualOutput, targetOutput) {
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);
assertEquals(getCardValue("2♠"), 2);
assertEquals(getCardValue("10♦"), 10);

// Face cards
assertEquals(getCardValue("J♣"), 10);
assertEquals(getCardValue("Q♥"), 10);
assertEquals(getCardValue("K♦"), 10);

// Ace
assertEquals(getCardValue("A♠"), 11);

// Handling invalid cards
try {
Expand All @@ -49,4 +81,15 @@ try {
console.error("Error was not thrown for invalid card");
} catch (e) {}


// What other invalid card cases can you think of?

const invalidCards = ["invalid", "1♠", "B♣", "10?", "Z♠"];
for (const card of invalidCards) {
try {
getCardValue(card);
console.error(`Error was not thrown for invalid card: ${card}`);
} catch (e) {
// Expected error, do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,35 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when (angle=== 90)`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
test (`should return "Obtuse angle" when (90 < angle < 180)` ,() =>{

expect(getAngleType(95)).toEqual("Obtuse angle");
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(100)).toEqual("Obtuse angle");
});

// Case 4: Straight angle
test (`should return "Straight angle" when ( angle === 180)` ,() =>{

expect(getAngleType(180)).toEqual("Straight angle");

});
// Case 5: Reflex angles
test (`should return "Reflex angle" when (180 < angle < 360)` ,() =>{

expect(getAngleType(190)).toEqual("Reflex angle");
expect(getAngleType(300)).toEqual("Reflex angle");
expect(getAngleType(200)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test (`should return "Invalid angle" when (angle <= 0 or angle > 360)` ,() => {

expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(400)).toEqual("Invalid angle");
expect(getAngleType(-10)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,42 @@
// We will use the same function, but write tests for it using Jest in this file.
const isProperFraction = require("../implement/2-is-proper-fraction");

// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.

// Special case: numerator is zero
test(`should return false when denominator is zero`, () => {
// denominator is zero
test("should return false when denominator is zero", () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// proper fraction (numerator < denominator)
test("should return true when numerator < denominator", () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

// improper fraction (numerator > denominator)
test("should return false when numerator > denominator", () => {
expect(isProperFraction(5, 3)).toEqual(false);
});

// equal numbers
test("should return false when numerator === denominator", () => {
expect(isProperFraction(4, 4)).toEqual(false);
});

// numerator is zero
test("should return true when numerator is zero and denominator is positive", () => {
expect(isProperFraction(0, 5)).toEqual(true);
});

// negative numerator
test("should return false when numerator is negative", () => {
expect(isProperFraction(-2, 4)).toEqual(false);
});

// negative denominator
test("should return false when denominator is negative", () => {
expect(isProperFraction(5, -4)).toEqual(false);
});

// both negative
test("should return false when both numerator and denominator are negative", () => {
expect(isProperFraction(-3, -5)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});


// Case 2: Number Cards (2–10)
test("Should return the numeric value for number cards", () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("5♥")).toEqual(5);
expect(getCardValue("9♦")).toEqual(9);
expect(getCardValue("10♣")).toEqual(10);
});

// Case 3: Face Cards (J, Q, K)
test("Should return 10 for face cards", () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♦")).toEqual(10);
});

// Case 4: Invalid Cards
test("Should throw an error for invalid cards", () => {
expect(() => getCardValue("1♠")).toThrowError();
expect(() => getCardValue("B♣")).toThrowError();
expect(() => getCardValue("10?")).toThrowError();
expect(() => getCardValue("invalid")).toThrowError();
});



// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
Expand Down
6 changes: 4 additions & 2 deletions Sprint-3/2-practice-tdd/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
function countChar(str, char) {

return str.split(char).length -1;
}

console.log(countChar('lol', 'a'));
module.exports = countChar;
10 changes: 8 additions & 2 deletions Sprint-3/2-practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function getOrdinalNumber(num) {
return "1st";
function getOrdinalNumber(n) {
if (n % 100 >= 11 && n % 100 <= 13) return n + "th";

if (n % 10 === 1) return n + "st";
if (n % 10 === 2) return n + "nd";
if (n % 10 === 3) return n + "rd";

return n + "th";
}

module.exports = getOrdinalNumber;
15 changes: 15 additions & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ const getOrdinalNumber = require("./get-ordinal-number");
// Case 1: Numbers ending with 1 (but not 11)
// When the number ends with 1, except those ending with 11,
// Then the function should return a string by appending "st" to the number.
// Case 1: numbers ending with 1 (except 11)
test("should append 'st' for numbers ending with 1, except those ending with 11", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(131)).toEqual("131st");
});

// Case 2: numbers ending with 2 (except 12)
test("should append 'nd' for numbers ending with 2, except those ending with 12", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
expect(getOrdinalNumber(142)).toEqual("142nd");
});

// Case 3: numbers ending with 3 (except 13)
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(143)).toEqual("143rd");
});
6 changes: 4 additions & 2 deletions Sprint-3/2-practice-tdd/repeat-str.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function repeatStr() {
return "hellohellohello";
function repeatStr(str, count) {
if( count >= 0 )
{return str.repeat (count)};
else { return 'invalid count'};
}

module.exports = repeatStr;
20 changes: 18 additions & 2 deletions Sprint-3/2-practice-tdd/repeat-str.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,29 @@ test("should repeat the string count times", () => {
// Given a target string `str` and a `count` equal to 1,
// When the repeatStr function is called with these inputs,
// Then it should return the original `str` without repetition.

test("should repeat the string count times", () => {
const str = "hello";
const count = 1;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("hello");
});
// Case: Handle count of 0:
// Given a target string `str` and a `count` equal to 0,
// When the repeatStr function is called with these inputs,
// Then it should return an empty string.

test("should repeat the string count times", () => {
const str = "hello";
const count = 0;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual(" ");
});
// Case: Handle negative count:
// Given a target string `str` and a negative integer `count`,
// When the repeatStr function is called with these inputs,
// Then it should throw an error, as negative counts are not valid.
test("should repeat the string count times", () => {
const str = "hello";
const count = -1;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("invalid count");
});
3 changes: 1 addition & 2 deletions Sprint-3/3-dead-code/exercise-1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

// Find the instances of unreachable and redundant code - remove them!
// The sayHello function should continue to work for any reasonable input it's given.

let testName = "Jerry";
const greeting = "hello";

function sayHello(greeting, name) {
const greetingStr = greeting + ", " + name + "!";
return `${greeting}, ${name}!`;
console.log(greetingStr);
}

testName = "Aman";
Expand Down
4 changes: 0 additions & 4 deletions Sprint-3/3-dead-code/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable.

const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
const capitalisedPets = pets.map((pet) => pet.toUpperCase());
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");

function logPets(petsArr) {
petsArr.forEach((pet) => console.log(pet));
}

function countAndCapitalisePets(petsArr) {
const petCount = {};
Expand Down
Loading