Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
// TODO: Implement this function
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 "Straight angle";
} else if (angle > 180 && angle < 360) {
return "Reflex angle";
} else {
return "Invalid angle";
}
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -34,4 +46,30 @@ function assertEquals(actualOutput, targetOutput) {
// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
const right = getAngleType(90);
const acute = getAngleType(66);
const obtuse = getAngleType(109);
const straight = getAngleType(180);
const reflex = getAngleType(222);
const invalid = getAngleType(366);
const boundary = getAngleType(0);
const invalidBoundary = getAngleType(360)
const acuteBoundary = getAngleType(1)
const acuteSecondBoundary = getAngleType(89)
const obtuseBoundary = getAngleType(91)
const reflexBoundary = getAngleType(181)



assertEquals(right, "Right angle");
assertEquals(acute, "Acute angle");
assertEquals(obtuse, "Obtuse angle");
assertEquals(straight, "Straight angle");
assertEquals(reflex, "Reflex angle")
assertEquals(invalid, "Invalid angle")
assertEquals(invalidBoundary, "Invalid angle")
assertEquals(acuteBoundary, "Acute angle")
assertEquals(acuteSecondBoundary, "Acute angle")
assertEquals(obtuseBoundary, "Obtuse angle")
assertEquals(reflexBoundary, "Reflex angle")


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

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
return numerator <= denominator && numerator > 0
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -31,3 +31,10 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(0, 4), false);
assertEquals(isProperFraction(5, 5), true);
assertEquals(isProperFraction(-8, 2), false);
assertEquals(isProperFraction(4, 0), false);
assertEquals(isProperFraction(0, 0), false);
assertEquals(isProperFraction(-2, -2), false)

@Liam310 Liam310 Jul 22, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you were to check the case of isProperFraction(-1, 2), what do we want to see as the answer? And would that test pass?

(Things get a little awkwardly mathsy with negative fractions, I recognise)


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

function getCardValue(card) {
// TODO: Implement this function
const removeSuit = card.slice(0, -1);
if (removeSuit === "A") {
return 11;
} else if (removeSuit === "J" || removeSuit === "Q" ||removeSuit === "K") {
return 10;
} else if (removeSuit > 1 && removeSuit < 11) {
return Number(removeSuit);
} else {
throw new Error("Error")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A great solution, very readable 👌

Just one point, you've declared let removeSuit - should this be a let or a const? In either case, why?

}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -40,15 +49,29 @@ function assertEquals(actualOutput, targetOutput) {
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);
assertEquals(getCardValue("A♠"), 11);
assertEquals(getCardValue("J♦"), 10);
assertEquals(getCardValue("7♥"), 7);
assertEquals(getCardValue("A♥"), 11);
assertEquals(getCardValue("8♥"), 8);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When writing a test suite, we want to try and cover all possible "behaviours" of our function. Here I can see you've covered:

  • Hearts
  • Spades
  • Diamonds
  • Numbered cards
  • Jacks
  • Aces

Looking at that list, what have you not covered?

assertEquals(getCardValue("Q♠"), 10);
assertEquals(getCardValue("K♦"), 10);

// Handling invalid cards
try {
getCardValue("invalid");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}

// What other invalid card cases can you think of?
try {
getCardValue("15♥");
// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,34 @@ const getAngleType = require("../implement/1-get-angle-type");

// Case 1: Acute angles
test(`should return "Acute angle" when (0 < angle < 90)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

// 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 (angle < 180, angle > 90)`, () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
expect(getAngleType(99)).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 (angle < 360, angle > 180)`, () => {
expect(getAngleType(189)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
expect(getAngleType(199)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angle" when (angle > 361, angle < 0)`, () => {
expect(getAngleType(505)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(699)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});
test(`should return true when denominator is smaller or equal to the numerator`,() =>{
expect(isProperFraction(2, 4)).toEqual(true);
expect(isProperFraction(3, 3)).toEqual(true);
expect(isProperFraction(5, 10)).toEqual(true);
expect(isProperFraction(2, 2)).toEqual(true);
});

test(`should return false when denominator is bigger than the numerator`, () => {
expect(isProperFraction(12, 4)).toEqual(false);
});

test("should return false when the numerator or denominator is not a positive number", () => {
expect(isProperFraction(5, -2)).toEqual(false);
expect(isProperFraction(-1, 0)).toEqual(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expect(isProperFraction(-1, 0)).toEqual(false);

This test case, which test does it belong in? What grouping of behaviours does it fall into?

});

Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,31 @@ test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});

// Case 2:

test(`should return 10 for face cards"`, () => {
expect(getCardValue("J♥")).toEqual(10);
expect(getCardValue("K♠")).toEqual(10);
expect(getCardValue("Q♣")).toEqual(10);
});

//Case 3:
test(`should return the numeric value of numbered cards`, () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("5♠")).toEqual(5);
expect(getCardValue("8♠")).toEqual(8);
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
// Invalid Cards

// To learn how to test whether a function throws an error as expected in Jest,
// please refer to the Jest documentation:
// https://jestjs.io/docs/expect#tothrowerror

// https://jestjs.io/docs/exåpect#tothrowerror
test(`Should not return any card should throw an error message`, () => {
expect(() => {
getCardValue("QQ♥");
}).toThrow();
});
Loading