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,9 +15,18 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
// TODO: Implement this function
if (angle <= 0 || angle >= 360) return "Invalid angle";

if (angle < 90) return "Acute angle";
if (angle === 90) return "Right angle";
if (angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";

return "Reflex angle";
}

module.exports = getAngleType;

// The line below allows us to load the getAngleType function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getAngleType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (denominator === 0) return false;

return Math.abs(numerator) < Math.abs(denominator);
}

module.exports = isProperFraction;

// The line below allows us to load the isProperFraction function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = isProperFraction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,38 @@
// execute the code to ensure all tests pass.

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

const rank = card.slice(0, -1);
const suit = card.slice(-1);

if (!ranks.includes(rank) || !suits.includes(suit)) {
throw new Error("Invalid card");
}

if (rank === "A") return 11;
if (["J", "Q", "K"].includes(rank)) return 10;

return Number(rank);
}

module.exports = getCardValue;

// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getCardValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,29 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when angle is 90`, () => {
expect(getAngleType(90)).toBe("Right angle");
});
// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
expect(getAngleType(91)).toBe("Obtuse angle");
expect(getAngleType(120)).toBe("Obtuse angle");
expect(getAngleType(179)).toBe("Obtuse angle");
});
// Case 4: Straight angle
test(`should return "Straight angle" when angle is 180`, () => {
expect(getAngleType(180)).toBe("Straight angle");
});
// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
expect(getAngleType(181)).toBe("Reflex angle");
expect(getAngleType(270)).toBe("Reflex angle");
expect(getAngleType(359)).toBe("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angle" for angles <= 0 or >= 360`, () => {
expect(getAngleType(0)).toBe("Invalid angle");
expect(getAngleType(-10)).toBe("Invalid angle");
expect(getAngleType(360)).toBe("Invalid angle");
expect(getAngleType(1000)).toBe("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,31 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Proper fractions (true cases)
test("should return true for proper fractions", () => {
expect(isProperFraction(1, 2)).toBe(true);
expect(isProperFraction(2, 3)).toBe(true);
expect(isProperFraction(-1, 2)).toBe(true);
expect(isProperFraction(1, -2)).toBe(true);
});

// Improper fractions (false cases)
test("should return false for improper fractions", () => {
expect(isProperFraction(2, 1)).toBe(false);
expect(isProperFraction(5, 3)).toBe(false);
expect(isProperFraction(-5, 3)).toBe(false);
expect(isProperFraction(3, -2)).toBe(false);
});

// Equal numerator and denominator
test("should return false when numerator equals denominator", () => {
expect(isProperFraction(1, 1)).toBe(false);
expect(isProperFraction(-4, -4)).toBe(false);
});

// Invalid case: denominator is zero
test("should return false when denominator is zero", () => {
expect(isProperFraction(1, 0)).toBe(false);
expect(isProperFraction(-5, 0)).toBe(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});

// Case 2: Number cards (2–10)
test("should return numeric value for number cards", () => {
expect(getCardValue("2♠")).toBe(2);
expect(getCardValue("5♥")).toBe(5);
expect(getCardValue("10♦")).toBe(10);
expect(getCardValue("7♣")).toBe(7);
});

// Case 3: Face cards
test("should return 10 for face cards", () => {
expect(getCardValue("J♠")).toBe(10);
expect(getCardValue("Q♥")).toBe(10);
expect(getCardValue("K♦")).toBe(10);
expect(getCardValue("J♣")).toBe(10);
});

// Case 4: Invalid rank
test("should throw error for invalid rank", () => {
expect(() => getCardValue("1♠")).toThrow();
expect(() => getCardValue("11♠")).toThrow();
expect(() => getCardValue("Z♠")).toThrow();
});

// Case 5: Invalid suit
test("should throw error for invalid suit", () => {
expect(() => getCardValue("A★")).toThrow();
expect(() => getCardValue("10X")).toThrow();
expect(() => getCardValue("5?")).toThrow();
});

// Case 6: Malformed input
test("should throw error for malformed card strings", () => {
expect(() => getCardValue("")).toThrow();
expect(() => getCardValue("♠A")).toThrow();
expect(() => getCardValue("A♠♠")).toThrow();
expect(() => getCardValue("10")).toThrow();
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
Expand All @@ -17,4 +55,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