From 684e9e30a9d8d8e44ac91f95b5ea8b796ecbdf0e Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 26 Jul 2026 16:40:52 +0100 Subject: [PATCH 1/6] rewrite tests with jests complete Implemented the getAngleType function to classify angles and added comprehensive test cases for different angle types, including acute, right, obtuse, reflex, zero, and complete angles, as well as invalid angles. --- .../implement/1-get-angle-type.js | 55 ++++++++++++++++++- 1 file changed, 52 insertions(+), 3 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..56628d5db1 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -16,6 +16,30 @@ function getAngleType(angle) { // TODO: Implement this function + if (angle > 0 && angle < 90){ + return "Acute angle"; + } + else if (angle == 90){ + return "Right angle"; + } + else if (angle > 90 && angle < 180){ + return "Obtuse angle"; + } + else if (angle == 180){ + return "Straight angle"; + } + else if (angle > 180 && angle < 360){ + return "Reflex angle"; + } + else if(angle === 0){ + return "Zero angle" + } + else if(angle === 360){ + return "Complete angle" + } + else{ + return "Invalid angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. @@ -32,6 +56,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"); + +// Tests for right angles +assertEquals(getAngleType(90), "Right angle"); + +// Tests for acute angles +assertEquals(getAngleType(56), "Acute angle"); +assertEquals(getAngleType(1), "Acute angle"); + +// Test for a straight line +assertEquals(getAngleType(180), "Straight angle"); + +// Test for obtuse angle +assertEquals(getAngleType(95), "Obtuse angle"); +assertEquals(getAngleType(160), "Obtuse angle"); +assertEquals(getAngleType(102), "Obtuse angle"); + +// Test for reflex angle +assertEquals(getAngleType(181), "Reflex angle"); +assertEquals(getAngleType(249), "Reflex angle"); + +// Test for invalid angles +assertEquals(getAngleType(-980), "Invalid angle"); +assertEquals(getAngleType(9082), "Invalid angle"); +assertEquals(getAngleType(672), "Invalid angle"); +// +assertEquals(getAngleType(0), "Zero angle"); +assertEquals(getAngleType(360), "Complete angle"); +console.log("Execution finished! If any test failed, console.assert errors will appear above."); From 31d9a17fbc08b0744b68661e2c219ba9dfd0233d Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 26 Jul 2026 16:41:38 +0100 Subject: [PATCH 2/6] rewrite tests with jests complete Implemented the isProperFraction function to check if a fraction is proper and added test cases for various scenarios. --- .../implement/2-is-proper-fraction.js | 9 +++++++++ 1 file changed, 9 insertions(+) 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..a5f7be1dad 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,6 +11,7 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { + return Math.abs(numerator) < Math.abs(denominator); // TODO: Implement this function } @@ -31,3 +32,11 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(93, 112), true); +assertEquals(isProperFraction(2, 1), false); +assertEquals(isProperFraction(80, 80), false); +assertEquals(isProperFraction(-10, -15), true); +assertEquals(isProperFraction(-35, 25), false); +assertEquals(isProperFraction(1, 0), false); +assertEquals(isProperFraction(0, 1), true); +console.log("Execution finished! If any test failed, console.assert errors will appear above."); From f72b4fa5ca026f33db3e674933cd3451b9a30ec0 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 26 Jul 2026 16:44:34 +0100 Subject: [PATCH 3/6] rewrite tests with jests complete Implement getCardValue function to validate and return card values. Add tests for valid and invalid card inputs. --- .../implement/3-get-card-value.js | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) 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 ff5c532e1d..ec222233cb 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -23,8 +23,44 @@ function getCardValue(card) { // TODO: Implement this function + if (typeof card !== "string" || card.length < 2 || card.length > 3) { + throw new Error("Invalid card"); + } + const ranks = [ + "A", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "J", + "Q", + "K", + ]; + const suits = ["♠", "♥", "♦", "♣"]; +let rank = card.slice(0, -1)// This is extracting the bit before the suits alone +let suit = card.slice(-1) // THis is extracting the suit in the string + + if(!ranks.includes(rank)){ + throw new Error("Invalid card") + } + if (!suits.includes(suit)){ + throw new Error("Invalid card") + } + if (rank === "A"){ + return 11} + if (["J", "K", "Q"].includes(rank)){ + return 10 + } + else{ + 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. module.exports = getCardValue; @@ -40,6 +76,20 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("A♠"), 11); +assertEquals(getCardValue("J♣"), 10); +assertEquals(getCardValue("K♦"), 10); +assertEquals(getCardValue("5♣"), 5); +assertEquals(getCardValue("2♣"), 2); +assertEquals(getCardValue("10♥"), 10); +assertEquals(getCardValue("6♥"), 6); +assertEquals(getCardValue("5♥"), 5); +assertEquals(getCardValue("8♥"), 8); +assertEquals(getCardValue("4♥"), 4); +assertEquals(getCardValue("3♥"), 3); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("7♥"), 7); + // Handling invalid cards try { @@ -52,3 +102,17 @@ try { } // What other invalid card cases can you think of? + +try { + getCardValue("A"); + console.error("Error not thrown for invalid card missing suit"); +} catch (e) { + console.log("Error thrown for invalid card missing suit🎉"); +} + +try { + getCardValue(""); + console.error("Error not thrown for invalid card containing empty string"); +} catch (e) { + console.log("Error thrown for invalid card containing empty string"); +} From 4b854104302b4aac9244b28c190a98f4ca15522c Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 26 Jul 2026 16:45:41 +0100 Subject: [PATCH 4/6] jests test written for get angle type --- .../1-get-angle-type.test.js | 30 +++++++++++++++++++ 1 file changed, 30 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 d777f348d3..a1c4134225 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,37 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // 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 < angle < 180)`, () => { + // Test various obtuse angles, including boundary cases + expect(getAngleType(90.1)).toEqual("Obtuse angle"); + expect(getAngleType(179.9)).toEqual("Obtuse angle"); + expect(getAngleType(99.8)).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 "Reflex angle" when (180 < angle < 360)`, () => { + // Test various Reflex angles, including boundary cases + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(256)).toEqual("Reflex angle"); + expect(getAngleType(359.9)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test(`should return "Invalid angle" when (angle > 360 || angle < 0)`, () => { + // Test various invalid angles + expect(getAngleType(-180)).toEqual("Invalid angle"); + expect(getAngleType(561)).toEqual("Invalid angle"); + expect(getAngleType(980)).toEqual("Invalid angle"); +}); +test(`should return "Zero angle" when (angle === 0)`, () => { + expect(getAngleType(0)).toEqual("Zero angle"); +}); +test(`should return "Zero angle" when (angle === 360)`, () => { + expect(getAngleType(360)).toEqual("Complete angle"); +}); From 18524d2b26124e2d8fb08209c82766d395b35689 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 26 Jul 2026 16:46:40 +0100 Subject: [PATCH 5/6] rewrite tests with jests complete --- .../2-is-proper-fraction.test.js | 18 ++++++++++++++++++ 1 file changed, 18 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 7f087b2ba1..a7e7581d42 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 @@ -8,3 +8,21 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +// proper fractions +test(`should return true when denominator is higher than numerator`, () => { + expect(isProperFraction(0, 1)).toEqual(true); + expect(isProperFraction(2, 7)).toEqual(true); + expect(isProperFraction(89, 101)).toEqual(true); +}); +// Special case: numerator or denominator is negative, we consider the absolute values for fractions so ignore the negative signs +test(`should return true when negative/positive numerator is less than the positive/negative denominator`, () => { + expect(isProperFraction(-20, -30)).toEqual(true); + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(58, -68)).toEqual(true); +}); +// Special case: numerator or denominator is negative, we consider the absolute values for fractions so ignore the negative signs +test(`should return false when negative/positive numerator is greater than the positive/negative denominator`, () => { + expect(isProperFraction(-50, 10)).toEqual(false); + expect(isProperFraction(100, 2)).toEqual(false); + expect(isProperFraction(-1, -0)).toEqual(false); +}); From b5fc39ca1243fa8b8ddab014ec3fb86cdef9bd98 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 26 Jul 2026 16:47:20 +0100 Subject: [PATCH 6/6] rewrite tests with jests complete Added Jest tests for card value function covering Aces, face cards, number cards, and invalid cards. --- .../3-get-card-value.test.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 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 cf7f9dae2e..52a9bc5caf 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 @@ -3,12 +3,29 @@ 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); }); - +//Case 2: Face Cards(J, Q,K) +test(`Should return 10 when given a face card`, () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("K♣")).toEqual(10); + expect(getCardValue("J♦")).toEqual(10); +}); +//case 3: Number Cards (2-10) +test(`Should return the number when given a number card`, () => { + expect(getCardValue("4♠")).toEqual(4); + expect(getCardValue("9♣")).toEqual(9); + expect(getCardValue("2♦")).toEqual(2); +}); +//Case 4: Invalid cards +test(`Should return the invalid suit, invalid card or invalid card`, () => { + expect(() => getCardValue("Apple")).toThrow("Invalid card"); + expect(() => getCardValue("4🎉")).toThrow("Invalid card"); + expect(() => getCardValue("20♣")).toThrow("Invalid card"); +}); // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) @@ -16,5 +33,4 @@ 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 - +// https://jestjs.io/docs/expecttothrowerror