Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
dcf9e96
write tests for 1-implement-and-rewrite-tests/implement/1-get-angle-t…
Temceo Jun 23, 2026
f83d840
Confirm that all assert tests pass for 1-implement-and-rewrite-tests/…
Temceo Jun 23, 2026
d9144d9
write tests for 1-implement-and-rewrite-tests/implement/2-is-proper-f…
Temceo Jun 23, 2026
0bfbb21
Execute code to ensure all tests pass in 1-implement-and-rewrite-test…
Temceo Jun 23, 2026
3780aff
Add additional test and check it passes to 1-implement-and-rewrite-te…
Temceo Jun 23, 2026
49049fe
write tests for 1-implement-and-rewrite-tests/implement/3-get-card-va…
Temceo Jun 23, 2026
e82177d
Write tests for 1-implement-and-rewrite-tests/implement/3-get-card-va…
Temceo Jun 24, 2026
1d526db
Update answer to 1-implement-and-rewrite-tests/implement/3-get-card-v…
Temceo Jun 25, 2026
788b662
Add jest to package.json
Temceo Jun 25, 2026
e346b17
Write jest tests for 1-get-angle-type.test.js
Temceo Jun 25, 2026
163c1d0
Write jest tests for 2-is-proper-fraction.test.js
Temceo Jun 25, 2026
bae2cd3
Update 1-implment-and-rewrite-tests/implement/3-get-card-value.js
Temceo Jun 26, 2026
d3efba2
Update 1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-ca…
Temceo Jun 27, 2026
8ab3f10
Revert changes on package.json
Temceo Jun 27, 2026
312b092
Update 1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-ca…
Temceo Jun 27, 2026
a2518fa
Add tests to 1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-…
Temceo Jun 27, 2026
75ac962
Add ace card tests to 1-implement-and-rewrite-tests/rewrite-tests-wit…
Temceo Jun 27, 2026
3b6f6f7
Correct error in invalid cards test for 1-implement-and-rewrite-tests…
Temceo Jun 27, 2026
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,21 @@

function getAngleType(angle) {
// TODO: Implement this function
let returnAngle;
if (angle > 0 && angle < 90) {
returnAngle = "Acute";
} else if (angle === 90) {
returnAngle = "Right";
} else if (angle > 90 && angle < 180) {
returnAngle = "Obtuse";
} else if (angle === 180) {
returnAngle = "Straight";
} else if (angle > 180 && angle < 360) {
returnAngle = "Reflex";
} else {
returnAngle = "Invalid";
}
return `${returnAngle} angle`;
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -34,4 +49,17 @@ 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(75);
const obtuse = getAngleType(150);
const straight = getAngleType(180);
const reflex = getAngleType(340);
let invalid = getAngleType(0);
invalid = getAngleType(360);
invalid = getAngleType(-2);

assertEquals(right, "Right angle");
assertEquals(acute, "Acute angle");
assertEquals(obtuse, "Obtuse angle");
assertEquals(straight, "Straight angle");
assertEquals(reflex, "Reflex angle");
assertEquals(invalid, "Invalid angle");

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 this last test accurately checking your invalid test cases?

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 All @@ -31,3 +33,9 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(3, 1), false);
assertEquals(isProperFraction(2, 2), false);
assertEquals(isProperFraction(5, 0), false);
assertEquals(isProperFraction(-1, 0), false);
assertEquals(isProperFraction(-2, 4), true);
assertEquals(isProperFraction(4, -2), false);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@

function getCardValue(card) {
// TODO: Implement this function
const cardRanks = "A,2,3,4,5,6,7,8,9,10,J,Q,K".split(",");
const cardSuits = "♠,♥,♦,♣".split(",");

// Throw error if card is empty
if (!card) throw new Error(`Invalid card`);

const cardSuit = card[card.length - 1];
// Throw error is card suit is not valid
if (!cardSuits.includes(cardSuit)) {
throw new Error(`Invalid card suit`);
}

const cardRank = card.slice(0, -1);
// Throw error is cardRank is not valid
if (!cardRanks.includes(cardRank)) {
throw new Error(`Invalid card rank`);
}

// Return the card value based on given rank
if (cardRank === "A") return 11;
if (["J", "Q", "K"].includes(cardRank)) return 10;
return Number(cardRank);
}

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

// Handling invalid cards
try {
getCardValue("invalid");
function assertErrors(func, errorMessage) {
try {
func();
console.error("Error was not thrown for invalid card 😢");
} catch (error) {
console.assert(
error.message.includes(errorMessage),
`Expected error: ${errorMessage}, got: ${error.message}`
);
console.log("Error thrown for invalid card 🎉");
}
}

function testInvalidCards() {
const invalidCardCases = [
["A", "Invalid card suit"],
["11♠", "Invalid card rank"],
["N♠", "Invalid card rank"],
["7K", "Invalid card suit"],
["", "Invalid card"],
];

// 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 🎉");
invalidCardCases.forEach(([card, message]) => {
console.log("-".repeat(50));
console.log(`Card: ${card}, Message: ${message}`);
assertErrors(() => getCardValue(card), message);
});
}

// What other invalid card cases can you think of?
testInvalidCards();
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,28 @@ 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(120)).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
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(340)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid" when (angle < 1 || angel > 360)`, () => {
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(-15)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ 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 false when (numerator >= denominator)`, () => {
expect(isProperFraction(2, 1)).toEqual(false);
expect(isProperFraction(2, 2)).toEqual(false);
});

test(`should treat numerator and denominator as absolute values when determining proper fractions`, () => {
expect(isProperFraction(-2, 3)).toEqual(true);
expect(isProperFraction(-7, 2)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,30 @@ 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);
expect(getCardValue("A♥")).toEqual(11);
});

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

test(`Should return number when given an a face card (>= 2 && < 10)`, () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("6♠")).toEqual(6);
expect(getCardValue("9♠")).toEqual(9);
});

test(`Should throw for invalid cards`, () => {
expect(() => getCardValue("A")).toThrowError();
expect(() => getCardValue("11♠")).toThrowError();
expect(() => getCardValue("N♠")).toThrowError();
expect(() => getCardValue("7K")).toThrowError();
expect(() => getCardValue("")).toThrowError();
});

// Suggestion: Group the remaining test data into these categories:
Expand All @@ -17,4 +40,3 @@ test(`Should return 11 when given an ace 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