From c0f5e98958362a875f0a4e69800cda97a75389f0 Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Wed, 4 Mar 2026 12:27:17 +0000 Subject: [PATCH 1/5] Sprint 3 implement functions and tests --- .../implement/1-get-angle-type.js | 40 +++++++++++++++ .../implement/2-is-proper-fraction.js | 30 ++++++++++++ .../implement/3-get-card-value.js | 49 ++++++++++++++++++- 3 files changed, 118 insertions(+), 1 deletion(-) 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 9e05a871e..cb26378c2 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 @@ -16,6 +16,20 @@ 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"; + } else { + return "Invalid angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. @@ -35,3 +49,29 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +// Acute angle test +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +// Obtuse angle test +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + +// Straight angle test +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +// Reflex angle test +const reflex = getAngleType(270); +assertEquals(reflex, "Reflex angle"); + +// Boundary tests +assertEquals(getAngleType(1), "Acute angle"); +assertEquals(getAngleType(359), "Reflex angle"); + +// Invalid angle tests +assertEquals(getAngleType(0), "Invalid angle"); +assertEquals(getAngleType(360), "Invalid angle"); +assertEquals(getAngleType(-10), "Invalid angle"); +assertEquals(getAngleType(500), "Invalid angle"); \ No newline at end of file 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 970cb9b64..6ddba8c47 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 @@ -12,6 +12,16 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + + if (denominator === 0) { + return false; + } + + if (Math.abs(numerator) < Math.abs(denominator)) { + return true; + } + + return false; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +41,23 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +// numerator smaller than denominator +assertEquals(isProperFraction(3, 4), true); + +// numerator equal to denominator (not proper) +assertEquals(isProperFraction(5, 5), false); + +// numerator larger than denominator +assertEquals(isProperFraction(7, 3), false); + +// numerator is zero +assertEquals(isProperFraction(0, 5), true); + +// denominator is zero (invalid) +assertEquals(isProperFraction(1, 0), false); + +// negative numbers +assertEquals(isProperFraction(-1, 2), true); +assertEquals(isProperFraction(1, -2), true); +assertEquals(isProperFraction(-3, -2), false); \ No newline at end of file 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 c7559e787..83708952f 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 @@ -23,6 +23,30 @@ function getCardValue(card) { // TODO: Implement this function + + const suits = ["♠", "♥", "♦", "♣"]; + + if (typeof card !== "string" || card.length < 2) { + throw new Error("Invalid card"); + } + + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + if (!suits.includes(suit)) { + throw new Error("Invalid card"); + } + + if (rank === "A") return 11; + if (rank === "J" || rank === "Q" || rank === "K") return 10; + + const numberValue = Number(rank); + + if (numberValue >= 2 && numberValue <= 10) { + return numberValue; + } + + throw new Error("Invalid card"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -41,6 +65,18 @@ function assertEquals(actualOutput, targetOutput) { // Examples: assertEquals(getCardValue("9♠"), 9); +// Ace +assertEquals(getCardValue("A♠"), 11); + +// Face cards +assertEquals(getCardValue("J♥"), 10); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("K♣"), 10); + +// Number cards +assertEquals(getCardValue("2♠"), 2); +assertEquals(getCardValue("10♥"), 10); + // Handling invalid cards try { getCardValue("invalid"); @@ -49,4 +85,15 @@ try { console.error("Error was not thrown for invalid card"); } catch (e) {} -// What other invalid card cases can you think of? +// More invalid cases +try { + getCardValue("11♠"); + console.error("Error was not thrown for invalid card"); +} catch (e) {} + +try { + getCardValue("A"); + console.error("Error was not thrown for invalid card"); +} catch (e) {} + +// What other invalid card cases can you think of? \ No newline at end of file From 06c3aa15734b306c31c1bf03147a57364dffa681 Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Wed, 15 Apr 2026 16:03:43 +0100 Subject: [PATCH 2/5] Fix: strict validation for card values (prevent invalid numeric formats) --- .../implement/3-get-card-value.js | 11 ++++++----- package.json | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) 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 83708952f..7a0045c63 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 @@ -38,14 +38,15 @@ function getCardValue(card) { } if (rank === "A") return 11; - if (rank === "J" || rank === "Q" || rank === "K") return 10; + if (["J", "Q", "K"].includes(rank)) return 10; - const numberValue = Number(rank); - - if (numberValue >= 2 && numberValue <= 10) { - return numberValue; + const validNumbers = ["2", "3", "4", "5", "6", "7", "8", "9", "10"]; + + if (!validNumbers.includes(rank)) { + return Number(rank); } + throw new Error("Invalid card"); } diff --git a/package.json b/package.json index 0657e22dd..87d27ab8f 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "keywords": [], "author": "Code Your Future", "license": "ISC", - "dependencies": { - "jest": "^29.7.0" + "devDependencies": { + "jest": "^30.2.0" } -} \ No newline at end of file +} From b1be44396a87296622b48b8bff9c1045044de16f Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Fri, 17 Apr 2026 15:32:39 +0100 Subject: [PATCH 3/5] Updated tests --- .../implement/1-get-angle-type.js | 82 ++++-------------- .../implement/2-is-proper-fraction.js | 58 +------------ .../implement/3-get-card-value.js | 84 ++----------------- .../1-get-angle-type.test.js | 45 ++++++---- .../2-is-proper-fraction.test.js | 34 ++++++-- .../3-get-card-value.test.js | 52 ++++++++---- 6 files changed, 120 insertions(+), 235 deletions(-) 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 cb26378c2..b7c482b55 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 @@ -1,77 +1,27 @@ -// Implement a function getAngleType -// -// When given an angle in degrees, it should return a string indicating the type of angle: -// - "Acute angle" for angles greater than 0° and less than 90° -// - "Right angle" for exactly 90° -// - "Obtuse angle" for angles greater than 90° and less than 180° -// - "Straight angle" for exactly 180° -// - "Reflex angle" for angles greater than 180° and less than 360° -// - "Invalid angle" for angles outside the valid range. - -// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// 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 > 0 && angle < 90) { return "Acute angle"; - } else if (angle === 90) { + } + + if (angle === 90) { return "Right angle"; - } else if (angle > 90 && angle < 180) { + } + + if (angle > 90 && angle < 180) { return "Obtuse angle"; - } else if (angle === 180) { - return "Straight angle"; - } else if (angle > 180 && angle < 360) { - return "Reflex angle"; - } else { - return "Invalid angle"; } -} -// 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; + if (angle === 180) { + return "Straight angle"; + } -// This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); + if (angle > 180 && angle < 360) { + return "Reflex angle"; + } } -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); - -// Acute angle test -const acute = getAngleType(45); -assertEquals(acute, "Acute angle"); - -// Obtuse angle test -const obtuse = getAngleType(120); -assertEquals(obtuse, "Obtuse angle"); - -// Straight angle test -const straight = getAngleType(180); -assertEquals(straight, "Straight angle"); - -// Reflex angle test -const reflex = getAngleType(270); -assertEquals(reflex, "Reflex angle"); - -// Boundary tests -assertEquals(getAngleType(1), "Acute angle"); -assertEquals(getAngleType(359), "Reflex angle"); - -// Invalid angle tests -assertEquals(getAngleType(0), "Invalid angle"); -assertEquals(getAngleType(360), "Invalid angle"); -assertEquals(getAngleType(-10), "Invalid angle"); -assertEquals(getAngleType(500), "Invalid angle"); \ No newline at end of file +module.exports = getAngleType; \ No newline at end of file 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 6ddba8c47..a8a51ff7a 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 @@ -1,63 +1,9 @@ -// Implement a function isProperFraction, -// when given two numbers, a numerator and a denominator, it should return true if -// the given numbers form a proper fraction, and false otherwise. - -// Assumption: The parameters are valid numbers (not NaN or Infinity). - -// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition. - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - function isProperFraction(numerator, denominator) { - // TODO: Implement this function - if (denominator === 0) { return false; } - if (Math.abs(numerator) < Math.abs(denominator)) { - return true; - } - - 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; - -// Here's our helper again -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// TODO: Write tests to cover all cases. -// What combinations of numerators and denominators should you test? - -// Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), true); - -// numerator smaller than denominator -assertEquals(isProperFraction(3, 4), true); - -// numerator equal to denominator (not proper) -assertEquals(isProperFraction(5, 5), false); - -// numerator larger than denominator -assertEquals(isProperFraction(7, 3), false); - -// numerator is zero -assertEquals(isProperFraction(0, 5), true); - -// denominator is zero (invalid) -assertEquals(isProperFraction(1, 0), false); - -// negative numbers -assertEquals(isProperFraction(-1, 2), true); -assertEquals(isProperFraction(1, -2), true); -assertEquals(isProperFraction(-3, -2), false); \ No newline at end of file +module.exports = isProperFraction; \ No newline at end of file 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 7a0045c63..28695619e 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 @@ -1,29 +1,4 @@ -// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck - -// Implement a function getCardValue, when given a string representing a playing card, -// should return the numerical value of the card. - -// A valid card string will contain a rank followed by the suit. -// The rank can be one of the following strings: -// "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" -// The suit can be one of the following emojis: -// "♠", "♥", "♦", "♣" -// For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦". - -// When the card is an ace ("A"), the function should return 11. -// When the card is a face card ("J", "Q", "K"), the function should return 10. -// When the card is a number card ("2" to "10"), the function should return its numeric value. - -// When the card string is invalid (not following the above format), the function should -// throw an error. - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - function getCardValue(card) { - // TODO: Implement this function - const suits = ["♠", "♥", "♦", "♣"]; if (typeof card !== "string" || card.length < 2) { @@ -37,64 +12,21 @@ function getCardValue(card) { throw new Error("Invalid card"); } + // Ace if (rank === "A") return 11; + + // Face cards if (["J", "Q", "K"].includes(rank)) return 10; + // Number cards (STRICT check) const validNumbers = ["2", "3", "4", "5", "6", "7", "8", "9", "10"]; - - if (!validNumbers.includes(rank)) { + + if (validNumbers.includes(rank)) { return Number(rank); } - + // Everything else = invalid throw new Error("Invalid card"); } -// 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; - -// Helper functions to make our assertions easier to read. -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: -assertEquals(getCardValue("9♠"), 9); - -// Ace -assertEquals(getCardValue("A♠"), 11); - -// Face cards -assertEquals(getCardValue("J♥"), 10); -assertEquals(getCardValue("Q♦"), 10); -assertEquals(getCardValue("K♣"), 10); - -// Number cards -assertEquals(getCardValue("2♠"), 2); -assertEquals(getCardValue("10♥"), 10); - -// Handling invalid cards -try { - getCardValue("invalid"); - - // This line will not be reached if an error is thrown as expected - console.error("Error was not thrown for invalid card"); -} catch (e) {} - -// More invalid cases -try { - getCardValue("11♠"); - console.error("Error was not thrown for invalid card"); -} catch (e) {} - -try { - getCardValue("A"); - console.error("Error was not thrown for invalid card"); -} catch (e) {} - -// What other invalid card cases can you think of? \ No newline at end of file +module.exports = getCardValue; \ No newline at end of file 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 d777f348d..97b1c9c1c 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 @@ -1,20 +1,33 @@ -// This statement loads the getAngleType function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. const getAngleType = require("../implement/1-get-angle-type"); -// TODO: Write tests in Jest syntax to cover all cases/outcomes, -// including boundary and invalid cases. +describe("getAngleType", () => { + test("returns Acute angle", () => { + expect(getAngleType(1)).toBe("Acute angle"); + expect(getAngleType(45)).toBe("Acute angle"); + expect(getAngleType(89)).toBe("Acute angle"); + }); -// Case 1: Acute angles -test(`should return "Acute angle" when (0 < angle < 90)`, () => { - // Test various acute angles, including boundary cases - expect(getAngleType(1)).toEqual("Acute angle"); - expect(getAngleType(45)).toEqual("Acute angle"); - expect(getAngleType(89)).toEqual("Acute angle"); -}); + test("returns Right angle", () => { + expect(getAngleType(90)).toBe("Right angle"); + }); -// Case 2: Right angle -// Case 3: Obtuse angles -// Case 4: Straight angle -// Case 5: Reflex angles -// Case 6: Invalid angles + test("returns Obtuse angle", () => { + expect(getAngleType(100)).toBe("Obtuse angle"); + expect(getAngleType(179)).toBe("Obtuse angle"); + }); + + test("returns Straight angle", () => { + expect(getAngleType(180)).toBe("Straight angle"); + }); + + test("returns Reflex angle", () => { + expect(getAngleType(200)).toBe("Reflex angle"); + expect(getAngleType(359)).toBe("Reflex angle"); + }); + + test("returns Invalid angle", () => { + expect(getAngleType(0)).toBe("Invalid angle"); + expect(getAngleType(360)).toBe("Invalid angle"); + expect(getAngleType(-10)).toBe("Invalid angle"); + }); +}); \ No newline at end of file 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 7f087b2ba..6748db66a 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 @@ -1,10 +1,30 @@ -// This statement loads the isProperFraction function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. 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. +describe("isProperFraction", () => { + test("returns true when numerator is smaller than denominator", () => { + expect(isProperFraction(1, 2)).toBe(true); + expect(isProperFraction(3, 4)).toBe(true); + }); -// Special case: numerator is zero -test(`should return false when denominator is zero`, () => { - expect(isProperFraction(1, 0)).toEqual(false); -}); + test("returns false when numerator equals denominator", () => { + expect(isProperFraction(5, 5)).toBe(false); + }); + + test("returns false when numerator is larger than denominator", () => { + expect(isProperFraction(7, 3)).toBe(false); + }); + + test("returns true when numerator is zero", () => { + expect(isProperFraction(0, 5)).toBe(true); + }); + + test("returns false when denominator is zero", () => { + expect(isProperFraction(1, 0)).toBe(false); + }); + + test("works with negative numbers", () => { + expect(isProperFraction(-1, 2)).toBe(true); + expect(isProperFraction(1, -2)).toBe(true); + expect(isProperFraction(-3, -2)).toBe(false); + }); +}); \ No newline at end of file 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 cf7f9dae2..b5760ed64 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 @@ -1,20 +1,44 @@ -// This statement loads the getCardValue function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. const getCardValue = require("../implement/3-get-card-value"); -// TODO: Write tests in Jest syntax to cover all possible outcomes. +describe("getCardValue", () => { + // Ace + test("returns 11 for Ace", () => { + expect(getCardValue("A♠")).toBe(11); + }); -// Case 1: Ace (A) -test(`Should return 11 when given an ace card`, () => { - expect(getCardValue("A♠")).toEqual(11); -}); + // Face cards + test("returns 10 for face cards", () => { + expect(getCardValue("J♥")).toBe(10); + expect(getCardValue("Q♦")).toBe(10); + expect(getCardValue("K♣")).toBe(10); + }); -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards + // Number cards + test("returns correct value for number cards", () => { + expect(getCardValue("2♠")).toBe(2); + expect(getCardValue("10♥")).toBe(10); + }); -// 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 + // Invalid format + test("throws error for invalid strings", () => { + expect(() => getCardValue("invalid")).toThrow(); + expect(() => getCardValue("A")).toThrow(); + }); + // Invalid numbers (REVIEWER CHECK 🔥) + test("throws error for invalid numeric formats", () => { + expect(() => getCardValue("0x02♠")).toThrow(); + expect(() => getCardValue("2.1♠")).toThrow(); + expect(() => getCardValue("0002♠")).toThrow(); + }); + + // Invalid rank + test("throws error for invalid rank", () => { + expect(() => getCardValue("11♠")).toThrow(); + }); + + // Invalid suit + test("throws error for invalid suit", () => { + expect(() => getCardValue("A?")).toThrow(); + }); +}); \ No newline at end of file From 3fcf3f9d8014dd291fb858647cd0f63538189b15 Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Sun, 19 Apr 2026 19:57:37 +0100 Subject: [PATCH 4/5] Fix: erros fixed --- .../implement/3-get-card-value.js | 60 +------------------ 1 file changed, 3 insertions(+), 57 deletions(-) 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 92d5da5cc..058ba613b 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 @@ -18,68 +18,14 @@ function getCardValue(card) { // Face cards if (["J", "Q", "K"].includes(rank)) return 10; - // Number cards (STRICT check) - const validNumbers = ["2", "3", "4", "5", "6", "7", "8", "9", "10"]; + // Number cards + const validNumbers = ["2","3","4","5","6","7","8","9","10"]; if (validNumbers.includes(rank)) { return Number(rank); } - // Everything else = invalid throw new Error("Invalid card"); } -<<<<<<< HEAD -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; - -// Helper functions to make our assertions easier to read. -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} - -// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: -assertEquals(getCardValue("9♠"), 9); - -// Ace -assertEquals(getCardValue("A♠"), 11); - -// Face cards -assertEquals(getCardValue("J♥"), 10); -assertEquals(getCardValue("Q♦"), 10); -assertEquals(getCardValue("K♣"), 10); - -// Number cards -assertEquals(getCardValue("2♠"), 2); -assertEquals(getCardValue("10♥"), 10); - -// Handling invalid cards -try { - getCardValue("invalid"); - - // 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 🎉"); -} - -// More invalid cases -try { - getCardValue("11♠"); - console.error("Error was not thrown for invalid card"); -} catch (e) {} - -try { - getCardValue("A"); - console.error("Error was not thrown for invalid card"); -} catch (e) {} - -// What other invalid card cases can you think of? ->>>>>>> 983743526bc0a40a31b8e20926f23fa3ceb5cf29 +module.exports = getCardValue; \ No newline at end of file From a17bab54c7de437ea4665477d563c7226df4c185 Mon Sep 17 00:00:00 2001 From: MacDonald91 Date: Sun, 19 Apr 2026 20:28:32 +0100 Subject: [PATCH 5/5] Fix: revert package.json to original CYF version --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 87d27ab8f..0657e22dd 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "keywords": [], "author": "Code Your Future", "license": "ISC", - "devDependencies": { - "jest": "^30.2.0" + "dependencies": { + "jest": "^29.7.0" } -} +} \ No newline at end of file