Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -16,6 +16,32 @@

function getAngleType(angle) {
// TODO: Implement this function
// if angle is between 0 and 90 then return acute angle
if (angle > 0 && angle < 90) {
return "Acute angle";
}

// if it is exactly 90 return right angle
else if (angle === 90) {
return "Right angle";
}
// greater than 90 less than 180 return obtuse angle
else if (angle > 90 && angle < 180) {
return "Obtuse angle";
}
// if exactly 180 return straight angle
else if (angle === 180) {
return "Straight angle";
}
// greater than 180 less than 360 return reflex angle
else if (angle > 180 && angle < 360) {
return "Reflex angle";
}
// everything greater than 360 return invalid angle
else {
return "Invalid angle";
}
// return a string tells user which angle
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (denominator === 0) return false;
return Math.abs(numerator) < Math.abs(denominator);
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@

function getCardValue(card) {
// TODO: Implement this function

// if card is an ace return 11
if (card === "A") {
return 11;
}

// if card is face "J", "Q", "K"
else if (card === "J" || card === "Q" || card === "K") {
return 10;
}

// if card is a number card and card is bigger than 2 and less than 10 ("2" to "10"), should return its numerical value
else if (Number(card) >= 2 && Number(card) <= 10) {
return Number(card);
} else {
throw new Error("Error invalid card");
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -39,7 +56,7 @@ function assertEquals(actualOutput, targetOutput) {

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9"), 9);
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,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when (angle === 90)`, () => {
// Test various right angles, including boundary cases
expect(getAngleType(90)).toEqual("Right angle");
});
// Case 3: Obtuse angles
test(`should return "Obtuse angles" when (angle > 90 && < 180)`, () => {
// Test various obtuse angles, including boundary cases
expect(getAngleType(96)).toEqual("Obtuse angle");
expect(getAngleType(142)).toEqual("Obtuse angle");
expect(getAngleType(178)).toEqual("Obtuse angle");
});
// Case 4: Straight angle
test(`should return "Straight angle" when (angle === 180)`, () => {
// Test various straight angles, including boundary cases
expect(getAngleType(180)).toEqual("Straight angle");
});
// Case 5: Reflex angles
test(`should return "Reflex angles" when (angle > 180 && < 360)`, () => {
// Test various reflex angles, including boundary cases
expect(getAngleType(199)).toEqual("Reflex angle");
expect(getAngleType(245)).toEqual("Reflex angle");
expect(getAngleType(306)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angles" when (angle > 180 && < 360)`, () => {
// Test various invalid angles, including boundary cases
expect(getAngleType(360)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,18 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

test(`for positive`, () => {
expect(isProperFraction(6, 7)).toEqual(true);
expect(isProperFraction(2, 4)).toEqual(true);
});

test(`should return false for improper fractions`, () => {
expect(isProperFraction(8, 6)).toEqual(false);
expect(isProperFraction(4, 2)).toEqual(false);
});

test(`negative combinations`, () => {
expect(isProperFraction(-5, 9)).toEqual(true);
expect(isProperFraction(-2, 0)).toEqual(false);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have you tested your implementation with this script?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes and it passed

Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Mar 19, 2026

Choose a reason for hiding this comment

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

Unless you have different files on your computer, I don't see how your function can pass this test. Both the function implementation and the tests have bugs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok ill fix those bugs, thanks

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Altered function to pass failing test.

Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,35 @@ 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);
});

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

// Case 2: Face (J, Q, K)
test(`Should return 10 when given an face card`, () => {
expect(getCardValue("J")).toEqual(10);
});

test(`Should return 10 when given an face card`, () => {
expect(getCardValue("Q")).toEqual(10);
});

test(`Should return 10 when given an face card`, () => {
expect(getCardValue("K")).toEqual(10);
});
// Case 3: Number Cards (2-10)
test(`Should return numerical value when given an number card`, () => {
expect(getCardValue("5")).toEqual(5);
});
Comment on lines +29 to +32
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Supposedly a valid card is a string in this format: "5♠".

"5" (without the suit character), would be considered an invalid card.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, ive changed that.

Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Mar 19, 2026

Choose a reason for hiding this comment

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

Function implementation is correct.

This test category is supposed for valid number cards.


test(`Should return error if the card string is invalid`, () => {
expect(() => getCardValue("17")).toThrow("Error invalid card");
});

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

Loading