From 8670ab0cb48c36280a74e3797464e6594ac41351 Mon Sep 17 00:00:00 2001 From: pathywang Date: Thu, 12 Feb 2026 22:39:21 +0000 Subject: [PATCH 01/11] commit 1 --- .../implement/1-get-angle-type.js | 7 ++++++- 1 file changed, 6 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..7d44a5654 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,12 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + 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"; + if (angle > 180 && angle < 360) return "Reflex angle"; + return "Invalid angle" } // The line below allows us to load the getAngleType function into tests in other files. From 58a932206e082d2b5a57721227c8930f2f5ab9a9 Mon Sep 17 00:00:00 2001 From: pathywang Date: Thu, 12 Feb 2026 22:56:39 +0000 Subject: [PATCH 02/11] commit 2 --- .../implement/1-get-angle-type.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 7d44a5654..556f5e7a8 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 @@ -40,3 +40,25 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +// Case 2: Identify Acute Angles: +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +// Case 3: Identify Obtuse Angles: +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + +// Case 4: Identify Straight Angles: +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +// Case 5: Identify Reflex Angles: +const reflex = getAngleType(300); +assertEquals(reflex, "Reflex angle"); + +//case 6: Identify Invalid angle: +assertEquals(getAngleType(367),"Invalid angle"); + +//case 7: Identify boundary angle: +assertEquals(getAngleType(1), "Acute angle"); \ No newline at end of file From 284f020ad9f843d8c519f09e8057d6b7e8e82f34 Mon Sep 17 00:00:00 2001 From: pathywang Date: Sat, 14 Feb 2026 11:28:10 +0000 Subject: [PATCH 03/11] commit 2 --- .../implement/2-is-proper-fraction.js | 26 ++++++++++++++++++- example.js | 0 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 example.js 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..a5b53ca0c 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,7 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + return Math.abs(numerator) < Math.abs(denominator) } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +31,27 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +//Case 2: 5/5 is not a proper fraction +assertEquals(isProperFraction(5,5), false); + +//Case 3: (-3)/(-5) is a proper fraction +assertEquals(isFinite(-3,-5), true); + +//Case 4: (-4)/6 is a proper fraction +assertEquals(isProperFraction(-4,6),true); + +//case 5: 5/(-8) is a proper fraction +assertEquals(isProperFraction(5,-8), true); + +//case 6: 9/7 is not a proper fraction +assertEquals(isProperFraction(9,7), false); + +//case 7: 7/0 is not a proper fraction +assertEquals(isProperFraction(7,0), false); + +//case 8: 0/6 is a proper fraction +assertEquals(isProperFraction(0,6), true); + +//case 9: 0/-8 is a proper fraction +assertEquals(isProperFraction(0,-8), true); \ No newline at end of file diff --git a/example.js b/example.js new file mode 100644 index 000000000..e69de29bb From 8cb939726e703bb358434464b3044c0aeb0020a2 Mon Sep 17 00:00:00 2001 From: pathywang Date: Sun, 15 Feb 2026 08:41:34 +0000 Subject: [PATCH 04/11] complete --- .../implement/3-get-card-value.js | 61 ++++++++++++++++--- 1 file changed, 54 insertions(+), 7 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 c7559e787..1b544e5c8 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,8 +22,23 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function -} + const validSuits = ["♠", "♥", "♦", "♣"]; + const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; + + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + + if (!validSuits.includes(suit) || !validRanks.includes(rank)) { + throw new Error("Invalid card"); + } + + if (rank === "A") return 11; + if (["J", "Q", "K"].includes(rank)) return 10; + + return Number(rank); +} + // 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. @@ -38,15 +53,47 @@ function assertEquals(actualOutput, targetOutput) { } // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: +// Examples 1 numbers: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("5♣"), 5); + +//Examples A: +assertEquals(getCardValue("A♦"), 11) + +//Examples J Q K:, +assertEquals(getCardValue("Q♥"), 10) +assertEquals(getCardValue("K♥"), 10) -// Handling invalid cards -try { - getCardValue("invalid"); +//Examples invalid numbers: +assertThrow(()=>getCardValue("1♥")) +assertThrow(()=>getCardValue("11♥")) + +//Examples invalid suit: +assertThrow(()=>getCardValue("A*")) + +//Examples missing rank or suit: +assertThrow(()=>getCardValue("♥")) +assertThrow(()=>getCardValue("5")) + +//Example extra suit: +assertThrow(()=>getCardValue("Q♠♠")) + + +function assertThrow(fn){ +try { (fn) + // we try to run this function, if it throws, stop running this bit and run the catch below // This line will not be reached if an error is thrown as expected console.error("Error was not thrown for invalid card"); -} catch (e) {} +} catch (error) { + // if the above code throws, we catch the error here, that stops the whole program crashing + console.log('there was an error getting card value!',error) +}} + +console.log(' we finished running getCardvValue') // What other invalid card cases can you think of? + +//Examples wrong type: +assertThrow(()=>getCardValue("null")) +assertThrow(()=>getCardValue("42")) From 9013592cd32f1746f54c1ee919dd3c1eaf8fb8c3 Mon Sep 17 00:00:00 2001 From: pathywang Date: Sun, 15 Feb 2026 19:03:49 +0000 Subject: [PATCH 05/11] complete test --- .../implement/1-get-angle-type.js | 4 +-- .../implement/3-get-card-value.js | 2 +- .../1-get-angle-type.test.js | 17 +++++++++++++ .../2-is-proper-fraction.test.js | 25 ++++++++++++++++++- .../3-get-card-value.test.js | 15 +++++++++++ package.json | 6 ++--- 6 files changed, 62 insertions(+), 7 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 556f5e7a8..ec6627390 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 @@ -17,9 +17,9 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; if (angle < 90) return "Acute angle"; - if (angle > 90 && angle < 180) return "Obtuse angle"; + if (90 180 && angle < 360) return "Reflex angle"; + if (180 { }); // Case 2: Right angle +test ('should return "Right angle" when angle ===90',() => { + expect(getAngleType(90)).toEqual("Right angle"); +}) // Case 3: Obtuse angles +test ('should return "Obtuse angle" when (90 { + expect(getAngleType(135)).toEqual("Obtuse angle"); +}) // Case 4: Straight angle +test ('should return "Straight angle" when angle ===180',() => { + expect(getAngleType(180)).toEqual("Straight angle"); +}) + // Case 5: Reflex angles +test ('should return "Obtuse angle" when (180 { + expect(getAngleType(275)).toEqual("Reflex angle"); +}) + // Case 6: Invalid angles +test('should return "Invalid angle"when (angle>=360)', ()=> { + expect(getAngleType(360)).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..92741097c 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,30 @@ 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); }); + +//case:absolute numerator is bigger than absolute denominator +test ('should return false when numerator absolute is bigger than denominator absolute',() => { + expect(isProperFraction(5, -4)).toEqual(false); +}) + +//case:numerator is the same as denominator +test('should return false if numerator is the same as denominator', () =>{ + expect(isProperFraction(-9,-9)).toEqual(false) +}) + +//case: absolute numerator is less than absolute denominator +test ('should return true when numerator absolute is less than denominator absolute',() => { + expect(isProperFraction(3,-8)).toEqual(true); +}) + +//case: numerator is zero +test(`should return true when nominator is zero`, () => { + expect(isProperFraction(0,-3)).toEqual(true); +}); + + + 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..5bf037776 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 @@ -14,6 +14,21 @@ test(`Should return 11 when given an ace card`, () => { // Face Cards (J, Q, K) // Invalid Cards +// Case 2 : Number(2-10) +test('should return the exact number when given an number card', () =>{ + expect(getCardValue("5♠")).toEqual(5); +}) + +//case 3 : face card(J,Q,K) +test('should return number when given face card', () =>{ + expect(getCardValue("K♠")).toEqual(10); +}) + +// case 4: Invalid cards +test('throws new Error', () => { + expect(() => getCardValue("9**")).toThrow("Invalid 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 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 879957bf45e938a3dd29f5d112f84b209ec53cce Mon Sep 17 00:00:00 2001 From: pathywang Date: Sun, 15 Feb 2026 20:23:48 +0000 Subject: [PATCH 06/11] pass test --- Sprint-3/2-practice-tdd/count.js | 10 ++++++++- Sprint-3/2-practice-tdd/count.test.js | 9 +++++++- Sprint-3/2-practice-tdd/get-ordinal-number.js | 22 ++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..2e9b762d7 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,13 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0 + for(let i=0;i { + expect(countChar("tired", "d")).toEqual(1) +}) + // Scenario: Multiple Occurrences // Given the input string `str`, @@ -22,3 +26,6 @@ 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 count no occurrences of a character", () => { + expect(countChar("bananataste","w")).toEqual(0) +}) \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db1..a25d6b24b 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,25 @@ function getOrdinalNumber(num) { - return "1st"; + lastDigit = num % 10; + lastTwoDigits = num % 100; + + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return num + "th"; + } + + switch (lastDigit) { + case 1: + return num + "st"; + case 2: + return num + "nd"; + case 3: + return num + "rd"; + default: + return num + "th"; + } } +console.log(getOrdinalNumber(112)) + + + module.exports = getOrdinalNumber; From 3f949434ce1fe438279ab70190e51c6bcc232545 Mon Sep 17 00:00:00 2001 From: pathywang Date: Sun, 15 Feb 2026 22:24:03 +0000 Subject: [PATCH 07/11] test jest --- .../2-practice-tdd/get-ordinal-number.test.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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..09469502e 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,31 @@ 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: last two digits ending with 11,12,13 +test("should append 'th' for numbers with last digits 11,12,13", () =>{ + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(313)).toEqual("313th") + expect(getOrdinalNumber(2112)).toEqual("2112th") +}) + +// Case 3: Numbers ending with 2(but not 12) +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(52)).toEqual("52nd"); + expect(getOrdinalNumber(232)).toEqual("232nd"); +}); + +// Case 4: Numbers ending with 3(but not 13) +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(83)).toEqual("83rd"); + expect(getOrdinalNumber(463)).toEqual("463rd"); +}); + +// case 5: Numbers ending with 4-9 and 0 +test("should append 'th' for numbers with last 4-9 and 0", () =>{ + expect(getOrdinalNumber(8)).toEqual("8th"); + expect(getOrdinalNumber(3130)).toEqual("3130th") + expect(getOrdinalNumber(2119)).toEqual("2119th") +}) From bea11a55133f01ec0e8b1a66c504727aa924dcd3 Mon Sep 17 00:00:00 2001 From: pathywang Date: Sun, 15 Feb 2026 22:57:47 +0000 Subject: [PATCH 08/11] commit --- Sprint-3/2-practice-tdd/repeat-str.js | 10 ++++++++-- Sprint-3/2-practice-tdd/repeat-str.test.js | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..13e1a914f 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,11 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str,count) { + if (count>0) return str.repeat(count) + if (count===0) return "" + if (count<0) return"invalid count" } +console.log(repeatStr("hello",5)) +console.log(repeatStr("nihao",1)) +console.log(repeatStr("nihao",-5)) + 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..d41e4d0e5 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,22 @@ 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 only once", () => { + expect(repeatStr("nihao",1)).toEqual("nihao"); +}); // 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 0", () => { + expect(repeatStr("newyear",0)).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 negative times", () => { + expect(repeatStr("celebration", -5)).toEqual("invalid count"); +}); From 4435fdf4a0b59ac809137171bf49693b59232f9f Mon Sep 17 00:00:00 2001 From: pathywang Date: Mon, 16 Feb 2026 21:32:35 +0000 Subject: [PATCH 09/11] Delete Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js --- .../implement/1-get-angle-type.js | 64 ------------------- 1 file changed, 64 deletions(-) delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js 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 deleted file mode 100644 index ec6627390..000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ /dev/null @@ -1,64 +0,0 @@ -// 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) { - if (angle === 90) return "Right angle"; - if (angle < 90) return "Acute angle"; - if (90 Date: Mon, 16 Feb 2026 21:57:37 +0000 Subject: [PATCH 10/11] Delete example.js --- example.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 example.js diff --git a/example.js b/example.js deleted file mode 100644 index e69de29bb..000000000 From 859215b8463e7fdbca03cf36313d92f2b4c27d14 Mon Sep 17 00:00:00 2001 From: pathywang Date: Mon, 16 Feb 2026 23:01:38 +0000 Subject: [PATCH 11/11] delete --- .../1-implement-and-rewrite-tests/implement/3-get-card-value.js | 1 + 1 file changed, 1 insertion(+) 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 147e8ba25..98ace579f 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 @@ -97,3 +97,4 @@ console.log(' we finished running getCardValue') //Examples wrong type: assertThrow(()=>getCardValue("null")) assertThrow(()=>getCardValue("42")) +cd \ No newline at end of file