Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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,37 @@

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";
}

// if it is 360 then it is a full rotation
else if (angle === 360) {
return "Full rotation";
}
// everything greater than 360 rand less than 0 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 All @@ -35,3 +66,18 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");

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

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

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

const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");

const invalid = getAngleType(200);
assertEquals(invalid, "Invalid angle");
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 @@ -22,7 +22,32 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
const suits = ["♠", "♥", "♦", "♣"]; // valid card suits

const suit = card.slice(-1); // gives me the last character
const rank = card.slice(0, -1); // gets beginning character up to (not including) the last character

if (!suits.includes(suit)) {
throw new Error("Error invalid 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,39 @@ 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
// Case 6: Invalid 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: Full rotation
test("returns full rotation for 360 degrees (angle === 360))", () => {
expect(getAngleType(360)).toBe("Full rotation");
});
// Case 7: Invalid angles
test(`should return "Invalid angles" when (angle >360)`, () => {
// Test various invalid angles, including boundary cases
expect(getAngleType(400)).toEqual("Invalid angle");
});
// Case 8: Invalid angles
test(`should return "Invalid angles" when (angle <0)`, () => {
expect(getAngleType(-7)).toBe("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,43 @@ 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
// Special case: denominator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Case 2: Proper fractions
// the numerator is smaller than the denominator, so the fraction is a proper fraction
test(`should return true when |numerator| < |denominator|`, () => {
expect(isProperFraction(6, 7)).toEqual(true);
expect(isProperFraction(2, 4)).toEqual(true);
});

// Case 3: Improper fractions
// numerator is bigger than denominator, so the fraction is not proper
test("should return false when numerator is bigger than denominator", () => {
expect(isProperFraction(8, 6)).toEqual(false);
expect(isProperFraction(4, 2)).toEqual(false);
});

// Case 4: Negative numbers
// numerator or denominator is negative, but function compares absolute values
test("should return correct result when numerator or denominator is negative", () => {
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.

Could consider combine this into case 2. Otherwise the description does not quite describe the tests in this category.

You could also consider use the notations |...| in the descriptions of improper fractions.

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.

Are the changes what you was expecting?

Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Mar 18, 2026

Choose a reason for hiding this comment

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

"correct result" is a bit vague. Ideally it should indicate what the correct result is.

What I meant in my previous comment was, you could test both positive and negative values in the test described as
should return true when |numerator| < |denominator|

If you prefer to test positive and mixed cases separately, you could consider:
should return true when |numerator| < |denominator| (positive numerator and denominator)
should return true when |numerator| < |denominator| (negative numerator or denominator)


// Case 5: Numerator equals denominator fraction equals 1, so it is not proper
test("should return false when numerator is equal to denominator", () => {
expect(isProperFraction(6, 6)).toEqual(false);
});

// Case 6: Numerator just less than denominator fraction is slightly below 1, so it is proper
test("should return true when numerator is just less than denominator", () => {
expect(isProperFraction(2, 3)).toEqual(true);
});

// Case 7: Numerator greater than denominator fraction is slightly above 1, so it is not proper
test("should return false when numerator is greater than denominator", () => {
expect(isProperFraction(6, 5)).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 @@ -14,7 +14,27 @@ test(`Should return 11 when given an ace card`, () => {
// 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