From 32407f92f9fd0ce28e3fba5ec44b26a38b344a5e Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Thu, 5 Mar 2026 09:52:22 +0000 Subject: [PATCH 01/11] Update .gitignore to include .vscode directory --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bde36e5302..a4da420804 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules .DS_Store -.vscode -**/.DS_Store \ No newline at end of file +.vscode/ +**/.DS_Store From 01ca25c6149fb57efd33b942ec3a1962d28562e3 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Sat, 14 Mar 2026 12:43:00 +0000 Subject: [PATCH 02/11] Add Implement and Rewrite Test files only --- .../implement/1-get-angle-type.js | 37 ++++++++- .../implement/2-is-proper-fraction.js | 16 +++- .../implement/3-get-card-value.js | 76 ++++++++++++++++++- .../1-get-angle-type.test.js | 35 ++++++++- .../2-is-proper-fraction.test.js | 22 +++++- .../3-get-card-value.test.js | 52 ++++++++++--- 6 files changed, 216 insertions(+), 22 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 9e05a871e2..545f1c41a0 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,18 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle < 0 || angle >= 360) return "Invalid angle"; + if (angle < 90) return "Acute angle"; + if (angle === 90) return "Right angle"; + if (angle > 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. // This will be useful in the "rewrite tests with jest" step. -module.exports = getAngleType; +module.exports = getAngleType; // 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) { @@ -31,7 +36,31 @@ 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(270); +assertEquals(reflex, "Reflex angle"); + +const invalid = getAngleType(-10); +assertEquals(invalid, "Invalid angle"); + +const invalid2 = getAngleType(360); +assertEquals(invalid2, "Invalid angle"); + +console.log(getAngleType(20)); +console.log(getAngleType(90)); +console.log(getAngleType(120)); +console.log(getAngleType(180)); +console.log(getAngleType(270)); +console.log(getAngleType(-10)); +console.log(getAngleType(360)); diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b641..574470b7ea 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,9 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (denominator === 0) return false; // A fraction with a zero denominator is not valid + if (Math.abs(numerator) >= Math.abs(denominator)) return false; // Not a proper fraction + return true; // Is a proper fraction } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +33,15 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(2, 2), false); +assertEquals(isProperFraction(2, 1), false); +assertEquals(isProperFraction(0, 2), true); +assertEquals(isProperFraction(1, 0), false); +assertEquals(isProperFraction(0, 0), false); + +console.log(isProperFraction(1, 2)); +console.log(isProperFraction(2, 2)); +console.log(isProperFraction(2, 1)); +console.log(isProperFraction(0, 2)); +console.log(isProperFraction(1, 0)); +console.log(isProperFraction(0, 0)); 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 c7559e787e..8efc14733c 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -22,9 +22,40 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function -} + if (typeof card !== "string" || card.length < 2) { + throw new Error("Invalid card"); + } + // Handle "10" which is like "10♥" + if (card.startsWith("10")) { + return 10; + } + //if more than 2 characters and not starting with a 10 card + if (card.length > 2) { + throw new Error("Invalid card"); + } + + // remaining cards must be 2 characters long + + const validSuits = ["♠", "♥", "♦", "♣"]; + const suit = card[card.length - 1]; + + const firstChar = card[0]; + + // check if picture cards + if (firstChar === "A") return 11; + if (firstChar === "J" || firstChar === "Q" || firstChar === "K") return 10; + + // check if number is between 2 and 9, 10 has already been checked for and there should be no other valid cards + const num = Number(firstChar); + + if (!isNaN(num) && num >= 2 && num <= 9) { + return num; + // for everything else + } else { + 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; @@ -40,13 +71,52 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("10♥"), 10); +assertEquals(getCardValue("J♥"), 10); +assertEquals(getCardValue("A♠"), 11); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("K♣"), 10); // Handling invalid cards +try { + getCardValue("♠J"); + console.error("Error was not thrown for invalid card"); +} catch (e) {} + try { getCardValue("invalid"); + console.error("Error was not thrown for invalid card"); +} catch (e) {} + +try { + getCardValue("22"); + console.error("Error was not thrown for invalid card"); +} catch (e) {} - // This line will not be reached if an error is thrown as expected +console.log(getCardValue("9♠")); +console.log(getCardValue("10♥")); +console.log(getCardValue("J♥")); +console.log(getCardValue("A♠")); +console.log(getCardValue("Q♦")); +console.log(getCardValue("K♣")); + +// This line will not be reached if an error is thrown as expected +try { console.error("Error was not thrown for invalid card"); } catch (e) {} // What other invalid card cases can you think of? + +// There could be cards with special characters. + +// There could be cards with two numbers rather than a number and a suite +// These will not be picked up because the code only checks for if starts with 10 or if the first character +// is a number between 2 and 9, so cards like "22" would be valid because the first number +// is 2, but the second character is not checked for validity. It is also 2 characters +// so will not cause an error when the length is checked. + +// Since the second character is not checked it could be 2D which is not a valid card but +// would be accepted because the first character is 2 and the second character is not checked for validity + +// When the card is checked if it begins with 10 it does check if it has a valid suite +// as only the first 2 characters are checked so it could be 10DEVON or 10♥♥. diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d3..94eac95b04 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 @@ -2,19 +2,48 @@ // 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. - // 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"); + expect(getAngleType(91)).toEqual("Obtuse angle"); }); // Case 2: Right angle +test(`should return "Right angle" when (angle === 90)`, () => { + // Test various right angles, including boundary cases + expect(getAngleType(90)).toEqual("Right angle"); + expect(getAngleType(89)).toEqual("Acute angle"); + expect(getAngleType(91)).toEqual("Obtuse angle"); +}); + // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (angle > 90) && when (angle < 180)`, () => { + // Test various obtuse angles, including boundary cases + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(150)).toEqual("Obtuse angle"); + expect(getAngleType(189)).toEqual("Reflex angle"); +}); + // Case 4: Straight angle +test(`should return "Straight angle" when (angle === 180)`, () => { + // Test various straight angles, including boundary cases + expect(getAngleType(180)).toEqual("Straight angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); + expect(getAngleType(181)).toEqual("Reflex angle"); +}); + // Case 5: Reflex angles +test(`should return "Reflex angle" when (angle > 180)`, () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(270)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test(`should return "Invalid angle" when (angle < 0 || angle >= 360)`, () => { + expect(getAngleType(-1)).toEqual("Invalid angle"); + 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 7f087b2ba1..356903e40b 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,9 +2,27 @@ // 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. - // Special case: numerator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); + +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(2, 2)).toEqual(false); +}); + +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(2, 1)).toEqual(false); +}); + +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(0, 0)).toEqual(false); +}); + +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(0, 1)).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 cf7f9dae2e..f215e37b42 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,54 @@ // 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 { createTestScheduler } = require("jest"); const getCardValue = require("../implement/3-get-card-value"); -// TODO: Write tests in Jest syntax to cover all possible outcomes. - // Case 1: Ace (A) test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards +// Case 2: Face Cards (J, Q, K) +test(`Should return 10 when given a Jack card`, () => { + expect(getCardValue("J♥")).toEqual(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 +test(`Should return 10 when given a Queen card`, () => { + expect(getCardValue("Q♦")).toEqual(10); +}); + +test(`Should return 10 when given a King card`, () => { + expect(getCardValue("K♣")).toEqual(10); +}); + +// Case 3: Number Cards (2-10) +test(`Should return 2 when given a 2 card`, () => { + expect(getCardValue("2♠")).toEqual(2); +}); + +test(`Should return 10 when given a 10 card`, () => { + expect(getCardValue("10♥")).toEqual(10); +}); + +// Case 4: Invalid Cards +test(`Should throw an error when given an invalid card`, () => { + expect(() => getCardValue("♠J")).toThrow(); +}); + +test(`Should throw an error when given an invalid card`, () => { + expect(() => getCardValue("invalid")).toThrow(); +}); + +test(`Should throw an error when given an invalid card`, () => { + expect(() => getCardValue("12♠")).toThrow(); +}); + +test(`Should throw an error when given an invalid card`, () => { + expect(() => getCardValue("1")).toThrow(); +}); +// when I tested with test(`Should throw an error when given an invalid card`, () => { +// expect(() => getCardValue("22")).toThrow(); it did not throw an error because 22 passes the +// test of first number between and 9 and being 2 characters long, +// but it is not a valid card because the second character is not a valid suite. +// The second character is not checked. From 77ebe17de7134ebc01e11d40fef9548ecd8345fa Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Sat, 14 Mar 2026 13:04:38 +0000 Subject: [PATCH 03/11] Update 1-get-angle-type.test.js with new lines --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 2 ++ 1 file changed, 2 insertions(+) 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 94eac95b04..19703a08bf 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 @@ -46,4 +46,6 @@ test(`should return "Reflex angle" when (angle > 180)`, () => { test(`should return "Invalid angle" when (angle < 0 || angle >= 360)`, () => { expect(getAngleType(-1)).toEqual("Invalid angle"); expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(361)).toEqual("Invalid angle"); }); From 1af10d63c97f545df56abb80aa319ff1b249fdd6 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Sat, 14 Mar 2026 13:23:01 +0000 Subject: [PATCH 04/11] Fix test case for proper fraction --- .../2-is-proper-fraction.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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 356903e40b..a2a8cbd762 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 @@ -3,26 +3,26 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // 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`, () => { + expect(isProperFraction(0, 1)).toEqual(true); }); -test(`should return false when denominator is zero`, () => { +test(`should return true when denominator is bigger then numerator => { expect(isProperFraction(1, 2)).toEqual(true); }); -test(`should return false when denominator is zero`, () => { +test(`should return false when denominator is equal to numerator`, () => { expect(isProperFraction(2, 2)).toEqual(false); }); -test(`should return false when denominator is zero`, () => { +test(`should return false when denominator is smaller than numerator`, () => { expect(isProperFraction(2, 1)).toEqual(false); }); -test(`should return false when denominator is zero`, () => { +test(`should return false when denominator and numerator are both zero`, () => { expect(isProperFraction(0, 0)).toEqual(false); }); test(`should return false when denominator is zero`, () => { - expect(isProperFraction(0, 1)).toEqual(true); + expect(isProperFraction(1, 0)).toEqual(false); }); From 2deb27ec0986a148eae73cdd73bf0e32f8edc88b Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Sat, 14 Mar 2026 13:32:41 +0000 Subject: [PATCH 05/11] Fix test case for isProperFraction() with zero numerator --- .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a2a8cbd762..8528bffc2f 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,7 @@ test(`should return true when numerator is zero`, () => { expect(isProperFraction(0, 1)).toEqual(true); }); -test(`should return true when denominator is bigger then numerator => { +test(`should return true when denominator is bigger then numerator` => { expect(isProperFraction(1, 2)).toEqual(true); }); From 01b8b9ce4d0777c168b8f605d633e30321fec25a Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Sat, 14 Mar 2026 14:04:18 +0000 Subject: [PATCH 06/11] Updated test for proper fraction --- .../2-is-proper-fraction.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 8528bffc2f..4ac44bcc23 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 @@ -3,26 +3,26 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // Special case: numerator is zero -test(`should return true when numerator is zero`, () => { +test(`should return true when the numerator is zero`, () => { expect(isProperFraction(0, 1)).toEqual(true); }); -test(`should return true when denominator is bigger then numerator` => { +test(`should return true when the denominator is bigger then the numerator` => { expect(isProperFraction(1, 2)).toEqual(true); }); -test(`should return false when denominator is equal to numerator`, () => { +test(`should return false when the denominator is equal to the numerator`, () => { expect(isProperFraction(2, 2)).toEqual(false); }); -test(`should return false when denominator is smaller than numerator`, () => { +test(`should return false when the denominator is smaller than the numerator`, () => { expect(isProperFraction(2, 1)).toEqual(false); }); -test(`should return false when denominator and numerator are both zero`, () => { +test(`should return false when the denominator and the numerator are both zero`, () => { expect(isProperFraction(0, 0)).toEqual(false); }); -test(`should return false when denominator is zero`, () => { +test(`should return false when the denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); From eaaccca9552949688be7bb79495ebbfbb6549678 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Sat, 14 Mar 2026 14:17:22 +0000 Subject: [PATCH 07/11] Grouped tests together --- .../3-get-card-value.test.js | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) 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 f215e37b42..872365a8f0 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -9,41 +9,24 @@ test(`Should return 11 when given an ace card`, () => { }); // Case 2: Face Cards (J, Q, K) -test(`Should return 10 when given a Jack card`, () => { +test(`Should return 10 when given a Jack, Queen or King card`, () => { expect(getCardValue("J♥")).toEqual(10); -}); - -test(`Should return 10 when given a Queen card`, () => { expect(getCardValue("Q♦")).toEqual(10); -}); - -test(`Should return 10 when given a King card`, () => { expect(getCardValue("K♣")).toEqual(10); }); // Case 3: Number Cards (2-10) -test(`Should return 2 when given a 2 card`, () => { +test(`Should return the value of number cards (2-10)`, () => { expect(getCardValue("2♠")).toEqual(2); -}); - -test(`Should return 10 when given a 10 card`, () => { + expect(getCardValue("5♥")).toEqual(5); expect(getCardValue("10♥")).toEqual(10); }); // Case 4: Invalid Cards test(`Should throw an error when given an invalid card`, () => { expect(() => getCardValue("♠J")).toThrow(); -}); - -test(`Should throw an error when given an invalid card`, () => { expect(() => getCardValue("invalid")).toThrow(); -}); - -test(`Should throw an error when given an invalid card`, () => { expect(() => getCardValue("12♠")).toThrow(); -}); - -test(`Should throw an error when given an invalid card`, () => { expect(() => getCardValue("1")).toThrow(); }); From 23b24d4f46ce8baeb05bb1032ff074535a209102 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Sun, 15 Mar 2026 20:30:20 +0000 Subject: [PATCH 08/11] updated to include angle-0 --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 19703a08bf..6115fcb01d 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 @@ -43,7 +43,7 @@ test(`should return "Reflex angle" when (angle > 180)`, () => { }); // Case 6: Invalid angles -test(`should return "Invalid angle" when (angle < 0 || angle >= 360)`, () => { +test(`should return "Invalid angle" when angle <= 0 || angle >= 360`, () => { expect(getAngleType(-1)).toEqual("Invalid angle"); expect(getAngleType(360)).toEqual("Invalid angle"); expect(getAngleType(0)).toEqual("Invalid angle"); From 39e1bfc015cf13100ef2d0c278711f6ffcd35834 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Sun, 15 Mar 2026 21:36:38 +0000 Subject: [PATCH 09/11] made descriptions more concise and added tests for negative numbers --- .../2-is-proper-fraction.test.js | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 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 4ac44bcc23..d66a974f54 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,27 +2,36 @@ // We will use the same function, but write tests for it using Jest in this file. const isProperFraction = require("../implement/2-is-proper-fraction"); -// Special case: numerator is zero -test(`should return true when the numerator is zero`, () => { +// Special case: numerator equals zero +test(`returns true if numerator equals zero`, () => { expect(isProperFraction(0, 1)).toEqual(true); + expect(isProperFraction(0, -2)).toEqual(true); }); -test(`should return true when the denominator is bigger then the numerator` => { +test(`returns true when abs(denominator) > abs(numerator)`, () => { expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(-1, -2)).toEqual(true); + expect(isProperFraction(0, 1)).toEqual(true); }); -test(`should return false when the denominator is equal to the numerator`, () => { +test(`returns false when denominator equals numerator`, () => { expect(isProperFraction(2, 2)).toEqual(false); + expect(isProperFraction(-2, -2)).toEqual(false); }); -test(`should return false when the denominator is smaller than the numerator`, () => { +test(`returns false when abs(denominator) < abs(numerator)`, () => { expect(isProperFraction(2, 1)).toEqual(false); + expect(isProperFraction(-2, 1)).toEqual(false); + expect(isProperFraction(2, -1)).toEqual(false); + expect(isProperFraction(-2, -1)).toEqual(false); }); -test(`should return false when the denominator and the numerator are both zero`, () => { +test(`returns false when 0/0`, () => { expect(isProperFraction(0, 0)).toEqual(false); }); -test(`should return false when the denominator is zero`, () => { +test(`returns false when denominator equals 0`, () => { expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(-1, 0)).toEqual(false); }); From 126aa36237780f446a4b4cc454c17953e260c74d Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Sun, 15 Mar 2026 21:43:38 +0000 Subject: [PATCH 10/11] amended case 5 to exclude 360 --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6115fcb01d..5f6400c42f 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 @@ -36,7 +36,7 @@ test(`should return "Straight angle" when (angle === 180)`, () => { }); // Case 5: Reflex angles -test(`should return "Reflex angle" when (angle > 180)`, () => { +test(`should return "Reflex angle" when (180 < angle > 360)`, () => { expect(getAngleType(181)).toEqual("Reflex angle"); expect(getAngleType(270)).toEqual("Reflex angle"); expect(getAngleType(359)).toEqual("Reflex angle"); From 767fe59589f3d657cd74c6a0ea810af716164786 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 16 Mar 2026 00:11:47 +0000 Subject: [PATCH 11/11] amended to check second character --- .../implement/3-get-card-value.js | 64 +++++++++---------- 1 file changed, 30 insertions(+), 34 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 8efc14733c..d662025376 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,40 +22,39 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - if (typeof card !== "string" || card.length < 2) { - throw new Error("Invalid card"); - } - // Handle "10" which is like "10♥" - if (card.startsWith("10")) { - return 10; - } - //if more than 2 characters and not starting with a 10 card - if (card.length > 2) { + // if card is less than 2 characters or more than 3 characters it is invalid + // and check if not a string + + if (typeof card !== "string" || card.length < 2 || card.length > 3) { throw new Error("Invalid card"); } - // remaining cards must be 2 characters long - const validSuits = ["♠", "♥", "♦", "♣"]; - const suit = card[card.length - 1]; - const firstChar = card[0]; + let firstChar, suit; - // check if picture cards - if (firstChar === "A") return 11; - if (firstChar === "J" || firstChar === "Q" || firstChar === "K") return 10; + if (card.startsWith("10")) { + firstChar = "10"; + suit = card[2]; //if it starts with 10 the third character is the suit + } else { + firstChar = card[0]; //otherwise + suit = card[1]; //the second character is the suit + } + if (!suit || !validSuits.includes(suit)) { + throw new Error("Invalid suit"); + } - // check if number is between 2 and 9, 10 has already been checked for and there should be no other valid cards + // check if picture cards + if (firstChar === "A") return 11; // if Ace return 11 + if (["J", "Q", "K"].includes(firstChar)) return 10; // if Jack, Queen or King return 10 const num = Number(firstChar); + if (num >= 2 && num <= 10) return num; //checks number is between 2 and 10 - if (!isNaN(num) && num >= 2 && num <= 9) { - return num; - // for everything else - } else { - throw new Error("Invalid card"); - } + // for everything else that is invalid + throw new Error("Invalid number"); } + // 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; @@ -80,17 +79,19 @@ assertEquals(getCardValue("K♣"), 10); // Handling invalid cards try { getCardValue("♠J"); - console.error("Error was not thrown for invalid card"); + console.error("Error was not thrown for invalid suit first"); } catch (e) {} try { getCardValue("invalid"); - console.error("Error was not thrown for invalid card"); -} catch (e) {} + console.error("Test failed: invalid card accepted"); +} catch (e) { + console.log("Test passed: Invalid card rejected"); +} try { getCardValue("22"); - console.error("Error was not thrown for invalid card"); + console.error("Error was not thrown for invalid number"); } catch (e) {} console.log(getCardValue("9♠")); @@ -100,16 +101,11 @@ console.log(getCardValue("A♠")); console.log(getCardValue("Q♦")); console.log(getCardValue("K♣")); -// This line will not be reached if an error is thrown as expected -try { - console.error("Error was not thrown for invalid card"); -} catch (e) {} - // What other invalid card cases can you think of? // There could be cards with special characters. -// There could be cards with two numbers rather than a number and a suite +// There could be cards with two numbers rather than a number and a suit // These will not be picked up because the code only checks for if starts with 10 or if the first character // is a number between 2 and 9, so cards like "22" would be valid because the first number // is 2, but the second character is not checked for validity. It is also 2 characters @@ -118,5 +114,5 @@ try { // Since the second character is not checked it could be 2D which is not a valid card but // would be accepted because the first character is 2 and the second character is not checked for validity -// When the card is checked if it begins with 10 it does check if it has a valid suite +// When the card is checked if it begins with 10 it does not check if it has a valid suit // as only the first 2 characters are checked so it could be 10DEVON or 10♥♥.