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 @@ -10,3 +10,53 @@ test("Classifies right angles", () => {
const right = getAngleType(90);
assert.equal(right, "Right angle");
});

test("Classifies acute angles", () => {
const acute = getAngleType(45);
assert.equal(acute, "Acute angle");
});

test("Classifies obtuse angles", () => {
const obtuse = getAngleType(120);
assert.equal(obtuse, "Obtuse angle");
});

test("Classifies straight angles", () => {
const straight = getAngleType(180);
assert.equal(straight, "Straight angle");
});

test("Classifies reflex angles", () => {
const reflex = getAngleType(270);
assert.equal(reflex, "Reflex angle");
});

test("Rejects out-of-range angles - too large", () => {
const tooLarge = getAngleType(400);
assert.equal(tooLarge, "Out of range");
});

test("Rejects out-of-range angles - negative", () => {
const negative = getAngleType(-50);
assert.equal(negative, "Out of range");
});
//
test("Rejects invalid inputs correctly - empty string", () => {
const emptyString = getAngleType("");
assert.equal(emptyString, "Invalid Input");
});

test("Rejects invalid inputs correctly - NaN value", () => {
const nanValue = getAngleType(NaN);
assert.equal(nanValue, "Invalid Input");
});

test("Rejects invalid inputs correctly - undefined ", () => {
const undefinedValue = getAngleType(undefined);
assert.equal(undefinedValue, "Invalid Input");
});

