From e16389e0434bf5c40325c1b5d2dd154b9035c026 Mon Sep 17 00:00:00 2001 From: Mohsen Zamani Date: Sat, 31 Jan 2026 19:07:57 +0000 Subject: [PATCH 1/3] Complete sprint-3/implementandrewritetests --- .../implement/1-get-angle-type.js | 27 +++++++- .../implement/2-is-proper-fraction.js | 26 +++++++- .../implement/3-get-card-value.js | 43 ++++++++++++- .../1-get-angle-type.test.js | 24 +++++++ .../2-is-proper-fraction.test.js | 64 ++++++++++++++++++- .../3-get-card-value.test.js | 29 ++++++++- 6 files changed, 208 insertions(+), 5 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 9e05a871e..d12d92f4f 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,7 +15,13 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (typeof angle !== "number" || angle <= 0 || angle >= 360) + return "Invalid angle"; + if (angle === 90) return "Right angle"; + if (angle < 90) return "Acute angle"; + if (angle > 90 && angle < 180) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; + return "Reflex angle"; } // The line below allows us to load the getAngleType function into tests in other files. @@ -33,5 +39,24 @@ 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"); + +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +const reflex = getAngleType(260); +assertEquals(reflex, "Reflex angle"); + +const invalid1 = getAngleType(400); +assertEquals(invalid1, "Invalid angle"); + +const invalid2 = getAngleType("400"); +assertEquals(invalid2, "Invalid angle"); 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..9f64b7f37 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,7 +11,11 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + numerator = Math.abs(numerator); + denominator = Math.abs(denominator); + if (numerator < denominator) return true; + else if (numerator > denominator) return false; + else if (numerator === denominator) return false; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +35,23 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +// Example: 5/2 is not a proper fraction +const improperFraction = isProperFraction(5, 2); +assertEquals(improperFraction, false); + +// Example: -4/7 is a proper fraction +const negativeFraction = isProperFraction(-4, 7); +assertEquals(negativeFraction, true); + +// Example: 3/3 is not a proper fraction +const equalFraction = isProperFraction(3, 3); +assertEquals(equalFraction, false); + +// Example: 4/-7 is a proper fraction +const negativeFraction1 = isProperFraction(4, -7); +assertEquals(negativeFraction1, true); + +// Example: -4/-7 is a proper fraction +const negativeFraction2 = isProperFraction(4, 7); +assertEquals(negativeFraction2, true); 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..9fedfba4c 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,7 +22,14 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + if (!["♠", "♣", "♦", "♥"].includes(card.slice(-1))) + throw new Error("Invalid card rank."); + const rank = card.slice(0, card.length - 1); + if (rank === "A") return 11; + if (["10", "J", "Q", "K"].includes(rank)) return 10; + if (["2", "3", "4", "5", "6", "7", "8", "9"].includes(rank)) + return Number(rank); + throw new Error("Invalid card rank."); } // The line below allows us to load the getCardValue function into tests in other files. @@ -41,6 +48,15 @@ function assertEquals(actualOutput, targetOutput) { // Examples: assertEquals(getCardValue("9♠"), 9); +const fiveOfHearts = getCardValue("5♥"); +assertEquals(fiveOfHearts, 5); + +const faceCard = getCardValue("J♣"); +assertEquals(faceCard, 10); + +const aceCard = getCardValue("A♦"); +assertEquals(aceCard, 11); + // Handling invalid cards try { getCardValue("invalid"); @@ -50,3 +66,28 @@ try { } catch (e) {} // What other invalid card cases can you think of? +try { + getCardValue("9K"); + + console.log("Error was not thrown for invalid card"); +} catch (error) {} +try { + getCardValue(""); + + console.log("Error was not thrown for invalid card"); +} catch (error) {} +try { + getCardValue("ABC"); + + console.log("Error was not thrown for invalid card"); +} catch (error) {} +try { + getCardValue("A"); + + console.log("Error was not thrown for invalid card"); +} catch (error) {} +try { + getCardValue("JK"); + + console.log("Error was not thrown for invalid card"); +} catch (error) {} 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..c0fb38250 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,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Acute angle" when (angle = 90)`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test("should identify obtuse angle (90° < angle < 180°)", () => { + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(130)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test("should identify straight angle (angle = 180°)", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles +test("should identify reflex angle (180° < angle < 360)", () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(280)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test("should identify invalid angle (0 > angle > 360)", () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(361)).toEqual("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 7f087b2ba..e5caa3b8b 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,7 +4,69 @@ 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 +// Special case: denominator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +test("should return true when numerator is zero and denominator is non-zero", () => { + expect(isProperFraction(0, 5)).toEqual(true); +}); + +test("should return false when both numerator and denominator are zero", () => { + expect(isProperFraction(0, 0)).toEqual(false); +}); + +// Case 2: Identify Improper Fractions: +test("should return false for improper fraction", () => { + expect(isProperFraction(2, 3)).toEqual(true); +}); + +// Case 3: Identify Negative Fractions: +test("should return true for proper negative fraction", () => { + expect(isProperFraction(-3, 6)).toEqual(true); +}); + +test("should return false for improper negative fraction", () => { + expect(isProperFraction(-5, 2)).toEqual(false); +}); + +test("should return true for proper fraction with negative denominator", () => { + expect(isProperFraction(2, -5)).toEqual(true); +}); + +test("should return false for improper fraction with negative denominator", () => { + expect(isProperFraction(7, -3)).toEqual(false); +}); + +// Case 4: Identify Equal Numerator and Denominator: +test("should return false for improper fraction (numerator === denominator)", () => { + expect(isProperFraction(3, 3)).toEqual(false); +}); + +// Case 5: Identify both Numerator and Denominator as negative +test("should return true when both numerator and denominator are negative and proper", () => { + expect(isProperFraction(-2, -5)).toEqual(true); +}); + +test("should return false when both numerator and denominator are negative and improper", () => { + expect(isProperFraction(-6, -3)).toEqual(false); +}); + +// Case 6: Identify both Numerator and Denominator as decimal +test("should return true for proper decimal fractions", () => { + expect(isProperFraction(1.5, 2.5)).toEqual(true); +}); + +test("should return false for improper decimal fractions", () => { + expect(isProperFraction(2.5, 1.5)).toEqual(false); +}); + +// Case 7: Identify both Numerator and Denominator as large numbers +test("should return true for large proper fractions", () => { + expect(isProperFraction(100, 1000)).toEqual(true); +}); + +test("should return false for large improper fractions", () => { + expect(isProperFraction(1000, 100)).toEqual(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 cf7f9dae2..d6f4f1be4 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 @@ -7,6 +7,34 @@ const getCardValue = require("../implement/3-get-card-value"); // Case 1: Ace (A) test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); + expect(getCardValue("A♣")).toEqual(11); + expect(getCardValue("A♦")).toEqual(11); + expect(getCardValue("A♥")).toEqual(11); +}); + +// Case 2: Handle Number Cards (2-10): +test("should return the appropriate number from 2 to 10", () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("3♠")).toEqual(3); + expect(getCardValue("4♠")).toEqual(4); + expect(getCardValue("5♠")).toEqual(5); + expect(getCardValue("6♠")).toEqual(6); + expect(getCardValue("7♠")).toEqual(7); + expect(getCardValue("8♠")).toEqual(8); + expect(getCardValue("9♠")).toEqual(9); + expect(getCardValue("10♠")).toEqual(10); +}); +// Case 3: Handle Face Cards (J, Q, K): +test("should return 10 for face cards", () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♠")).toEqual(10); + expect(getCardValue("K♠")).toEqual(10); +}); + +// Case 4: Handle Invalid Cards: +test("Should return 'Invalid card rank.' for invalid cards", () => { + expect(() => getCardValue("KJ")).toThrow("Invalid card rank."); + expect(() => getCardValue("AK")).toThrow("Invalid card rank."); }); // Suggestion: Group the remaining test data into these categories: @@ -17,4 +45,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 - From 4e176f14c54f053e527644857d7d672a9ccfe40b Mon Sep 17 00:00:00 2001 From: Mohsen Zamani Date: Sat, 31 Jan 2026 20:01:13 +0000 Subject: [PATCH 2/3] Complete coursework/sprint-3-practice-tdd --- Sprint-3/2-practice-tdd/count.js | 5 ++- Sprint-3/2-practice-tdd/count.test.js | 6 +++ Sprint-3/2-practice-tdd/get-ordinal-number.js | 21 +++++++++- .../2-practice-tdd/get-ordinal-number.test.js | 38 +++++++++++++++++++ Sprint-3/2-practice-tdd/repeat-str.js | 5 ++- Sprint-3/2-practice-tdd/repeat-str.test.js | 17 +++++++++ 6 files changed, 88 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..443e7d207 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,8 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + return [...stringOfCharacters].reduce( + (acc, curr) => acc + (curr === findCharacter ? 1 : 0), + 0 + ); } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf..df692b909 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 `str`. // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of `char` were found. +test("should return 0, since there are no occurrences of a character", () => { + const char = "a"; + const str = "AABBFFSAA"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db1..02d566d14 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,24 @@ function getOrdinalNumber(num) { - return "1st"; + const last2Digits = String(num).slice(-2); + if (["11", "12", "13"].includes(last2Digits)) return `${num}th`; + + const lastDigit = String(num).slice(-1); + const restOfNum = String(num).slice(0, -1); + let ordinalResult = ""; + switch (lastDigit) { + case "1": + ordinalResult = `${num}st`; + break; + case "2": + ordinalResult = `${num}nd`; + break; + case "3": + ordinalResult = `${num}rd`; + break; + default: + ordinalResult = `${num}th`; + } + return ordinalResult; } module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index adfa58560..eea071483 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,41 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +// Case 2: Numbers ending with 2 (but not 12) +// When the number ends with 2, except those ending with 12, +// Then the function should return a string by appending "nd" to the number. +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(31562)).toEqual("31562nd"); + expect(getOrdinalNumber(2322)).toEqual("2322nd"); +}); + +// Case 3: Numbers ending with 3 (but not 13) +// When the number ends with 3, except those ending with 13, +// Then the function should return a string by appending "rd" to the number. +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(3243)).toEqual("3243rd"); + expect(getOrdinalNumber(5462133)).toEqual("5462133rd"); +}); + +// Case 4: Numbers ending with 11, 12 or 13 +// When the number ends with 11, 12 or 13 +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for numbers with 11, 12 or 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(2111)).toEqual("2111th"); + expect(getOrdinalNumber(2113)).toEqual("2113th"); + expect(getOrdinalNumber(524312)).toEqual("524312th"); +}); + +// Case 4: Numbers not ending in 1, 2 and 3 +// When the number ends with 0, 4, 5, 6, 7, 8, 9 +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for numbers not ending in 1, 2 and 3", () => { + expect(getOrdinalNumber(19)).toEqual("19th"); + expect(getOrdinalNumber(2118)).toEqual("2118th"); + expect(getOrdinalNumber(2110)).toEqual("2110th"); + expect(getOrdinalNumber(524334)).toEqual("524334th"); +}); diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..2e224ff02 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,6 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + if (count < 0) throw new Error("Can not repeat negative times."); + return str.repeat(count); } module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c..0b2ca5640 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,30 @@ test("should repeat the string count times", () => { // Given a target string `str` and a `count` equal to 1, // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. +test("should repeat the string count times", () => { + const str = "hello"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hello"); +}); // Case: Handle count of 0: // Given a target string `str` and a `count` equal to 0, // When the repeatStr function is called with these inputs, // Then it should return an empty string. +test("should repeat the string count times", () => { + const str = "hello"; + const count = 0; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual(""); +}); // Case: Handle negative count: // Given a target string `str` and a negative integer `count`, // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid. +test("should repeat the string count times", () => { + const str = "hello"; + const count = -3; + expect(() => repeatStr(str, count)).toThrow("Can not repeat negative times."); +}); From 75a06d449068d606ca04a2791a6a3b3a05f5f421 Mon Sep 17 00:00:00 2001 From: Mohsen Zamani Date: Sat, 31 Jan 2026 20:04:48 +0000 Subject: [PATCH 3/3] Revert accidental changes to 1-implement-and-rewrite-tests --- .../implement/1-get-angle-type.js | 27 +------- .../implement/2-is-proper-fraction.js | 26 +------- .../implement/3-get-card-value.js | 43 +------------ .../1-get-angle-type.test.js | 24 ------- .../2-is-proper-fraction.test.js | 64 +------------------ .../3-get-card-value.test.js | 29 +-------- 6 files changed, 5 insertions(+), 208 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 d12d92f4f..9e05a871e 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,13 +15,7 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - if (typeof angle !== "number" || angle <= 0 || angle >= 360) - return "Invalid angle"; - if (angle === 90) return "Right angle"; - if (angle < 90) return "Acute angle"; - if (angle > 90 && angle < 180) return "Obtuse angle"; - if (angle === 180) return "Straight angle"; - return "Reflex angle"; + // TODO: Implement this function } // The line below allows us to load the getAngleType function into tests in other files. @@ -39,24 +33,5 @@ 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"); - -const acute = getAngleType(45); -assertEquals(acute, "Acute angle"); - -const obtuse = getAngleType(120); -assertEquals(obtuse, "Obtuse angle"); - -const straight = getAngleType(180); -assertEquals(straight, "Straight angle"); - -const reflex = getAngleType(260); -assertEquals(reflex, "Reflex angle"); - -const invalid1 = getAngleType(400); -assertEquals(invalid1, "Invalid angle"); - -const invalid2 = getAngleType("400"); -assertEquals(invalid2, "Invalid angle"); 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 9f64b7f37..970cb9b64 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,11 +11,7 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - numerator = Math.abs(numerator); - denominator = Math.abs(denominator); - if (numerator < denominator) return true; - else if (numerator > denominator) return false; - else if (numerator === denominator) return false; + // TODO: Implement this function } // The line below allows us to load the isProperFraction function into tests in other files. @@ -35,23 +31,3 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); - -// Example: 5/2 is not a proper fraction -const improperFraction = isProperFraction(5, 2); -assertEquals(improperFraction, false); - -// Example: -4/7 is a proper fraction -const negativeFraction = isProperFraction(-4, 7); -assertEquals(negativeFraction, true); - -// Example: 3/3 is not a proper fraction -const equalFraction = isProperFraction(3, 3); -assertEquals(equalFraction, false); - -// Example: 4/-7 is a proper fraction -const negativeFraction1 = isProperFraction(4, -7); -assertEquals(negativeFraction1, true); - -// Example: -4/-7 is a proper fraction -const negativeFraction2 = isProperFraction(4, 7); -assertEquals(negativeFraction2, true); 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 9fedfba4c..c7559e787 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,14 +22,7 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - if (!["♠", "♣", "♦", "♥"].includes(card.slice(-1))) - throw new Error("Invalid card rank."); - const rank = card.slice(0, card.length - 1); - if (rank === "A") return 11; - if (["10", "J", "Q", "K"].includes(rank)) return 10; - if (["2", "3", "4", "5", "6", "7", "8", "9"].includes(rank)) - return Number(rank); - throw new Error("Invalid card rank."); + // TODO: Implement this function } // The line below allows us to load the getCardValue function into tests in other files. @@ -48,15 +41,6 @@ function assertEquals(actualOutput, targetOutput) { // Examples: assertEquals(getCardValue("9♠"), 9); -const fiveOfHearts = getCardValue("5♥"); -assertEquals(fiveOfHearts, 5); - -const faceCard = getCardValue("J♣"); -assertEquals(faceCard, 10); - -const aceCard = getCardValue("A♦"); -assertEquals(aceCard, 11); - // Handling invalid cards try { getCardValue("invalid"); @@ -66,28 +50,3 @@ try { } catch (e) {} // What other invalid card cases can you think of? -try { - getCardValue("9K"); - - console.log("Error was not thrown for invalid card"); -} catch (error) {} -try { - getCardValue(""); - - console.log("Error was not thrown for invalid card"); -} catch (error) {} -try { - getCardValue("ABC"); - - console.log("Error was not thrown for invalid card"); -} catch (error) {} -try { - getCardValue("A"); - - console.log("Error was not thrown for invalid card"); -} catch (error) {} -try { - getCardValue("JK"); - - console.log("Error was not thrown for invalid card"); -} catch (error) {} 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 c0fb38250..d777f348d 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,31 +14,7 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle -test(`should return "Acute angle" when (angle = 90)`, () => { - expect(getAngleType(90)).toEqual("Right angle"); -}); - // Case 3: Obtuse angles -test("should identify obtuse angle (90° < angle < 180°)", () => { - expect(getAngleType(91)).toEqual("Obtuse angle"); - expect(getAngleType(130)).toEqual("Obtuse angle"); - expect(getAngleType(179)).toEqual("Obtuse angle"); -}); - // Case 4: Straight angle -test("should identify straight angle (angle = 180°)", () => { - expect(getAngleType(180)).toEqual("Straight angle"); -}); - // Case 5: Reflex angles -test("should identify reflex angle (180° < angle < 360)", () => { - expect(getAngleType(181)).toEqual("Reflex angle"); - expect(getAngleType(280)).toEqual("Reflex angle"); - expect(getAngleType(359)).toEqual("Reflex angle"); -}); - // Case 6: Invalid angles -test("should identify invalid angle (0 > angle > 360)", () => { - expect(getAngleType(0)).toEqual("Invalid angle"); - expect(getAngleType(361)).toEqual("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 e5caa3b8b..7f087b2ba 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,69 +4,7 @@ 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: denominator is zero +// Special case: numerator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); - -test("should return true when numerator is zero and denominator is non-zero", () => { - expect(isProperFraction(0, 5)).toEqual(true); -}); - -test("should return false when both numerator and denominator are zero", () => { - expect(isProperFraction(0, 0)).toEqual(false); -}); - -// Case 2: Identify Improper Fractions: -test("should return false for improper fraction", () => { - expect(isProperFraction(2, 3)).toEqual(true); -}); - -// Case 3: Identify Negative Fractions: -test("should return true for proper negative fraction", () => { - expect(isProperFraction(-3, 6)).toEqual(true); -}); - -test("should return false for improper negative fraction", () => { - expect(isProperFraction(-5, 2)).toEqual(false); -}); - -test("should return true for proper fraction with negative denominator", () => { - expect(isProperFraction(2, -5)).toEqual(true); -}); - -test("should return false for improper fraction with negative denominator", () => { - expect(isProperFraction(7, -3)).toEqual(false); -}); - -// Case 4: Identify Equal Numerator and Denominator: -test("should return false for improper fraction (numerator === denominator)", () => { - expect(isProperFraction(3, 3)).toEqual(false); -}); - -// Case 5: Identify both Numerator and Denominator as negative -test("should return true when both numerator and denominator are negative and proper", () => { - expect(isProperFraction(-2, -5)).toEqual(true); -}); - -test("should return false when both numerator and denominator are negative and improper", () => { - expect(isProperFraction(-6, -3)).toEqual(false); -}); - -// Case 6: Identify both Numerator and Denominator as decimal -test("should return true for proper decimal fractions", () => { - expect(isProperFraction(1.5, 2.5)).toEqual(true); -}); - -test("should return false for improper decimal fractions", () => { - expect(isProperFraction(2.5, 1.5)).toEqual(false); -}); - -// Case 7: Identify both Numerator and Denominator as large numbers -test("should return true for large proper fractions", () => { - expect(isProperFraction(100, 1000)).toEqual(true); -}); - -test("should return false for large improper fractions", () => { - expect(isProperFraction(1000, 100)).toEqual(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 d6f4f1be4..cf7f9dae2 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 @@ -7,34 +7,6 @@ const getCardValue = require("../implement/3-get-card-value"); // Case 1: Ace (A) test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); - expect(getCardValue("A♣")).toEqual(11); - expect(getCardValue("A♦")).toEqual(11); - expect(getCardValue("A♥")).toEqual(11); -}); - -// Case 2: Handle Number Cards (2-10): -test("should return the appropriate number from 2 to 10", () => { - expect(getCardValue("2♠")).toEqual(2); - expect(getCardValue("3♠")).toEqual(3); - expect(getCardValue("4♠")).toEqual(4); - expect(getCardValue("5♠")).toEqual(5); - expect(getCardValue("6♠")).toEqual(6); - expect(getCardValue("7♠")).toEqual(7); - expect(getCardValue("8♠")).toEqual(8); - expect(getCardValue("9♠")).toEqual(9); - expect(getCardValue("10♠")).toEqual(10); -}); -// Case 3: Handle Face Cards (J, Q, K): -test("should return 10 for face cards", () => { - expect(getCardValue("J♠")).toEqual(10); - expect(getCardValue("Q♠")).toEqual(10); - expect(getCardValue("K♠")).toEqual(10); -}); - -// Case 4: Handle Invalid Cards: -test("Should return 'Invalid card rank.' for invalid cards", () => { - expect(() => getCardValue("KJ")).toThrow("Invalid card rank."); - expect(() => getCardValue("AK")).toThrow("Invalid card rank."); }); // Suggestion: Group the remaining test data into these categories: @@ -45,3 +17,4 @@ test("Should return 'Invalid card rank.' for invalid cards", () => { // 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 +