From 71394a89147ea9f957d3648dd2fe63b9fa955b07 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Wed, 5 Nov 2025 13:12:52 +0000 Subject: [PATCH 01/13] Refactor getAngleType function to implement missing angle cases and update tests --- .../implement/1-get-angle-type.js | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 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 ca1dfe7f2..937fb4e3a 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,20 +1,20 @@ -// Implement a function getAngleType -// Build up your function case by case, writing tests as you go -// The first test and case is written for you. The next case has a test, but no code. -// Execute this script in your terminal -// node 1-get-angle-type.js -// The assertion error will tell you what the expected output is -// Write the code to pass the test -// Then, write the next test! :) Go through this process until all the cases are implemented - function getAngleType(angle) { if (angle === 90) { return "Right angle"; } - // Run the tests, work out what Case 2 is testing, and implement the required code here. - // Then keep going for the other cases, one at a time. + if (angle < 90) { + return "Acute angle"; + } + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + if (angle === 180) { + return "Straight angle"; + } + if (angle > 180 && angle < 360) { + return "Reflex 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; @@ -28,12 +28,6 @@ function assertEquals(actualOutput, targetOutput) { ); } -// Acceptance criteria: - -// Given an angle in degrees, -// When the function getAngleType is called with this angle, -// Then it should: - // Case 1: Identify Right Angles: // When the angle is exactly 90 degrees, // Then the function should return "Right angle" @@ -50,14 +44,16 @@ assertEquals(acute, "Acute angle"); // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" const obtuse = getAngleType(120); -// ====> write your test here, and then add a line to pass the test in the function above +assertEquals(obtuse, "Obtuse angle"); // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" -// ====> write your test here, and then add a line to pass the test in the function above +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" -// ====> write your test here, and then add a line to pass the test in the function above \ No newline at end of file +const reflex = getAngleType(250); +assertEquals(reflex, "Reflex angle"); From 0166d840acdbefdf1a4a364647e389a6cffc399f Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Wed, 5 Nov 2025 13:55:44 +0000 Subject: [PATCH 02/13] Proper fractions checked to return true or false for a range of inputs --- .../implement/2-is-proper-fraction.js | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) 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 a4739af77..686b470a0 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,16 +1,11 @@ -// Implement a function isProperFraction -// Write assertions for your function to check it works in different cases -// Terms: -// Fractions: https://www.bbc.co.uk/bitesize/topics/zt9n6g8/articles/zjxpp4j -// Written here like this: 1/2 == Numerator/Denominator -// the first test and first case is written for you -// complete the rest of the tests and cases -// write one test at a time, and make it pass, build your solution up methodically function isProperFraction(numerator, denominator) { if (numerator < denominator) { return true; } + else { + return false; + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -25,8 +20,7 @@ function assertEquals(actualOutput, targetOutput) { ); } -// Acceptance criteria: - +// Case 1 // Proper Fraction check: // Input: numerator = 2, denominator = 3 // target output: true @@ -34,6 +28,7 @@ function assertEquals(actualOutput, targetOutput) { const properFraction = isProperFraction(2, 3); assertEquals(properFraction, true); +//Case 2 // Improper Fraction check: // Input: numerator = 5, denominator = 2 // target output: false @@ -41,19 +36,39 @@ assertEquals(properFraction, true); const improperFraction = isProperFraction(5, 2); assertEquals(improperFraction, false); +//Case 3 // Negative Fraction check: // Input: numerator = -4, denominator = 7 // target output: true // Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. const negativeFraction = isProperFraction(-4, 7); -// ====> complete with your assertion +assertEquals(negativeFraction, true); +//The function already works for negative numerators, so no changes are needed. +//case 4 // Equal Numerator and Denominator check: // Input: numerator = 3, denominator = 3 // target output: false // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. const equalFraction = isProperFraction(3, 3); -// ====> complete with your assertion +assertEquals(equalFraction, false); // Stretch: // What other scenarios could you test for? +// Case 5 +//Negative denominator +const negativeDenominator = isProperFraction(4, -5); +assertEquals(negativeDenominator, true); +// Explanation: The fraction 4/-5 is a proper fraction because the absolute value of the numerator (4) is less than the absolute value of the denominator (5). The function should return true. + +// Case 6 +//Both numerator and denominator negative +const bothNegative = isProperFraction(-3, -4); +assertEquals(bothNegative, true); +// Explanation: The fraction -3/-4 is a proper fraction because the absolute value of the numerator (3) is less than the absolute value of the denominator (4). The function should return true. + +// Case 7 +//Zero numerator +const zeroNumerator = isProperFraction(0, 5); +assertEquals(zeroNumerator, true); +// Explanation: The fraction 0/5 is a proper fraction because the numerator (0) is less than the denominator (5). The function should return true. From 94d470e007f9dc4af29db7ce3e2547098846d08b Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Wed, 5 Nov 2025 13:56:11 +0000 Subject: [PATCH 03/13] formatted --- .../implement/2-is-proper-fraction.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 686b470a0..65ed39082 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,9 +1,7 @@ - function isProperFraction(numerator, denominator) { if (numerator < denominator) { return true; - } - else { + } else { return false; } } From ec1257eec9c38d3227f458901669844b5b87eb66 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Wed, 5 Nov 2025 14:43:34 +0000 Subject: [PATCH 04/13] Implement getCardValue function to handle card values and add tests for valid and invalid cards --- .../implement/3-get-card-value.js | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 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 266525d1b..b3a0078f5 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,16 +1,17 @@ -// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck - -// You will need to implement a function getCardValue -// the function takes a single parameter, a string representing a playing card -// the function should return the numerical value of the card -// the first test and first case is written for you -// complete the rest of the tests and cases -// write one test at a time, and make it pass, build your solution up methodically -// just make one change at a time -- don't rush -- programmers are deep and careful thinkers function getCardValue(card) { + const rank = card.slice(0, -1); if (rank === "A") { return 11; } + if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 10) { + // checks for number cards 2-10 + return Number(rank); + } + if (["J", "Q", "K"].includes(rank)) { + return 10; + } else { + throw new Error("Invalid card rank"); + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -26,32 +27,49 @@ function assertEquals(actualOutput, targetOutput) { `Expected ${actualOutput} to equal ${targetOutput}` ); } -// Acceptance criteria: +// Case 1 // Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A), // When the function getCardValue is called with this card string as input, // Then it should return the numerical card value const aceofSpades = getCardValue("A♠"); assertEquals(aceofSpades, 11); +// Case 2 // Handle Number Cards (2-10): // Given a card with a rank between "2" and "9", // When the function is called with such a card, // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). const fiveofHearts = getCardValue("5♥"); -// ====> write your test here, and then add a line to pass the test in the function above +assertEquals(fiveofHearts, 5); +// Case 3 // Handle Face Cards (J, Q, K): // Given a card with a rank of "10," "J," "Q," or "K", // When the function is called with such a card, // Then it should return the value 10, as these cards are worth 10 points each in blackjack. +const kingofDiamonds = getCardValue("K♦"); +assertEquals(kingofDiamonds, 10); +// Case 4 // Handle Ace (A): // Given a card with a rank of "A", // When the function is called with an Ace, // Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. +const aceofHearts = getCardValue("A♥"); +assertEquals(aceofHearts, 11); +// Case 5 // Handle Invalid Cards: // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." +try { + getCardValue("1♣"); + console.assert(false, "Expected error for invalid card"); +} catch (error) { + console.assert( + error.message === "Invalid card rank", + `Expected "Invalid card rank" error, but got: ${error.message}` + ); +} From 2ef15ec4b3e617c794634a93d762cd97f24b376a Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Thu, 6 Nov 2025 00:48:58 +0000 Subject: [PATCH 05/13] Angle function tested with jest --- .../1-get-angle-type.test.js | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) 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 4a92a3e82..4e2f4ced6 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 @@ -10,17 +10,25 @@ test("should identify right angle (90°)", () => { // make your test descriptions as clear and readable as possible // Case 2: Identify Acute Angles: -// When the angle is less than 90 degrees, -// Then the function should return "Acute angle" +test("should identify acute angle (<90°)", () => { + // Call the function with an angle less than 90 degrees + expect(getAngleType(45)).toEqual("Acute angle"); // Function is expected to return "Acute angle" +}); // Case 3: Identify Obtuse Angles: -// When the angle is greater than 90 degrees and less than 180 degrees, -// Then the function should return "Obtuse angle" +test("should identify obtuse angle (>90° and <180°)", () => { + // Call the function with an angle greater than 90 degrees and less than 180 degrees + expect(getAngleType(120)).toEqual("Obtuse angle"); // Function is expected to return "Obtuse angle" +}); // Case 4: Identify Straight Angles: -// When the angle is exactly 180 degrees, -// Then the function should return "Straight angle" +test("should identify straight angle (180°)", () => { + // Call the function with an angle of exactly 180 degrees + expect(getAngleType(180)).toEqual("Straight angle"); // Function is expected to return "Straight angle" +}); // Case 5: Identify Reflex Angles: -// When the angle is greater than 180 degrees and less than 360 degrees, -// Then the function should return "Reflex angle" +test("should identify reflex angle (>180° and <360°)", () => { + // Call the function with an angle greater than 180 degrees and less than 360 degrees + expect(getAngleType(270)).toEqual("Reflex angle"); // Function is expected to return "Reflex angle" +}); From 1e11b37d711b53534c4efd239b079ece72b01729 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Thu, 6 Nov 2025 00:59:43 +0000 Subject: [PATCH 06/13] fraction function tested with jest --- .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 9 +++++++++ 1 file changed, 9 insertions(+) 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 caf08d15b..510d7616a 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 @@ -7,7 +7,16 @@ test("should return true for a proper fraction", () => { }); // Case 2: Identify Improper Fractions: +test("should return false for an improper fraction", () => { + expect(isProperFraction(5, 4)).toEqual(false); +}); // Case 3: Identify Negative Fractions: +test("should return false for a negative fraction", () => { + expect(isProperFraction(-3, 4)).toEqual(true); +}); // Case 4: Identify Equal Numerator and Denominator: +test("should return false for equal numerator and denominator", () => { + expect(isProperFraction(3, 3)).toEqual(false); +}); From 2547a1a9a2fac109ace2b450dc8dce3770ce5983 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Thu, 6 Nov 2025 01:06:12 +0000 Subject: [PATCH 07/13] card value function tested with jest --- .../3-get-card-value.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 04418ff72..9552e26d8 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 @@ -8,6 +8,25 @@ test("should return 11 for Ace of Spades", () => { }); // Case 2: Handle Number Cards (2-10): +test("should return 7 for 7 of Hearts", () => { + const sevenOfHearts = getCardValue("7♥"); + expect(sevenOfHearts).toEqual(7); +}); + // Case 3: Handle Face Cards (J, Q, K): +test("should return 10 for King of Hearts", () => { + const kingOfHearts = getCardValue("K♥"); + expect(kingOfHearts).toEqual(10); +}); + // Case 4: Handle Ace (A): +test("should return 11 for Ace of Diamonds", () => { + const aceOfDiamonds = getCardValue("A♦"); + expect(aceOfDiamonds).toEqual(11); +}); + // Case 5: Handle Invalid Cards: +test("should return 0 for invalid card", () => { + const invalidCard = getCardValue("1♣"); + expect(invalidCard).toEqual(0); +}); From a5e2e07c8cc33d41e8c625ff30c458d10f962e5a Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Thu, 6 Nov 2025 17:00:58 +0000 Subject: [PATCH 08/13] countChar function tested --- Sprint-3/2-practice-tdd/count.js | 8 +++++++- Sprint-3/2-practice-tdd/count.test.js | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..d59e425d6 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,11 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters[i] === findCharacter) { + count++; + } + } + return count; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 42baf4b4b..3331a4d07 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,9 @@ test("should count multiple occurrences of a character", () => { // And a character char that does not exist within the case-sensitive str, // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. +test("should return 0 when character does not exist in string", () => { + const str = "hello world"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); From f5199804f021382764d09fde5abcb393df311559 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Wed, 12 Nov 2025 16:48:05 +0000 Subject: [PATCH 09/13] Refactor isProperFraction to use absolute values for numerator and denominator; update tests for negative fractions --- .../implement/2-is-proper-fraction.js | 2 +- .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) 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 65ed39082..c75002044 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,5 +1,5 @@ function isProperFraction(numerator, denominator) { - if (numerator < denominator) { + if (Math.abs(numerator) < Math.abs(denominator)) { return true; } else { return false; 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 510d7616a..2e1a14ee4 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 @@ -4,6 +4,7 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test("should return true for a proper fraction", () => { expect(isProperFraction(2, 3)).toEqual(true); + expect(isProperFraction(4, -5)).toEqual(true); }); // Case 2: Identify Improper Fractions: @@ -12,7 +13,7 @@ test("should return false for an improper fraction", () => { }); // Case 3: Identify Negative Fractions: -test("should return false for a negative fraction", () => { +test("should return true for a negative fraction", () => { expect(isProperFraction(-3, 4)).toEqual(true); }); From 8a26524f74e1cc1798f1f9bb24351ae8674c3d72 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Wed, 12 Nov 2025 17:01:28 +0000 Subject: [PATCH 10/13] Refactor getCardValue function to improve rank validation for number cards --- .../implement/3-get-card-value.js | 6 +++--- 1 file changed, 3 insertions(+), 3 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 b3a0078f5..5a1ea458a 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 @@ -3,10 +3,10 @@ function getCardValue(card) { if (rank === "A") { return 11; } - if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 10) { - // checks for number cards 2-10 + if (/^(?:[2-9]|10)$/.test(rank)) { return Number(rank); - } + } // Matches strings of only whole numbers 2-10 + // Handle 10 separately to avoid matching '1' alone if (["J", "Q", "K"].includes(rank)) { return 10; } else { From 9c6744595cb6cfe4dff0c1b1f6d2b4756c3e6ef6 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Wed, 12 Nov 2025 17:12:19 +0000 Subject: [PATCH 11/13] Update tests for isProperFraction to include negative fractions in validation --- .../2-is-proper-fraction.test.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 2e1a14ee4..e5f4214a5 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 @@ -2,14 +2,19 @@ // We will use the same function, but write tests for it using Jest in this file. const isProperFraction = require("../implement/2-is-proper-fraction"); -test("should return true for a proper fraction", () => { +test("should return true for a proper fraction, including negatives", () => { expect(isProperFraction(2, 3)).toEqual(true); + expect(isProperFraction(-2, 3)).toEqual(true); expect(isProperFraction(4, -5)).toEqual(true); + expect(isProperFraction(-4, -5)).toEqual(true); }); // Case 2: Identify Improper Fractions: -test("should return false for an improper fraction", () => { - expect(isProperFraction(5, 4)).toEqual(false); +test("should return false for an improper fraction, including negatives", () => { + expect(isProperFraction(5, 4)).toEqual(false); // numerator greater than denominator + expect(isProperFraction(5, -4)).toEqual(false); // negative denominator + expect(isProperFraction(-5, 4)).toEqual(false); // negative numerator + expect(isProperFraction(-5, -4)).toEqual(false); // both negative }); // Case 3: Identify Negative Fractions: From 743daf69937f1cde84b29484033a05c75ae38c4f Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Wed, 12 Nov 2025 18:04:21 +0000 Subject: [PATCH 12/13] Refactor tests for getCardValue function to handle all Aces and number cards dynamically; update invalid card handling --- .../implement/3-get-card-value.js | 8 --- .../3-get-card-value.test.js | 52 +++++++++++-------- 2 files changed, 30 insertions(+), 30 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 5a1ea458a..8fa6e12d7 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 @@ -52,14 +52,6 @@ const kingofDiamonds = getCardValue("K♦"); assertEquals(kingofDiamonds, 10); // Case 4 -// Handle Ace (A): -// Given a card with a rank of "A", -// When the function is called with an Ace, -// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. -const aceofHearts = getCardValue("A♥"); -assertEquals(aceofHearts, 11); - -// Case 5 // Handle Invalid Cards: // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, 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 9552e26d8..eaaea251c 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 @@ -2,31 +2,39 @@ // We will use the same function, but write tests for it using Jest in this file. const getCardValue = require("../implement/3-get-card-value"); -test("should return 11 for Ace of Spades", () => { - const aceofSpades = getCardValue("A♠"); - expect(aceofSpades).toEqual(11); -}); +test("should return 11 for all Aces", () => { + const suits = ["♠", "♥", "♦", "♣"]; + for (const suit of suits) { + expect(getCardValue(`A${suit}`)).toEqual(11); + } +}); // One array handles all suits for Aces // Case 2: Handle Number Cards (2-10): -test("should return 7 for 7 of Hearts", () => { - const sevenOfHearts = getCardValue("7♥"); - expect(sevenOfHearts).toEqual(7); -}); +test("should return correct value for number cards (2-10)", () => { + const suits = ["♠", "♥", "♦", "♣"]; + for (let i = 2; i <= 10; i++) { + for (const suit of suits) { + expect(getCardValue(`${i}${suit}`)).toEqual(i); + } + } +}); // Loop through numbers 2-10 for all suits; 36 test cases // Case 3: Handle Face Cards (J, Q, K): -test("should return 10 for King of Hearts", () => { - const kingOfHearts = getCardValue("K♥"); - expect(kingOfHearts).toEqual(10); -}); +test("should return 10 for all face cards (J, Q, K)", () => { + const faceCards = ["J", "Q", "K"]; + const suits = ["♠", "♥", "♦", "♣"]; + for (const card of faceCards) { + for (const suit of suits) { + expect(getCardValue(`${card}${suit}`)).toEqual(10); + } + } +}); // Loop through face cards for all suits; 12 test cases -// Case 4: Handle Ace (A): -test("should return 11 for Ace of Diamonds", () => { - const aceOfDiamonds = getCardValue("A♦"); - expect(aceOfDiamonds).toEqual(11); -}); -// Case 5: Handle Invalid Cards: -test("should return 0 for invalid card", () => { - const invalidCard = getCardValue("1♣"); - expect(invalidCard).toEqual(0); -}); +// Case 4: Handle Invalid Cards: +test("should throw error for all invalid cards", () => { + const invalidCards = ["1♣", "11♦", "B♠", "Z♥", "15♣", "", " "]; + for (const card of invalidCards) { + expect(() => getCardValue(card)).toThrow("Invalid card rank"); + } +}); // Loop through all invalid cards; 7 test cases \ No newline at end of file From 2c42fe7629a65100184a577b67cbb6e21c0f7d35 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Wed, 12 Nov 2025 18:33:00 +0000 Subject: [PATCH 13/13] improve readability and maintain consistency --- .../2-is-proper-fraction.test.js | 2 +- .../3-get-card-value.test.js | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) 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 e5f4214a5..3c230b9d6 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 @@ -14,7 +14,7 @@ test("should return false for an improper fraction, including negatives", () => expect(isProperFraction(5, 4)).toEqual(false); // numerator greater than denominator expect(isProperFraction(5, -4)).toEqual(false); // negative denominator expect(isProperFraction(-5, 4)).toEqual(false); // negative numerator - expect(isProperFraction(-5, -4)).toEqual(false); // both negative + expect(isProperFraction(-5, -4)).toEqual(false); // both negative }); // Case 3: Identify Negative Fractions: 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 eaaea251c..03f1f977c 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 @@ -11,13 +11,13 @@ test("should return 11 for all Aces", () => { // Case 2: Handle Number Cards (2-10): test("should return correct value for number cards (2-10)", () => { - const suits = ["♠", "♥", "♦", "♣"]; - for (let i = 2; i <= 10; i++) { - for (const suit of suits) { - expect(getCardValue(`${i}${suit}`)).toEqual(i); - } - } -}); // Loop through numbers 2-10 for all suits; 36 test cases + const suits = ["♠", "♥", "♦", "♣"]; + for (let i = 2; i <= 10; i++) { + for (const suit of suits) { + expect(getCardValue(`${i}${suit}`)).toEqual(i); + } + } +}); // Loop through numbers 2-10 for all suits; 36 test cases // Case 3: Handle Face Cards (J, Q, K): test("should return 10 for all face cards (J, Q, K)", () => { @@ -30,11 +30,10 @@ test("should return 10 for all face cards (J, Q, K)", () => { } }); // Loop through face cards for all suits; 12 test cases - // Case 4: Handle Invalid Cards: test("should throw error for all invalid cards", () => { const invalidCards = ["1♣", "11♦", "B♠", "Z♥", "15♣", "", " "]; for (const card of invalidCards) { expect(() => getCardValue(card)).toThrow("Invalid card rank"); } -}); // Loop through all invalid cards; 7 test cases \ No newline at end of file +}); // Loop through all invalid cards; 7 test cases