test("Rejects invalid inputs correctly - null ", () => {
const nullValue = getAngleType(null);
assert.equal(nullValue, "Invalid Input");
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,35 @@ test("Basic proper fraction", () => {
// Example: 1/2 is a proper fraction
assert.equal(isProperFraction(1, 2), true);
});

test("Improper fraction where numerator is bigger than denominator", () => {
assert.equal(isProperFraction(3, 2), false);
});

test("Proper fraction with negative denominator", () => {
assert.equal(isProperFraction(1, -2), true);
});

test("Proper fraction with negative numerator", () => {
assert.equal(isProperFraction(-2, 4), true);
});

test("Proper fraction with both negatives where numerator is smaller", () => {
assert.equal(isProperFraction(-2, -4), true);
});

test("Proper fraction with both negatives where numerator is bigger", () => {
assert.equal(isProperFraction(-3, -2), false);
});

test("Improper fraction with equal values", () => {
assert.equal(isProperFraction(2, 2), false);
});

test("Proper fraction with zero numerator", () => {
assert.equal(isProperFraction(0, 4), true);
});

test("Improper fraction with zero denominator", () => {
assert.equal(isProperFraction(4, 0), false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,64 @@ import { getCardValue } from "../implement/3-get-card-value.js";

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.

// test("Valid single-digit card", () => {
// assert.equal(getCardValue("9♠"), 9);
// });

// test("Arbitrary non-card string", () => {
// assert.throws(
// () => getCardValue("invalid"),
// /Expected a number followed by a suit, but got "invalid"/
// );
// });

test("Valid single-digit card", () => {
assert.equal(getCardValue("9♠"), 9);
assert.equal(getCardValue("2♠"), 2);
});

test("Arbitrary non-card string", () => {
assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error");
test("Valid double-digit card", () => {
assert.equal(getCardValue("10♥"), 10);
});
test("Valid king card", () => {
assert.equal(getCardValue("Q♣"), 10);
});
test("Valid queen card", () => {
assert.equal(getCardValue("K♠"), 10);
});
test("Valid jack card", () => {
assert.equal(getCardValue("J♦"), 10);
});
test("Valid ace card", () => {
assert.equal(getCardValue("A♠"), 11);
});

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

test("No suit symbol", () => {
assert.throws(
() => getCardValue("A"),
Error,
"Should throw an error for card without suit"
);
});

test("Invalid number", () => {
assert.throws(
() => getCardValue("0"),
Error,
"Should throw an error for card with invalid number"
);
});
test("Empty input", () => {
assert.throws(
() => getCardValue(""),
Error,
"Should throw an error for empty input"
);
});
test("Any other invalid input", () => {
assert.throws(
() => getCardValue("10♥♥"),
Error,
"Should throw an error for an invalid input"
);
});
19 changes: 17 additions & 2 deletions implement-and-rewrite-tests/implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

export function getAngleType(angle) {
// TODO: Implement this function

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 do you think happens when a function is declared twice, once at the top and again right inside itself without the inner one ever being called?

@ausiejute ausiejute Oct 12, 2026 •

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.

I had to have a read about it and it seems that the function would be redefined inside of itself resulting in the inner function being called instead, but only if it needed to be a recursive one. In this situation, it would look confusing, but would still do the intended job.
However, I think there might have been a misunderstanding with the diff. I only changed the function declaration/export style slightly, so the original declaration in red was replaced by the implementation in green; the function isn't declared twice. I wondered about this because a similar comment was added to another task (implement-isProperFraction) on a function that was also in the deleted code. Could you clarify if I'm missing something?

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 happens if someone passes a non-number like "90" or null here? Should we add validation

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.

Good point. I did not take that into consideration. Passing a regular string would return an "invalid angle", but an empty one or null would not

function getAngleType(angle) {
if (isNaN(angle) || angle == null || angle === "") return `Invalid Input`;

if (angle === 90) {
return `Right angle`;
} else if (angle >= 0 && angle < 90) {
return `Acute 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`;
}
return `Out of range`;
}

export { getAngleType };
6 changes: 4 additions & 2 deletions implement-and-rewrite-tests/implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

export function isProperFraction(numerator, denominator) {
// TODO: Implement this function

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks like this function is declared twice here. What do you think happens to that inner function since it's never called

@ausiejute ausiejute Oct 12, 2026 •

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.

I changed the function declaration/export style slightly and if you view the file it's more clear that the function has been declared once

function isProperFraction(numerator, denominator) {
return Math.abs(numerator) < Math.abs(denominator);
}

export { isProperFraction };
36 changes: 34 additions & 2 deletions implement-and-rewrite-tests/implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just like the other files, this function is declared twice. What happens to the inner function since it isn't exported or called

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.

once again, the function is declared once.. The export statement simply makes that existing function available to other modules; it does not declare another function or create an inner function. Your comments are written on the deleted sections

function getCardValue(card) {
if (card == "") {
throw new Error(`Missing a specific number and specific suit symbol`);
}
const cardRank = card.slice(0, -1);
const suit = card.slice(-1);

if (!["♠", "♥", "♦", "♣"].includes(suit)) {
throw new Error(`Missing a specific suit symbol`);
}

if (cardRank == "A") {
return 11;
}
if (cardRank == "J" || cardRank == "K" || cardRank == "Q") {
return 10;
}
if (
cardRank == "2" ||
cardRank == "3" ||
cardRank == "4" ||
cardRank == "5" ||
cardRank == "6" ||
cardRank == "7" ||
cardRank == "8" ||
cardRank == "9" ||
cardRank == "10"
) {
return Number(cardRank);
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The instructions above mention that an invalid card string should throw an error. How does returning the string "invalid" compare to throwing an error

@ausiejute ausiejute Oct 12, 2026 •

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.

returning the string "invalid" would still allow the program to continue running without interruption, whereas throwing an error indicates a more serious issue that requires immediate attention and handling

Edit: I see now that some misunderstandings happened due to us looking at different versions of the file

throw new Error(`Missing a specific number and specific suit symbol`);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is there any debug logging at the bottom of the file that we should remove before finalizing?

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.

sorry I couldn't find any

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is there any debug logging (console.log) at the bottom of the file that we should remove before finalizing or committing our code?

@ausiejute ausiejute Oct 12, 2026 •

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.

function getCardValue(card) {
  // implementation
}

export { getCardValue };

export { getCardValue };
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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(91)).toEqual("Obtuse angle");
expect(getAngleType(135)).toEqual("Obtuse angle");
expect(getAngleType(179)).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
// Case 6: Invalid angles
test(`should return "Reflex angle" when (180 < angle < 360 )`, () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
// Case 6: Out of range angles
test(`should return "Out of range" when (angle < 0 || angle > 360)`, () => {
expect(getAngleType(-1)).toEqual("Out of range");
expect(getAngleType(361)).toEqual("Out of range");
});
// Case 7: Invalid inputs
test(`should return "Invalid Input" when (isNaN(angle) || angle == null || angle === "")`, () => {
expect(getAngleType(NaN)).toEqual("Invalid Input");
expect(getAngleType(null)).toEqual("Invalid Input");
expect(getAngleType("")).toEqual("Invalid Input");
expect(getAngleType(undefined)).toEqual("Invalid Input");
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,35 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js";
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

test(`should return true when numerator is zero`, () => {
expect(isProperFraction(0, 1)).toEqual(true);
});

test(`should return true when numerator is less than denominator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

test(`should return false when numerator is more than denominator`, () => {
expect(isProperFraction(3, 2)).toEqual(false);
});

test(`should return true when denominator is negative`, () => {
expect(isProperFraction(1, -2)).toEqual(true);
});

test(`should return true when nominator is negative`, () => {
expect(isProperFraction(-2, 4)).toEqual(true);
});

test(`should return true with both negatives where numerator is smaller`, () => {
expect(isProperFraction(-2, -4)).toEqual(true);
});

test(`should return false with both negatives where numerator is bigger`, () => {
expect(isProperFraction(-3, -2)).toEqual(false);
});

test(`should return false with equal values`, () => {
expect(isProperFraction(2, 2)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,52 @@ test(`Should return 11 when given an ace card`, () => {
// 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
// -----number cards------

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

GREAT WORK HERE!
but notice how all the number card tests (2 through 9) follow the exact same pattern. Is there a built-in Jest feature (like test.each) we could use here to keep our tests DRY (Do not repeat yourself) and avoid repeating code

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! it's great to know how to avoid repeating the code

test.each([
{ card: "2♥", value: 2 },
{ card: "3♣", value: 3 },
{ card: "4♦", value: 4 },
{ card: "5♠", value: 5 },
{ card: "6♦", value: 6 },
{ card: "7♥", value: 7 },
{ card: "8♠", value: 8 },
{ card: "9♥", value: 9 },
{ card: "10♣", value: 10 },
])("Should return $value when given a $card card", ({ card, value }) => {
expect(getCardValue(card)).toEqual(value);
});
// -----remaining face cards-----
test(`Should return 10 when given a jack card`, () => {
expect(getCardValue("J♥")).toEqual(10);
});
test(`Should return 10 when given a king card`, () => {
expect(getCardValue("K♣")).toEqual(10);
});
test(`Should return 10 when given a queen card`, () => {
expect(getCardValue("Q♥")).toEqual(10);
});
// -----invalid cards-----
test("Should throw an error for card without suit", () => {
expect(() => getCardValue("A")).toThrow("Missing a specific suit symbol");
});

test("Should throw an error for card with invalid number", () => {
expect(() => getCardValue("0♥")).toThrow(
"Missing a specific number and specific suit symbol"
);
});

test("Should throw an error for empty input", () => {
expect(() => getCardValue("")).toThrow(
"Missing a specific number and specific suit symbol"
);
});

test("Should throw an error for an invalid input", () => {
expect(() => getCardValue("J♥♥")).toThrow(
"Missing a specific number and specific suit symbol"
);
});
Loading