diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e2..c04db492c3 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -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; diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b641..d30f2ac403 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -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; diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index ff5c532e1d..a1215792e9 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -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; diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d3..7a7ef3a977 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -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"); +}); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 7f087b2ba1..ee245a01ac 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -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); +}); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index cf7f9dae2e..ea2f939704 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -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) @@ -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 -