Skip to content
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
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 > 360){
return "Invalid";
}else if (angle > 0 && angle < 90){
return "Acute angle";
}else if (angle == 90){
return "Right angle";
}else if (angle < 180){
return "Obtuse angle";
}else if (angle == 180){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What's the difference between == and ===? Which one do you think is more appropriate here?

return "Straight line";
}else if (angle > 180 && angle < 360){
return "Reflex angle";
}
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -35,3 +47,18 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");

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

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

const straight = getAngleType(180);
assertEquals(straight, "Straight line");

const reflexAngle = getAngleType(215);
assertEquals(reflexAngle, "Reflex angle");

const invalid = getAngleType(380);
assertEquals(invalid, "Invalid");
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (numerator < denominator){
return true;
}else{
return 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.

I think there's a nice refactor we could do here... given that numerator < denominator already evaluates to true or false, how might you refactor this solution to not need an if/else statement and just be a single return statement?

}

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

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(2, 3), true);
assertEquals(isProperFraction(499, 500), true);
assertEquals(isProperFraction(5, 2), false);
assertEquals(isProperFraction(5, 5), false);
assertEquals(isProperFraction(1, 0), false);
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,35 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
const number = card.slice(0, -1);
const suit = card.slice(-1);
//console.log(`number is ${number}`);
//console.log(typeof suit);
//console.log(suit);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perfectly valid to use console.log to figure out the problem as we're solving it, but make sure to remove any unnecessary logs and/or comments like these for the final solution 🙂

if (suit == "♠" || suit == "♥" || suit == "♦" || suit == "♣"){
switch (number) {
case "A":
return 11;
case "J":
case "Q":
case "K":
return 10;
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
return Number(number);
default:
return "invalid";

}
}else{
return "invalid";
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -39,7 +67,19 @@ 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("A♥"), 11);
assertEquals(getCardValue("J♦"), 10);
assertEquals(getCardValue("Q♦"), 10);
assertEquals(getCardValue("K♦"), 10);
assertEquals(getCardValue("2♣"), 2);
assertEquals(getCardValue("3♣"), 3);
assertEquals(getCardValue("4♦"), 4);
assertEquals(getCardValue("5♦"), 5);
assertEquals(getCardValue("6♦"), 6);
assertEquals(getCardValue("7♦"), 7);
assertEquals(getCardValue("8♣"), 8);
assertEquals(getCardValue("9♣"), 9);

// Handling invalid cards
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,37 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

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

// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
// Test various obtuse angles, including boundary cases
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(125)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});

// Case 4: Straight angle
test(`should return "Straight angle angle" when (angle = 180)`, () => {
// Test right angles, only one case
expect(getAngleType(180)).toEqual("Straight line");
});

// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
// Test various reflex angles, including boundary cases
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(225)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});

// Case 6: Invalid angles
test(`should return "Invalid" when ( angle < 0 or angle > 360 )`, () => {
// Test various invalid angle, including boundary cases
expect(getAngleType(-1)).toEqual("Invalid");
expect(getAngleType(361)).toEqual("Invalid");
expect(getAngleType(550)).toEqual("Invalid");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,21 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Proper fraction cases
test(`should return true when numerator is smaller then denominator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(65, 67)).toEqual(true);
expect(isProperFraction(1, 1000)).toEqual(true);
expect(isProperFraction(999, 1000)).toEqual(true);
expect(isProperFraction(0, 6)).toEqual(true);
});

// Improper fraction cases
test(`should return false when numerator is bigger then denominator`, () => {
expect(isProperFraction(3, 2)).toEqual(false);
expect(isProperFraction(65, 60)).toEqual(false);
expect(isProperFraction(1000, 1)).toEqual(false);
expect(isProperFraction(2999, 1000)).toEqual(false);
expect(isProperFraction(11, 10)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@ const getCardValue = require("../implement/3-get-card-value");
// Case 1: Ace (A)
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
expect(getCardValue("A♦")).toEqual(11);
expect(getCardValue("A♠")).toEqual(11);
});

// Case 2: Face cards Jack, Queen, King (J,Q,K)
test(`Should return 10 when given a face card`, () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("J♦")).toEqual(10);
expect(getCardValue("Q♣")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
});

// Case 3: Number cards 2-10 (2,3,4,5,6,7,8,9)
test(`Should return the card value when given a number card`, () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("3♦")).toEqual(3);
expect(getCardValue("4♣")).toEqual(4);
expect(getCardValue("5♥")).toEqual(5);
expect(getCardValue("6♠")).toEqual(6);
expect(getCardValue("7♦")).toEqual(7);
expect(getCardValue("8♣")).toEqual(8);
expect(getCardValue("9♥")).toEqual(9);
});

// Case 4: Invalid card
test(`Should return 10 when given an ace card`, () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure this test description matches what the test is checking for!

expect(getCardValue("invalid")).toEqual("invalid");
expect(getCardValue("♦")).toEqual("invalid");
expect(getCardValue("4")).toEqual("invalid");
expect(getCardValue("")).toEqual("invalid");
expect(getCardValue("m")).toEqual("invalid");
expect(getCardValue("300")).toEqual("invalid");
Comment on lines +38 to +41

@Liam310 Liam310 Jul 14, 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.

In an earlier comment I asked you to consider some further invalid cases for testing. You've added some nice ones here but I think there's still one thing you haven't covered that is worth checking for. Once you've figured that out, it should be included in your Jest tests also!

});

// Suggestion: Group the remaining test data into these categories:
Expand Down
Loading