Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
// TODO: Implement this function
if (angle > 0 && angle < 90) {
return "Acute angle";
} else if (angle === 90) {
return "Right 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 "Invalid angle";
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -33,5 +44,10 @@ function assertEquals(actualOutput, targetOutput) {

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
assertEquals(getAngleType(45), "Acute angle");
assertEquals(getAngleType(90), "Right angle");
assertEquals(getAngleType(120), "Obtuse angle");
assertEquals(getAngleType(180), "Straight angle");
assertEquals(getAngleType(270), "Reflex angle");
assertEquals(getAngleType(-1), "Invalid angle");
assertEquals(getAngleType(360), "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@
// 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);
}




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

function getCardValue(card) {
// TODO: Implement this function
const rank = card.slice(0, -1);
const suit = card.slice(-1);
const validSuits = ["♠", "♥", "♦", "♣"];
const validRanks = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];

if (!validSuits.includes(suit) || !validRanks.includes(rank)) {
throw new Error("Invalid card");
}
if (rank === "A") {
return 11;
}
if (rank === "J" || rank === "Q" || rank === "K") {
return 10;
}
return parseInt(rank);
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand Down
Comment thread
KKtech06 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,39 @@ const getAngleType = require("../implement/1-get-angle-type");
// including boundary and invalid cases.

// Case 1: Acute angles
test(`should return "Acute angle" when (0 < angle < 90)`, () => {
// Test various acute angles, including boundary cases
test("should return 'Acute angle' when angle ∈ ]0, 90[", () => {
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

// Case 2: Right angle
test("should return 'Right angle' when angle is 90", () => {
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
test("should return 'Obtuse angle' when angle ∈ ]90, 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 is 180", () => {
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Reflex angles
test("should return 'Reflex angle' when angle ∈ ]180, 360[", () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});

// Case 6: Invalid angles
test("should return 'Invalid angle' when angle is < 0 or >= 360", () => {
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(400)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,31 @@ 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
test(`should return false when denominator is zero`, () => {
// Case 1: Proper fractions (|numerator| < |denominator|)
test("should return true when |numerator| < |denominator|", () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(3, 4)).toEqual(true);
expect(isProperFraction(0, 5)).toEqual(true);
});

// Case 2: Improper fractions (numerator >= denominator)
test("should return false when |numerator| >= |denominator|", () => {
expect(isProperFraction(2, 1)).toEqual(false);
expect(isProperFraction(4, 3)).toEqual(false);
expect(isProperFraction(5, 5)).toEqual(false);
expect(isProperFraction(-2, 1)).toEqual(false);
expect(isProperFraction(2, -1)).toEqual(false);
expect(isProperFraction(-5, -5)).toEqual(false);
});

// Case 3: Proper fractions with negative values (|numerator| < |denominator|)
test("should return true when |numerator| < |denominator| with negative values", () => {
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(1, -2)).toEqual(true);
expect(isProperFraction(-3, -4)).toEqual(true);
});

// Case 4: Denominator is zero
test("should return false when denominator is zero", () => {
expect(isProperFraction(1, 0)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,33 @@ const getCardValue = require("../implement/3-get-card-value");
// TODO: Write tests in Jest syntax to cover all possible outcomes.

// Case 1: Ace (A)
test(`Should return 11 when given an ace card`, () => {
test("Should return 11 when given an ace card", () => {
expect(getCardValue("A♠")).toEqual(11);
});

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

// Case 3: Number cards (2-10)
test("Should return the numeric value when given a number card", () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("5♠")).toEqual(5);
expect(getCardValue("10♠")).toEqual(10);
});

// Case 4: Invalid cards
test("Should throw an error when given an invalid card", () => {
expect(() => getCardValue("1♠")).toThrow("Invalid card");
expect(() => getCardValue("11♠")).toThrow("Invalid card");
expect(() => getCardValue("B♠")).toThrow("Invalid card");
expect(() => getCardValue("A")).toThrow("Invalid card");
expect(() => getCardValue("")).toThrow("Invalid card");
expect(() => getCardValue("InvalidCard")).toThrow("Invalid card");
});
// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
Expand Down
Loading