From 5af0fcbef1420a2713d5345f6ab280a0ac293494 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 21:56:36 +0000 Subject: [PATCH 01/13] 1-get-angle-type.js committed --- .../implement/1-get-angle-type.js | 41 +++++++++++++++++++ 1 file changed, 41 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 9e05a871e2..c75fe4cd2d 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 @@ -1,3 +1,6 @@ +/** + * Original file: + * // Implement a function getAngleType // // When given an angle in degrees, it should return a string indicating the type of angle: @@ -35,3 +38,41 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); +* +* End of original file +*/ + +// 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.) + +function getAngleType(angle) { + // Check for invalid angles first (angles ≤ 0 or ≥ 360) + if (angle <= 0 || angle >= 360) { + return "Invalid angle"; + } + + // Check for specific angle types + if (angle < 90) { + return "Acute angle"; + } else if (angle === 90) { + return "Right angle"; + } else if (angle < 180) { + return "Obtuse angle"; + } else if (angle === 180) { + return "Straight angle"; + } else { // angle > 180 and < 360 (already validated above) + return "Reflex angle"; + } +} + +module.exports = getAngleType; + From 6563d24391b3982d606c9e5b0418b4b613b4e444 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 21:56:53 +0000 Subject: [PATCH 02/13] 2-is-proper-fraction.js committed --- .../implement/2-is-proper-fraction.js | 76 +++++++++++++++++++ 1 file changed, 76 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..055a80d03b 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 @@ -1,3 +1,6 @@ +/** + * Original file: + * // Implement a function isProperFraction, // when given two numbers, a numerator and a denominator, it should return true if // the given numbers form a proper fraction, and false otherwise. @@ -31,3 +34,76 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +* +*/ + +// Implementation of a function isProperFraction, +// when given two numbers, a numerator and a denominator, it should return true if +// the given numbers form a proper fraction, and false otherwise. + +// Assumption: The parameters are valid numbers (not NaN or Infinity). + +function isProperFraction(numerator, denominator) { + // Check if denominator is zero - not a valid fraction + if (denominator === 0) { + return false; + } + + // Check if both numbers are integers + if (!Number.isInteger(numerator) || !Number.isInteger(denominator)) { + return false; + } + + // Check if absolute value of numerator is less than absolute value of denominator + return Math.abs(numerator) < Math.abs(denominator); +} + +module.exports = isProperFraction; + +// Here's our helper again +function assertEquals(actualOutput, targetOutput) { + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); +} + +// TODO: Write tests to cover all cases. +console.log("Running tests for isProperFraction..."); + +// Test 1: Proper fractions with positive numbers +assertEquals(isProperFraction(1, 2), true); // 1/2 is proper +assertEquals(isProperFraction(3, 4), true); // 3/4 is proper +assertEquals(isProperFraction(5, 8), true); // 5/8 is proper +assertEquals(isProperFraction(0, 5), true); // 0/5 is proper (0 < 5) + +// Test 2: Improper fractions with positive numbers +assertEquals(isProperFraction(3, 2), false); // 3/2 is improper +assertEquals(isProperFraction(4, 3), false); // 4/3 is improper +assertEquals(isProperFraction(5, 5), false); // 5/5 is equal, so improper + +// Test 3: Fractions with negative numbers +assertEquals(isProperFraction(-1, 2), true); // |-1| < 2, so proper +assertEquals(isProperFraction(1, -2), true); // 1 < |-2|, so proper +assertEquals(isProperFraction(-3, -4), true); // |-3| < |-4|, so proper +assertEquals(isProperFraction(-3, 2), false); // |-3| > 2, so improper +assertEquals(isProperFraction(3, -2), false); // 3 > |-2|, so improper +assertEquals(isProperFraction(-4, -3), false); // |-4| > |-3|, so improper + +// Test 4: Edge cases with zero +assertEquals(isProperFraction(0, 1), true); // 0/1 is proper +assertEquals(isProperFraction(0, -5), true); // 0/ -5 is proper +assertEquals(isProperFraction(5, 0), false); // Denominator cannot be zero +assertEquals(isProperFraction(0, 0), false); // Denominator cannot be zero + +// Test 5: Non-integer inputs +assertEquals(isProperFraction(1.5, 2), false); // Numerator not integer +assertEquals(isProperFraction(1, 2.5), false); // Denominator not integer +assertEquals(isProperFraction(1.5, 2.5), false); // Both not integers + +// Test 6: Large numbers +assertEquals(isProperFraction(100, 101), true); // 100 < 101 +assertEquals(isProperFraction(1000, 999), false); // 1000 > 999 +assertEquals(isProperFraction(-100, 101), true); // |-100| < 101 + +console.log("Tests completed!"); From 63fc5f07cd51b2922cdfb8533af2d6f19b585907 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 21:57:14 +0000 Subject: [PATCH 03/13] 3-get-card-value.js committed --- .../implement/3-get-card-value.js | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) 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..3af518b4d6 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 @@ -1,3 +1,6 @@ +/** + * Original file: + * // This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck // Implement a function getCardValue, when given a string representing a playing card, @@ -50,3 +53,124 @@ try { } catch (e) {} // What other invalid card cases can you think of? +* +*/ + +// Implementation + +function getCardValue(card) { + // Validate input type + if (typeof card !== 'string' || card.length < 2) { + throw new Error('Invalid card format'); + } + + // Define valid ranks and suits + const validRanks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']; + const validSuits = ['♠', '♥', '♦', '♣']; + + // Extract rank and suit + let rank, suit; + + // Handle '10' which is 2 characters + if (card.startsWith('10') && card.length === 3) { + rank = '10'; + suit = card[2]; + } else if (card.length === 2) { + rank = card[0]; + suit = card[1]; + } else { + throw new Error('Invalid card format'); + } + + // Validate rank and suit + if (!validRanks.includes(rank) || !validSuits.includes(suit)) { + throw new Error('Invalid card format'); + } + + // Return value based on rank + if (rank === 'A') { + return 11; + } else if (['J', 'Q', 'K'].includes(rank)) { + return 10; + } else { + return parseInt(rank, 10); + } +} + +module.exports = getCardValue; + +function assertEquals(actualOutput, targetOutput) { + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); +} + +// Helper function to test error throwing +function assertThrowsError(fn, expectedErrorMessage) { + try { + fn(); + console.error(`Error was not thrown. Expected: ${expectedErrorMessage}`); + } catch (e) { + console.assert( + e.message === expectedErrorMessage, + `Expected error message "${expectedErrorMessage}" but got "${e.message}"` + ); + } +} + +// Tests for valid cards +console.log('Testing valid cards:'); +assertEquals(getCardValue('A♠'), 11); +assertEquals(getCardValue('A♥'), 11); +assertEquals(getCardValue('A♦'), 11); +assertEquals(getCardValue('A♣'), 11); + +assertEquals(getCardValue('2♠'), 2); +assertEquals(getCardValue('3♥'), 3); +assertEquals(getCardValue('4♦'), 4); +assertEquals(getCardValue('5♣'), 5); +assertEquals(getCardValue('6♠'), 6); +assertEquals(getCardValue('7♥'), 7); +assertEquals(getCardValue('8♦'), 8); +assertEquals(getCardValue('9♣'), 9); +assertEquals(getCardValue('10♠'), 10); +assertEquals(getCardValue('10♥'), 10); +assertEquals(getCardValue('10♦'), 10); +assertEquals(getCardValue('10♣'), 10); + +assertEquals(getCardValue('J♠'), 10); +assertEquals(getCardValue('Q♥'), 10); +assertEquals(getCardValue('K♦'), 10); +assertEquals(getCardValue('J♣'), 10); + +// Tests for invalid cards +console.log('\nTesting invalid cards:'); + +// Invalid format +assertThrowsError(() => getCardValue(''), 'Invalid card format'); +assertThrowsError(() => getCardValue('A'), 'Invalid card format'); +assertThrowsError(() => getCardValue('10'), 'Invalid card format'); +assertThrowsError(() => getCardValue('A♠♠'), 'Invalid card format'); +assertThrowsError(() => getCardValue('10♠♠'), 'Invalid card format'); + +// Invalid rank +assertThrowsError(() => getCardValue('1♠'), 'Invalid card format'); +assertThrowsError(() => getCardValue('11♠'), 'Invalid card format'); +assertThrowsError(() => getCardValue('B♠'), 'Invalid card format'); +assertThrowsError(() => getCardValue('X♠'), 'Invalid card format'); + +// Invalid suit +assertThrowsError(() => getCardValue('A♤'), 'Invalid card format'); // Using ♤ instead of ♠ +assertThrowsError(() => getCardValue('A♡'), 'Invalid card format'); // Using ♡ instead of ♥ +assertThrowsError(() => getCardValue('A♢'), 'Invalid card format'); // Using ♢ instead of ♦ +assertThrowsError(() => getCardValue('A♧'), 'Invalid card format'); // Using ♧ instead of ♣ + +// Invalid type +assertThrowsError(() => getCardValue(123), 'Invalid card format'); +assertThrowsError(() => getCardValue(null), 'Invalid card format'); +assertThrowsError(() => getCardValue(undefined), 'Invalid card format'); +assertThrowsError(() => getCardValue({}), 'Invalid card format'); + +console.log('\nAll tests completed!'); + From 175f8b548e816fc61b971fa19427509c01cb4fc6 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 21:57:47 +0000 Subject: [PATCH 04/13] 1-get-angle-type.test.js committed --- .../1-get-angle-type.test.js | 171 ++++++++++++++++++ 1 file changed, 171 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..89c98e38d6 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 @@ -1,7 +1,12 @@ +/** + * Original file + * // This statement loads the getAngleType function you wrote in the implement directory. // 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. @@ -18,3 +23,169 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { // Case 4: Straight angle // Case 5: Reflex angles // Case 6: Invalid angles +* + +// 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.) + +function getAngleType(angle) { + // Check for invalid angles first (angles ≤ 0 or ≥ 360) + if (angle <= 0 || angle >= 360) { + return "Invalid angle"; + } + + // Check for specific angle types + if (angle < 90) { + return "Acute angle"; + } else if (angle === 90) { + return "Right angle"; + } else if (angle < 180) { + return "Obtuse angle"; + } else if (angle === 180) { + return "Straight angle"; + } else { // angle > 180 and < 360 (already validated above) + 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; + +// 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) { + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); +} +* +* +// TODO: Write tests to cover all cases, including boundary and invalid cases. +* +* End of original file +*/ + +// 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) { + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); +} + +console.log("Running getAngleType tests...\n"); + +// Test Case 1: Acute angles (greater than 0° and less than 90°) +console.log("Testing Acute angles:"); +assertEquals(getAngleType(1), "Acute angle"); +assertEquals(getAngleType(45), "Acute angle"); +assertEquals(getAngleType(89), "Acute angle"); +assertEquals(getAngleType(89.9), "Acute angle"); + +// Test Case 2: Right angle (exactly 90°) +console.log("\nTesting Right angle:"); +assertEquals(getAngleType(90), "Right angle"); +assertEquals(getAngleType(90.0), "Right angle"); + +// Test Case 3: Obtuse angles (greater than 90° and less than 180°) +console.log("\nTesting Obtuse angles:"); +assertEquals(getAngleType(91), "Obtuse angle"); +assertEquals(getAngleType(135), "Obtuse angle"); +assertEquals(getAngleType(179), "Obtuse angle"); +assertEquals(getAngleType(179.9), "Obtuse angle"); + +// Test Case 4: Straight angle (exactly 180°) +console.log("\nTesting Straight angle:"); +assertEquals(getAngleType(180), "Straight angle"); +assertEquals(getAngleType(180.0), "Straight angle"); + +// Test Case 5: Reflex angles (greater than 180° and less than 360°) +console.log("\nTesting Reflex angles:"); +assertEquals(getAngleType(181), "Reflex angle"); +assertEquals(getAngleType(270), "Reflex angle"); +assertEquals(getAngleType(359), "Reflex angle"); +assertEquals(getAngleType(359.9), "Reflex angle"); + +// Test Case 6: Invalid angles (≤ 0° or ≥ 360°) +console.log("\nTesting Invalid angles:"); +// Zero and negative angles +assertEquals(getAngleType(0), "Invalid angle"); +assertEquals(getAngleType(-1), "Invalid angle"); +assertEquals(getAngleType(-45), "Invalid angle"); +assertEquals(getAngleType(-90), "Invalid angle"); +assertEquals(getAngleType(-180), "Invalid angle"); +assertEquals(getAngleType(-360), "Invalid angle"); + +// Angles ≥ 360 +assertEquals(getAngleType(360), "Invalid angle"); +assertEquals(getAngleType(361), "Invalid angle"); +assertEquals(getAngleType(400), "Invalid angle"); +assertEquals(getAngleType(720), "Invalid angle"); + +console.log("\nAll tests completed!"); + + +// getAngleType.test.js +// const getAngleType = require('./path-to-your-file'); + +describe('getAngleType', () => { + test('should return "Acute angle" for angles between 0 and 90 exclusive', () => { + expect(getAngleType(1)).toBe("Acute angle"); + expect(getAngleType(45)).toBe("Acute angle"); + expect(getAngleType(89)).toBe("Acute angle"); + expect(getAngleType(89.9)).toBe("Acute angle"); + }); + + test('should return "Right angle" for exactly 90 degrees', () => { + expect(getAngleType(90)).toBe("Right angle"); + expect(getAngleType(90.0)).toBe("Right angle"); + }); + + test('should return "Obtuse angle" for angles between 90 and 180 exclusive', () => { + expect(getAngleType(91)).toBe("Obtuse angle"); + expect(getAngleType(135)).toBe("Obtuse angle"); + expect(getAngleType(179)).toBe("Obtuse angle"); + expect(getAngleType(179.9)).toBe("Obtuse angle"); + }); + + test('should return "Straight angle" for exactly 180 degrees', () => { + expect(getAngleType(180)).toBe("Straight angle"); + expect(getAngleType(180.0)).toBe("Straight angle"); + }); + + test('should return "Reflex angle" for angles between 180 and 360 exclusive', () => { + expect(getAngleType(181)).toBe("Reflex angle"); + expect(getAngleType(270)).toBe("Reflex angle"); + expect(getAngleType(359)).toBe("Reflex angle"); + expect(getAngleType(359.9)).toBe("Reflex angle"); + }); + + test('should return "Invalid angle" for angles ≤ 0 or ≥ 360', () => { + // Zero and negative angles + expect(getAngleType(0)).toBe("Invalid angle"); + expect(getAngleType(-1)).toBe("Invalid angle"); + expect(getAngleType(-45)).toBe("Invalid angle"); + expect(getAngleType(-90)).toBe("Invalid angle"); + expect(getAngleType(-180)).toBe("Invalid angle"); + expect(getAngleType(-360)).toBe("Invalid angle"); + + // Angles ≥ 360 + expect(getAngleType(360)).toBe("Invalid angle"); + expect(getAngleType(361)).toBe("Invalid angle"); + expect(getAngleType(400)).toBe("Invalid angle"); + expect(getAngleType(720)).toBe("Invalid angle"); + }); +}); + From aef053a9e66f3886806d4e75d5610cb3af7402d2 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 21:58:03 +0000 Subject: [PATCH 05/13] 2-is-proper-fraction.test.js committed --- .../2-is-proper-fraction.test.js | 121 ++++++++++++++++++ 1 file changed, 121 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..81ea7363f7 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 @@ -1,3 +1,6 @@ +/** + * Original file: + * // This statement loads the isProperFraction function you wrote in the implement directory. // We will use the same function, but write tests for it using Jest in this file. const isProperFraction = require("../implement/2-is-proper-fraction"); @@ -8,3 +11,121 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +* +*/ + +// This statement loads the isProperFraction function written in the implement directory. +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. + +describe('isProperFraction', () => { + // Test 1: Proper fractions with positive numbers + describe('positive proper fractions', () => { + test('should return true when numerator < denominator', () => { + expect(isProperFraction(1, 2)).toBe(true); + expect(isProperFraction(3, 4)).toBe(true); + expect(isProperFraction(5, 8)).toBe(true); + }); + }); + + // Test 2: Improper fractions with positive numbers + describe('positive improper fractions', () => { + test('should return false when numerator > denominator', () => { + expect(isProperFraction(3, 2)).toBe(false); + expect(isProperFraction(4, 3)).toBe(false); + }); + + test('should return false when numerator = denominator', () => { + expect(isProperFraction(5, 5)).toBe(false); + expect(isProperFraction(1, 1)).toBe(false); + }); + }); + + // Test 3: Fractions with negative numbers + describe('fractions with negative numbers', () => { + test('should return true when |numerator| < |denominator|', () => { + expect(isProperFraction(-1, 2)).toBe(true); + expect(isProperFraction(1, -2)).toBe(true); + expect(isProperFraction(-3, -4)).toBe(true); + }); + + test('should return false when |numerator| >= |denominator|', () => { + expect(isProperFraction(-3, 2)).toBe(false); + expect(isProperFraction(3, -2)).toBe(false); + expect(isProperFraction(-4, -3)).toBe(false); + expect(isProperFraction(-2, -2)).toBe(false); + }); + }); + + // Test 4: Zero cases + describe('fractions with zero', () => { + test('should return true when numerator is zero and denominator non-zero', () => { + expect(isProperFraction(0, 1)).toBe(true); + expect(isProperFraction(0, -5)).toBe(true); + }); + + test('should return false when denominator is zero', () => { + expect(isProperFraction(1, 0)).toBe(false); + expect(isProperFraction(0, 0)).toBe(false); + expect(isProperFraction(-5, 0)).toBe(false); + }); + }); + + // Test 5: Non-integer inputs + describe('non-integer inputs', () => { + test('should return false when numerator is not an integer', () => { + expect(isProperFraction(1.5, 2)).toBe(false); + expect(isProperFraction(1.1, 3)).toBe(false); + }); + + test('should return false when denominator is not an integer', () => { + expect(isProperFraction(1, 2.5)).toBe(false); + expect(isProperFraction(3, 4.2)).toBe(false); + }); + + test('should return false when both are not integers', () => { + expect(isProperFraction(1.5, 2.5)).toBe(false); + expect(isProperFraction(3.14, 1.5)).toBe(false); + }); + }); + + // Test 6: Large numbers + describe('large numbers', () => { + test('should handle large proper fractions', () => { + expect(isProperFraction(100, 101)).toBe(true); + expect(isProperFraction(1000, 1001)).toBe(true); + expect(isProperFraction(999999, 1000000)).toBe(true); + }); + + test('should handle large improper fractions', () => { + expect(isProperFraction(1000, 999)).toBe(false); + expect(isProperFraction(1000000, 999999)).toBe(false); + }); + }); + + // Test 7: Edge cases with negative large numbers + describe('negative large numbers', () => { + test('should handle negative large proper fractions', () => { + expect(isProperFraction(-100, 101)).toBe(true); + expect(isProperFraction(100, -101)).toBe(true); + expect(isProperFraction(-1000, -1001)).toBe(true); + }); + + test('should handle negative large improper fractions', () => { + expect(isProperFraction(-101, 100)).toBe(false); + expect(isProperFraction(101, -100)).toBe(false); + expect(isProperFraction(-1001, -1000)).toBe(false); + }); + }); + + // Test 8: Special cases with Number.MIN_SAFE_INTEGER and MAX_SAFE_INTEGER + describe('edge integer values', () => { + test('should handle minimum and maximum safe integers', () => { + expect(isProperFraction(Number.MAX_SAFE_INTEGER - 1, Number.MAX_SAFE_INTEGER)).toBe(true); + expect(isProperFraction(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER - 1)).toBe(false); + expect(isProperFraction(Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)).toBe(false); + }); + }); +}); + From 766784ab7e09c1236ea328aa2570f0de214cb8ae Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 21:58:20 +0000 Subject: [PATCH 06/13] 3-get-card-value.test.js committed --- .../3-get-card-value.test.js | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) 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..e564687cfa 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,3 +1,6 @@ +/** + * Original file: + * // 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 getCardValue = require("../implement/3-get-card-value"); @@ -17,4 +20,123 @@ 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 +* +*/ + +// Implementation + +const getCardValue = require("../implement/3-get-card-value"); + +describe('getCardValue', () => { + // Test all valid cards + describe('valid cards', () => { + // Test all aces + test('should return 11 for aces', () => { + expect(getCardValue('A♠')).toBe(11); + expect(getCardValue('A♥')).toBe(11); + expect(getCardValue('A♦')).toBe(11); + expect(getCardValue('A♣')).toBe(11); + }); + + // Test all number cards + test('should return correct numeric value for number cards', () => { + expect(getCardValue('2♠')).toBe(2); + expect(getCardValue('3♥')).toBe(3); + expect(getCardValue('4♦')).toBe(4); + expect(getCardValue('5♣')).toBe(5); + expect(getCardValue('6♠')).toBe(6); + expect(getCardValue('7♥')).toBe(7); + expect(getCardValue('8♦')).toBe(8); + expect(getCardValue('9♣')).toBe(9); + }); + + // Test 10 specifically (since it's two digits) + test('should return 10 for ten cards', () => { + expect(getCardValue('10♠')).toBe(10); + expect(getCardValue('10♥')).toBe(10); + expect(getCardValue('10♦')).toBe(10); + expect(getCardValue('10♣')).toBe(10); + }); + + // Test all face cards + test('should return 10 for face cards', () => { + expect(getCardValue('J♠')).toBe(10); + expect(getCardValue('Q♥')).toBe(10); + expect(getCardValue('K♦')).toBe(10); + expect(getCardValue('J♣')).toBe(10); + }); + }); + + // Test invalid inputs + describe('invalid inputs', () => { + // Test invalid formats + test('should throw error for empty string', () => { + expect(() => getCardValue('')).toThrow('Invalid card format'); + }); + + test('should throw error for card without suit', () => { + expect(() => getCardValue('A')).toThrow('Invalid card format'); + expect(() => getCardValue('10')).toThrow('Invalid card format'); + }); + + test('should throw error for card with extra characters', () => { + expect(() => getCardValue('A♠♠')).toThrow('Invalid card format'); + expect(() => getCardValue('10♠♠')).toThrow('Invalid card format'); + }); + + // Test invalid ranks + test('should throw error for invalid rank', () => { + expect(() => getCardValue('1♠')).toThrow('Invalid card format'); + expect(() => getCardValue('11♠')).toThrow('Invalid card format'); + expect(() => getCardValue('B♠')).toThrow('Invalid card format'); + expect(() => getCardValue('X♠')).toThrow('Invalid card format'); + }); + + // Test invalid suits + test('should throw error for invalid suit', () => { + // Using similar-looking but incorrect suit symbols + expect(() => getCardValue('A♤')).toThrow('Invalid card format'); // ♤ instead of ♠ + expect(() => getCardValue('A♡')).toThrow('Invalid card format'); // ♡ instead of ♥ + expect(() => getCardValue('A♢')).toThrow('Invalid card format'); // ♢ instead of ♦ + expect(() => getCardValue('A♧')).toThrow('Invalid card format'); // ♧ instead of ♣ + }); + + // Test wrong order + test('should throw error when suit comes before rank', () => { + expect(() => getCardValue('♠A')).toThrow('Invalid card format'); + expect(() => getCardValue('♥10')).toThrow('Invalid card format'); + }); + + // Test invalid types + test('should throw error for non-string inputs', () => { + expect(() => getCardValue(123)).toThrow('Invalid card format'); + expect(() => getCardValue(null)).toThrow('Invalid card format'); + expect(() => getCardValue(undefined)).toThrow('Invalid card format'); + expect(() => getCardValue({})).toThrow('Invalid card format'); + expect(() => getCardValue([])).toThrow('Invalid card format'); + }); + }); + + // Test edge cases + describe('edge cases', () => { + test('should handle lowercase ranks? (assuming they should be invalid)', () => { + // This test checks if the function is case-sensitive + // According to spec, ranks should be uppercase + expect(() => getCardValue('a♠')).toThrow('Invalid card format'); + expect(() => getCardValue('j♥')).toThrow('Invalid card format'); + }); + + test('should handle whitespace', () => { + // Cards shouldn't have whitespace according to spec + expect(() => getCardValue('A ♠')).toThrow('Invalid card format'); + expect(() => getCardValue(' 10♥')).toThrow('Invalid card format'); + }); + + test('should throw error for completely invalid strings', () => { + expect(() => getCardValue('invalid')).toThrow('Invalid card format'); + expect(() => getCardValue('xyz')).toThrow('Invalid card format'); + expect(() => getCardValue('hello world')).toThrow('Invalid card format'); + }); + }); +}); From d41986340e615943b7b30db0e93ffc3f4609d7d2 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 22:02:02 +0000 Subject: [PATCH 07/13] Added package.json and package-lock.json --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bde36e5302..ed63450dce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ node_modules .DS_Store .vscode -**/.DS_Store \ No newline at end of file +*package.json +*package-lock.json +**/.DS_Store From 6b16709c709e09d767548e86c625069ff81eb385 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 22:10:51 +0000 Subject: [PATCH 08/13] Corrected some mispelling --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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 89c98e38d6..e46d731ba7 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 @@ -76,8 +76,8 @@ function assertEquals(actualOutput, targetOutput) { * End of original file */ -// This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass +// Implementation + function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, @@ -136,10 +136,6 @@ assertEquals(getAngleType(720), "Invalid angle"); console.log("\nAll tests completed!"); - -// getAngleType.test.js -// const getAngleType = require('./path-to-your-file'); - describe('getAngleType', () => { test('should return "Acute angle" for angles between 0 and 90 exclusive', () => { expect(getAngleType(1)).toBe("Acute angle"); From d4a9caeadb7cf7b6a0b360926a1de41b23eb5d70 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 22:11:19 +0000 Subject: [PATCH 09/13] Corrected some mispelling --- .../implement/1-get-angle-type.js | 10 +--------- 1 file changed, 1 insertion(+), 9 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 c75fe4cd2d..98f2bc4267 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 @@ -42,15 +42,7 @@ assertEquals(right, "Right angle"); * End of original file */ -// 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. +// Implementation a function getAngleType // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) From 273d39fc41ef6944f5cb184b331a2a7b02ce3881 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 22:15:39 +0000 Subject: [PATCH 10/13] 2-is-proper-fraction.js committed --- .../implement/2-is-proper-fraction.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 055a80d03b..639c707a27 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 @@ -35,9 +35,11 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); * +* End of the original file */ -// Implementation of a function isProperFraction, +// Implementation of a function isProperFraction + // when given two numbers, a numerator and a denominator, it should return true if // the given numbers form a proper fraction, and false otherwise. @@ -60,7 +62,7 @@ function isProperFraction(numerator, denominator) { module.exports = isProperFraction; -// Here's our helper again +// Here's our helper function again function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, From 155127d34b0203a8aaea6fea89ef7ce50aa9c082 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 22:16:02 +0000 Subject: [PATCH 11/13] 2-is-proper-fraction.test.js committed --- .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 3 ++- 1 file changed, 2 insertions(+), 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 81ea7363f7..38da52b6b5 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 @@ -12,12 +12,13 @@ test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); * +* End of original file */ // This statement loads the isProperFraction function written in the implement directory. 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. +// TODO: Tests in Jest syntax covering all combinations of positives, negatives, zeros, and other categories. describe('isProperFraction', () => { // Test 1: Proper fractions with positive numbers From 2fe0a727bfbb0a2da28fd0cc842da98a834d43fa Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 22:19:31 +0000 Subject: [PATCH 12/13] 3-get-card-value.test.js committed --- .../rewrite-tests-with-jest/3-get-card-value.test.js | 1 + 1 file changed, 1 insertion(+) 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 e564687cfa..eca65aa688 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 @@ -21,6 +21,7 @@ test(`Should return 11 when given an ace card`, () => { // please refer to the Jest documentation: // https://jestjs.io/docs/expect#tothrowerror * +* End of original file */ // Implementation From 18975bc4b9576e949b4ffc8460db52b28f172abb Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Tue, 3 Mar 2026 22:19:54 +0000 Subject: [PATCH 13/13] 3-get-card-value.js committed --- .../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 3af518b4d6..a3825b7d6f 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 @@ -54,6 +54,7 @@ try { // What other invalid card cases can you think of? * +* End of original file */ // Implementation