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..8aa3a81d6e 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 > 0 && 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";} + if (angle > 180 && angle < 360) {return "Reflex angle";} + else return "Invalid angle" } // The line below allows us to load the getAngleType function into tests in other files. @@ -33,5 +38,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"); + +assertEquals(getAngleType(-1), "Invalid angle"); +assertEquals(getAngleType(0), "Invalid angle"); +assertEquals(getAngleType(360), "Invalid angle"); +assertEquals(getAngleType(10000), "Invalid angle"); + +assertEquals(getAngleType(1), "Acute angle"); +assertEquals(getAngleType(45), "Acute angle"); +assertEquals(getAngleType(89.99), "Acute angle"); +assertEquals(getAngleType(45), "Acute angle"); + +assertEquals(getAngleType(90), "Right angle"); + +assertEquals(getAngleType(91), "Obtuse angle"); +assertEquals(getAngleType(179), "Obtuse angle"); + +assertEquals(getAngleType(180), "Straight angle"); + +assertEquals(getAngleType(181), "Reflex angle"); +assertEquals(getAngleType(359), "Reflex 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 970cb9b641..bbf43256ad 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,13 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(0.1, 2), true); +assertEquals(isProperFraction(-1, 2), true); +assertEquals(isProperFraction(1, -2), true); +assertEquals(isProperFraction(100000, 200000), true); + +assertEquals(isProperFraction(2, 1), false); +assertEquals(isProperFraction(2, 0.1), false); +assertEquals(isProperFraction(2, -1), false); +assertEquals(isProperFraction(-2, 1), false); +assertEquals(isProperFraction(200000, 100000), false); 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..7ef966a225 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,15 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const suits = ["♠", "♥", "♦", "♣"]; + if (!suits.includes(card.slice(-1))) {throw new Error("Invalid card");} + + const value = card.slice(0, -1); + if (value == 10) {return 10;} + if (value >= 2 && value <= 9) {return Number(value);} + if (value == "J" || value == "Q" || value == "K") {return 10;} + if (value == "A") {return 11;} + else throw new Error("Invalid card"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -39,7 +47,13 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: +assertEquals(getCardValue("2♠"), 2); assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("10♥"), 10); +assertEquals(getCardValue("J♥"), 10); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("K♦"), 10); +assertEquals(getCardValue("A♣"), 11); // Handling invalid cards try { @@ -52,3 +66,8 @@ try { } // What other invalid card cases can you think of? +// decimal numbers +// cards without suits +// numbers above 10 +// negative numbers +// letters outside J K Q and A \ No newline at end of file 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..dd6b1a8358 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -10,11 +10,43 @@ 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(89.99)).toEqual("Acute angle"); }); // Case 2: Right angle +test(`should return "Right angle" when angle == 90)`, () => { + // Test right angle +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.01)).toEqual("Obtuse angle"); + expect(getAngleType(135)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test(`should return "Straight angle" when angle == 180)`, () => { + // Test straight angle +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(270)).toEqual("Reflex angle"); + expect(getAngleType(359.99)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test(`should return "Invalid Angle" when invalid`, () => { + // Test various invalid angles + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(10000)).toEqual("Invalid angle"); + expect(getAngleType("Im not an angle")).toEqual("Invalid angle"); +}); \ No newline at end of file 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..da03352127 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,53 @@ 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`, () => { +test('should return true when the numerator is less than the denominator (1 and 2)', () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); + +test('should return true when the numerator is less than the denominator using decimals (0.1 and 2)', () => { + expect(isProperFraction(0.1, 2)).toEqual(true); +}); + +test('should return true when the numerator is less than the denominator and numerator is negative (-1 and 2)', () => { + expect(isProperFraction(-1, 2)).toEqual(true); +}); + +test('should return true when the numerator is less than the denominator and denominator is negative (1 and -2)', () => { + expect(isProperFraction(1, -2)).toEqual(true); +}); + +test('should return true for large numbers when numerator is less than denominator (1,000,000 and 2,000,000)', () => { + expect(isProperFraction(1000000, 2000000)).toEqual(true); +}); + + +test('should return false when the numerator is greater than the denominator (2 and 1)', () => { + expect(isProperFraction(2, 1)).toEqual(false); +}); + +test('should return false when the numerator is larger than the denominator with decimals (2 and 0.1)', () => { + expect(isProperFraction(2, 0.1)).toEqual(false); +}); + +test('should return false when the numerator is larger than the denominator (2 and -1)', () => { + expect(isProperFraction(2, -1)).toEqual(false); +}); + +test('should return false when the numerator is larger than the denominator (-2 and 1)', () => { + expect(isProperFraction(-2, 1)).toEqual(false); +}); + +test('should return false for large numbers when the numerator is larger than the denominator (2,000,000 and 1,000,000)', () => { + expect(isProperFraction(2000000, 1000000)).toEqual(false); +}); + +// Special case: denominator is zero +test('should return false when denominator is zero', () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +// Special case: numerator is string +test('should return false when denominator is zero', () => { + expect(isProperFraction("hello", 0)).toEqual(false); +}); \ No newline at end of file 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..2f626fbec3 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,12 +9,62 @@ 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) +// Number Cards (2-10) +test(`Should return 2 when given a "2♠" card`, () => { + expect(getCardValue("2♠")).toEqual(2); +}); + +test(`Should return 9 when given a "9♠" card`, () => { + expect(getCardValue("9♠")).toEqual(9); +}); + +test(`Should return 10 when given a "10♥" card`, () => { + expect(getCardValue("10♥")).toEqual(10); +}); + +// Face Cards (J, Q, K) +test(`Should return 10 when given a Jack "J♥" card`, () => { + expect(getCardValue("J♥")).toEqual(10); +}); + +test(`Should return 10 when given a Queen "Q♦" card`, () => { + expect(getCardValue("Q♦")).toEqual(10); +}); + +test(`Should return 10 when given a King "K♦" card`, () => { + expect(getCardValue("K♦")).toEqual(10); +}); + // Invalid Cards +test(`Should return error when given a string`, () => { + expect(() => { getCardValue("invalid");}).toThrow("Invalid card"); +}); + +test(`Should return error when given a wrong letter`, () => { + expect(() => { getCardValue("L♦");}).toThrow("Invalid card"); +}); + +test(`Should return error when given a wrong letter`, () => { + expect(() => { getCardValue("L♦");}).toThrow("Invalid card"); +}); + +test(`Should return error when given a wrong number`, () => { + expect(() => { getCardValue("11♦");}).toThrow("Invalid card"); +}); + +test(`Should return error when given a wrong order`, () => { + expect(() => { getCardValue("♦2");}).toThrow("Invalid card"); +}); + +test(`Should return error when given no suit`, () => { + expect(() => { getCardValue("3");}).toThrow("Invalid card"); +}); + +test(`Should return error when given only suit`, () => { + expect(() => { getCardValue("♦");}).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 - +// https://jestjs.io/docs/expect#tothrowerror \ No newline at end of file