From 57e4cd445101b686ace9811065a6bf6997811ae0 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 17 Feb 2026 17:29:59 +0000 Subject: [PATCH 1/8] added tests to check for proper fraction --- .../implement/1-get-angle-type.js | 74 ++++++++++++++----- 1 file changed, 55 insertions(+), 19 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 9e05a871e..2ce43ab79 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,29 +1,34 @@ // Implement a function getAngleType -// -// When given an angle in degrees, it should return a string indicating the type of angle: -// - "Acute angle" for angles greater than 0° and less than 90° -// - "Right angle" for exactly 90° -// - "Obtuse angle" for angles greater than 90° and less than 180° -// - "Straight angle" for exactly 180° -// - "Reflex angle" for angles greater than 180° and less than 360° -// - "Invalid angle" for angles outside the valid range. - -// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. +// Build up your function case by case, writing tests as you go +// The first test and case is written for you. The next case has a test, but no code. +// Execute this script in your terminal +// node 1-get-angle-type.js +// The assertion error will tell you what the expected output is +// Write the code to pass the test +// Then, write the next test! :) Go through this process until all the cases are implemented function getAngleType(angle) { - // TODO: Implement this function + if (angle === 90) { + return "Right angle"; + } + if (angle < 90) { + return "Acute angle"; + } + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + if (angle === 180) { + return "Straight angle"; + } + 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 +// we're going to use this helper function 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, @@ -31,7 +36,38 @@ function assertEquals(actualOutput, targetOutput) { ); } -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles +// Acceptance criteria: + +// Given an angle in degrees, +// When the function getAngleType is called with this angle, +// Then it should: + +// Case 1: Identify Right Angles: +// When the angle is exactly 90 degrees, +// Then the function should return "Right angle" const right = getAngleType(90); assertEquals(right, "Right angle"); + +// Case 2: Identify Acute Angles: +// When the angle is less than 90 degrees, +// Then the function should return "Acute angle" +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +// Case 3: Identify Obtuse Angles: +// When the angle is greater than 90 degrees and less than 180 degrees, +// Then the function should return "Obtuse angle" +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + +// Case 4: Identify Straight Angles: +// When the angle is exactly 180 degrees, +// Then the function should return "Straight angle" +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +// Case 5: Identify Reflex Angles: +// When the angle is greater than 180 degrees and less than 360 degrees, +// Then the function should return "Reflex angle" +const reflex = getAngleType(340); +assertEquals(reflex, "Reflex angle"); From bfa31ef7010144d7ab22e597a76515fdaa8ede1f Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:06:47 +0000 Subject: [PATCH 2/8] Add test case to verify countChar returns 0 for non-existent character --- Sprint-3/2-practice-tdd/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf..0425fe182 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,10 @@ test("should count multiple occurrences of a character", () => { // And a character `char` that does not exist within `str`. // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of `char` were found. + +test("should return 0 for no occurence", () => { + const str = "asdf"; + const char = "l"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); From 7c85f267acd69d3695238c033282afbfda22e103 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:06:57 +0000 Subject: [PATCH 3/8] Implement countChar function to count occurrences of a character in a string --- Sprint-3/2-practice-tdd/count.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..654cb8f38 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,11 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let sum = 0; + for (let char of stringOfCharacters) { + if (char === findCharacter) { + sum++; + } + } + return sum; } module.exports = countChar; From 3634d6716c6b48d852a5a97eb456852c2f392288 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:31:12 +0000 Subject: [PATCH 4/8] Add tests for getOrdinalNumber to cover cases for 2, 3, and general numbers --- .../2-practice-tdd/get-ordinal-number.test.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index adfa58560..63de8027e 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,31 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +// Case 2: Numbers ending with 2 (but not 12) +// When the number ends with 2, except those ending with 12, +// Then the function should return a string by appending "nd" to the number. +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(122)).toEqual("122nd"); +}); + +// Case 3: Numbers ending with 3 (but not 13) +// When the number ends with 3, except those ending with 13, +// Then the function should return a string by appending "rd" to the number. +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(123)).toEqual("123rd"); +}); + +// Case 4: Numbers ending with any number (but not 1,2 or 3) +// When the number ends with any number, except those ending with 1,2 or 3, +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for numbers ending with any number including 11,12 or 13, except those ending with 1,2 or 3", () => { + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(25)).toEqual("25th"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(4)).toEqual("4th"); +}); From e78fcb2558a32f1df76c4657cfc0a463f1f57790 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:31:24 +0000 Subject: [PATCH 5/8] Refactor getOrdinalNumber function to correctly return ordinal suffixes for numbers --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db1..6c049f336 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,15 @@ function getOrdinalNumber(num) { - return "1st"; + let numberToString = String(num); + let numberLastDigit = numberToString[numberToString.length - 1]; + let numberLast2Digits = numberToString.slice(numberToString.length - 2); + + if (numberLastDigit === "1" && numberLast2Digits !== "11") + return numberToString + "st"; + if (numberLastDigit === "2" && numberLast2Digits !== "12") + return numberToString + "nd"; + if (numberLastDigit === "3" && numberLast2Digits !== "13") + return numberToString + "rd"; + return numberToString + "th"; } module.exports = getOrdinalNumber; From d4b7e3661c2a414e96623e1c731824ad8d14a06f Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:42:27 +0000 Subject: [PATCH 6/8] Add tests for repeatStr function to cover cases for count of 1, 0, and negative numbers --- Sprint-3/2-practice-tdd/repeat-str.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c..c9b11d0cb 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,28 @@ test("should repeat the string count times", () => { // Given a target string `str` and a `count` equal to 1, // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. +test("should repeat string count times", () => { + const str = "bye"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("bye"); +}); // Case: Handle count of 0: // Given a target string `str` and a `count` equal to 0, // When the repeatStr function is called with these inputs, // Then it should return an empty string. +test("should repeat string count times", () => { + const str = "no"; + const count = 0; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual(""); +}); // Case: Handle negative count: // Given a target string `str` and a negative integer `count`, // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid. +test("should throw an error for negative numbers", () => { + expect(() => repeatStr("str", -2)).toThrow("negative counts are not valid"); +}); From 1c394fbea29e808eaff654fea4f33b64335ee8a8 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:42:37 +0000 Subject: [PATCH 7/8] Implement repeatStr function to return repeated string based on count, with error handling for negative counts --- Sprint-3/2-practice-tdd/repeat-str.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..3a45cd582 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,6 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + if (count < 0) throw new Error("negative counts are not valid"); + return str.repeat(count); } module.exports = repeatStr; From f87096956d86a09d9f8d6f914cd956c32276aa5a Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:51:28 +0000 Subject: [PATCH 8/8] Remove unrelated angle type change --- .../implement/1-get-angle-type.js | 74 +++++-------------- 1 file changed, 19 insertions(+), 55 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 2ce43ab79..9e05a871e 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,34 +1,29 @@ // Implement a function getAngleType -// Build up your function case by case, writing tests as you go -// The first test and case is written for you. The next case has a test, but no code. -// Execute this script in your terminal -// node 1-get-angle-type.js -// The assertion error will tell you what the expected output is -// Write the code to pass the test -// Then, write the next test! :) Go through this process until all the cases are implemented +// +// When given an angle in degrees, it should return a string indicating the type of angle: +// - "Acute angle" for angles greater than 0° and less than 90° +// - "Right angle" for exactly 90° +// - "Obtuse angle" for angles greater than 90° and less than 180° +// - "Straight angle" for exactly 180° +// - "Reflex angle" for angles greater than 180° and less than 360° +// - "Invalid angle" for angles outside the valid range. + +// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) + +// Acceptance criteria: +// After you have implemented the function, write tests to cover all the cases, and +// execute the code to ensure all tests pass. function getAngleType(angle) { - if (angle === 90) { - return "Right angle"; - } - if (angle < 90) { - return "Acute angle"; - } - if (angle > 90 && angle < 180) { - return "Obtuse angle"; - } - if (angle === 180) { - return "Straight angle"; - } - return "Reflex angle"; + // TODO: Implement this function } // 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; -// we're going to use this helper function to make our assertions easier to read -// if the actual output matches the target output, the test will pass +// 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, @@ -36,38 +31,7 @@ function assertEquals(actualOutput, targetOutput) { ); } -// Acceptance criteria: - -// Given an angle in degrees, -// When the function getAngleType is called with this angle, -// Then it should: - -// Case 1: Identify Right Angles: -// When the angle is exactly 90 degrees, -// Then the function should return "Right angle" +// TODO: Write tests to cover all cases, including boundary and invalid cases. +// Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); - -// Case 2: Identify Acute Angles: -// When the angle is less than 90 degrees, -// Then the function should return "Acute angle" -const acute = getAngleType(45); -assertEquals(acute, "Acute angle"); - -// Case 3: Identify Obtuse Angles: -// When the angle is greater than 90 degrees and less than 180 degrees, -// Then the function should return "Obtuse angle" -const obtuse = getAngleType(120); -assertEquals(obtuse, "Obtuse angle"); - -// Case 4: Identify Straight Angles: -// When the angle is exactly 180 degrees, -// Then the function should return "Straight angle" -const straight = getAngleType(180); -assertEquals(straight, "Straight angle"); - -// Case 5: Identify Reflex Angles: -// When the angle is greater than 180 degrees and less than 360 degrees, -// Then the function should return "Reflex angle" -const reflex = getAngleType(340); -assertEquals(reflex, "Reflex angle");