Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b5de08b
build up getAngleType case by case
Alaa-Tagi Oct 9, 2025
b5fa562
Editing is-proper-fraction code
Alaa-Tagi Oct 9, 2025
3898643
Editing getcardvalue code
Alaa-Tagi Oct 12, 2025
78d374a
rewrite test with jest for getangletype code
Alaa-Tagi Oct 12, 2025
d07dd99
update isproperfraction code
Alaa-Tagi Oct 12, 2025
a223e45
Rewrite test with jest for isproperfraction code
Alaa-Tagi Oct 12, 2025
ef42f92
rewrite test with jest for getcardvalue code
Alaa-Tagi Oct 12, 2025
b02a77f
Editing count code
Alaa-Tagi Oct 12, 2025
3f11ed4
Editing count.js code
Alaa-Tagi Oct 12, 2025
d7507ff
Rewrite tests with jest for count code
Alaa-Tagi Oct 12, 2025
2eaa92c
Editing getordinalnumber code
Alaa-Tagi Oct 12, 2025
73c8fcf
Rewrite tests with jest for getordinalnumber code
Alaa-Tagi Oct 12, 2025
52660c9
Editing repeat code
Alaa-Tagi Oct 12, 2025
408f2e1
Rewrite test with jest for repeat code
Alaa-Tagi Oct 12, 2025
1f0b098
1-get-angle-type.js
Alaa-Tagi Oct 12, 2025
d276533
2-is-proper-fraction.js
Alaa-Tagi Oct 12, 2025
ce08a1f
3-get-card-value.js
Alaa-Tagi Oct 12, 2025
874c5ca
1-get-angle-type.test.js
Alaa-Tagi Oct 12, 2025
ea944a1
3-get-card-value.test.js
Alaa-Tagi Oct 12, 2025
d25945b
2-is-proper-fraction.test.js
Alaa-Tagi Oct 12, 2025
5e24460
Removes all console logs from PR
Alaa-Tagi Oct 24, 2025
d269acc
Editing the code and jest code
Alaa-Tagi Oct 24, 2025
62bf3a9
Editing jest code
Alaa-Tagi Oct 24, 2025
6f9d56b
update the code
Alaa-Tagi Oct 24, 2025
b1c0345
Write additional tests
Alaa-Tagi Oct 24, 2025
8ff02d3
Correct the code
Alaa-Tagi Oct 24, 2025
2aafdb6
Add another tests
Alaa-Tagi Oct 24, 2025
c491953
Remove all console logs
Alaa-Tagi Oct 26, 2025
0f0c704
editing the code
Alaa-Tagi Oct 26, 2025
9e74422
fixing the code to run the jest test
Alaa-Tagi Oct 26, 2025
099a76f
Deleting line to fix the code
Alaa-Tagi Oct 26, 2025
2db8252
editing the code
Alaa-Tagi Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ const obtuse = getAngleType(120);
// 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"
// ====> write your test here, and then add a line to pass the test in the function above
// ====> write your test here, and then add a line to pass the test in the function above
14 changes: 13 additions & 1 deletion Sprint-3/2-practice-tdd/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
if (
typeof stringOfCharacters !== "string" ||
typeof findCharacter !== "string" ||
findCharacter.length !== 1
) {
return 0;
}

if (stringOfCharacters.length === 0) {
return 0;
}

return stringOfCharacters.split(findCharacter).length - 1;
}

module.exports = countChar;
84 changes: 83 additions & 1 deletion Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
const countChar = require("./count");
// Given a string str and a single character char to search for,
// When the countChar function is called with these inputs,
// Then it should:
// Then it should: correctly count the occurrences of char in str.


// Scenario: Multiple Occurrences
// Given the input string str,
Expand All @@ -17,8 +18,89 @@ test("should count multiple occurrences of a character", () => {
expect(count).toEqual(5);
});


// Scenario: No Occurrences
// Given the input string str,
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.

test("should return 0 for no occurrences", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is good but it doesn't test different possible function inputs. What if the inputs' types are not strings, the char string is longer than the str string, or you have an empty string for either of the inputs, etc.? Testing different inputs will show whether your function accounts for different scenarios, which is what makes a function robust.

const str = "hello";
const char = "z";
const count = countChar(str, char);
expect(count).toEqual(0);
});


// Scenario: Multiple occurrences
test("should count multiple occurrences of a character", () => {
const str = "aaaaa";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(5);
});

// Scenario: No occurrences
test("should return 0 for no occurrences", () => {
const str = "hello";
const char = "z";
const count = countChar(str, char);
expect(count).toEqual(0);
});

// Scenario: Empty string
test("should return 0 when input string is empty", () => {
const str = "";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(0);
});

// Scenario: Empty character
test("should return 0 when character input is empty", () => {
const str = "hello";
const char = "";
const count = countChar(str, char);
expect(count).toEqual(0);
});

// Scenario: Character longer than 1
test("should return 0 when character input is longer than one character", () => {
const str = "hello";
const char = "ll";
const count = countChar(str, char);
expect(count).toEqual(0);
});

// Scenario: char string longer than str string
test("should return 0 when char is longer than the input string", () => {
const str = "a";
const char = "abc";
const count = countChar(str, char);
expect(count).toEqual(0);
});

// Scenario: Non-string inputs
test("should return 0 when inputs are not strings", () => {
expect(countChar(12345, "1")).toEqual(0);
expect(countChar("12345", 1)).toEqual(0);
expect(countChar(null, "a")).toEqual(0);
expect(countChar("hello", undefined)).toEqual(0);
});
Comment on lines +76 to +90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine but when you read this function's purpose, you might think that if char is longer than str, it should perhaps throw an error as there is no way to count char occurrence in this case. It's fine to leave Scenario: char string longer than str string test case as is but it's something to consider while designing your function.

Same for Scenario: Non-string inputs but this test case should definitely throw errors.


// Scenario: Case sensitivity
test("should count only exact case matches", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very thoughtful test case!

const str = "AaAaA";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(2);
});

// Scenario: Spaces and special characters
test("should correctly count spaces and symbols", () => {
const str = "a b c d e ! !";
const char = " ";
const count = countChar(str, char);
expect(count).toEqual(6);
});
33 changes: 31 additions & 2 deletions Sprint-3/2-practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
function getOrdinalNumber(num) {
return "1st";
if (typeof num !== "number" || isNaN(num)) {
return "Invalid input";
}
const sign = num < 0 ? "-" : "";
num = Math.abs(num);

// Handle decimals
if (!Number.isInteger(num)) {
return sign + num + "th";
}

const lastTwo = num % 100;
const lastOne = num % 10;

// Handle special cases 11th, 12th, 13th
if (lastTwo >= 11 && lastTwo <= 13) {
return sign + num + "th";
}

// Normal ordinal rules
switch (lastOne) {
case 1:
return sign + num + "st";
case 2:
return sign + num + "nd";
case 3:
return sign + num + "rd";
default:
return sign + num + "th";
}
}

module.exports = getOrdinalNumber;
module.exports = getOrdinalNumber;
84 changes: 84 additions & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,87 @@ const getOrdinalNumber = require("./get-ordinal-number");
test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like these test cases but again, what are other expected/unexpected inputs your function can receive and how will it behave? For example, what if num is undefined, a boolean, etc.? That's just two examples of num being not of a type you expect.

/// Case 2: Identify the ordinal number for 2
// When the number is 2,
// Then the function should return "2nd"
test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});

// Case 3: Identify the ordinal number for 3
// When the number is 3,
// Then the function should return "3rd"
test("should return '3rd' for 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
});

// Case 4: Identify the ordinal number for 4
// When the number is 4,
// Then the function should return "4th"
test("should return '4th' for 4", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
});

// Case 5: Identify the ordinal number for 11
// When the number is 11,
// Then the function should return "11th"
test("should return '11th' for 11", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
});

// Case 6: Identify the ordinal number for 22
// When the number is 22,
// Then the function should return "22nd"
test("should return '22nd' for 22", () => {
expect(getOrdinalNumber(22)).toEqual("22nd");
});

// Case 7: Identify the ordinal number for 33
// When the number is 33,
// Then the function should return "33rd"
test("should return '33rd' for 33", () => {
expect(getOrdinalNumber(33)).toEqual("33rd");
});

// Case 8: Undefined input
// When the input is undefined,
// Then the function should return "Invalid input"
test("should handle undefined input gracefully", () => {
expect(getOrdinalNumber(undefined)).toEqual("Invalid input");
});

// Case 9: Null input
// When the input is null,
// Then the function should return "Invalid input"
test("should handle null input gracefully", () => {
expect(getOrdinalNumber(null)).toEqual("Invalid input");
});

// Case 10: Boolean input
// When the input is a boolean value,
// Then the function should return "Invalid input"
test("should handle boolean input gracefully", () => {
expect(getOrdinalNumber(true)).toEqual("Invalid input");
});

// Case 11: Non-numeric string input
// When the input is a non-numeric string,
// Then the function should return "Invalid input"
test("should handle non-numeric string input gracefully", () => {
expect(getOrdinalNumber("hello")).toEqual("Invalid input");
});

// Case 12: Negative number
// When the input is a negative number,
// Then the function should return the ordinal form with a negative sign
test("should return '-1st' for -1", () => {
expect(getOrdinalNumber(-1)).toEqual("-1st");
});

// Case 13: Floating number
// When the input is a floating number,
// Then the function should return the ordinal with decimal intact
test("should handle decimal numbers", () => {
expect(getOrdinalNumber(21.5)).toEqual("21.5th");
});
19 changes: 17 additions & 2 deletions Sprint-3/2-practice-tdd/repeat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
function repeat() {
return "hellohellohello";
function repeat(str, count) {
if (str === undefined || count === undefined){
throw new Error ("argument must be defined")
}
if (count < 0) {
throw new Error("Count must be a non-negative integer");
}

let result = "";
for (let i = 0; i < count; i++) {
result += str;
}

return result;
}

module.exports = repeat;



84 changes: 71 additions & 13 deletions Sprint-3/2-practice-tdd/repeat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const repeat = require("./repeat");
// Given a target string str and a positive integer count,
// When the repeat function is called with these inputs,
// Then it should:
// Then it should: repeat the str count times and return a new string containing the repeated str values.

// case: repeat String:
// Given a target string str and a positive integer count,
Expand All @@ -11,22 +11,80 @@ const repeat = require("./repeat");

test("should repeat the string count times", () => {
const str = "hello";
const count = 3;
const count = 4;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hellohellohello");
expect(repeatedStr).toEqual("hellohellohellohello");
});

// case: handle Count of 1:

// case: Handle Count of 1 :
// Given a target string str and a count equal to 1,
// When the repeat function is called with these inputs,
// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
// Then it should return the original str without repetition.
test("should return the original string when count is 1", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test suit are more comprehensive but can you think of other test cases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jennethydyrova i have fixed all the errors that you have mentioned to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried running the tests you wrote?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you try to run your unit tests, you will see that some of them are failing both for this function and getOrdinalNumber. Can you try to fix tests/functions by reading output produced when you run tests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have and it passed all the tests.

Copy link
Contributor

@jennethydyrova jennethydyrova Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit tests in your screenshots do not match those in the PR. Take a look at Sprint-3/2-practice-tdd/get-ordinal-number.test.js file, for example. Your last test in this PR is

test("should handle decimal numbers", () => {
  expect(getOrdinalNumber(21.5)).toEqual("21.5th");
});

and on the screenshot you sent the last test is

test("should return '33rd' for 33", () => {
  expect(getOrdinalNumber(33)).toEqual("33rd");
});

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jennethydyrova,
I have edited this code if you could check down

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always double check if you pushed your local changes, deleted all scratch work (including console logs) and ran all unit tests before requesting another round of review. It will reduce time I spend on reviewing your code and you going back to the same PR over and over again. File changes tab is quite useful for checking if you code is up to standard.

I don't see any new changes. I assume you made some local changes but you haven't pushed them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jennethydyrova, I am sorry and I appreciate your time. But I am so confused too I make the changes, do push as usual and in here every thing appears.

Alaa pic

Like this pic here it shows that the changes has been push and I do not see any unstage files.

Thanks for you patient with me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Okay, I can see these changes and I can see from the function implementation, that this particular unit test on the screenshot you sent will fail but you can understand this by just running unit tests. You have these changes locally, right? If you have same changes locally and you run unit tests, some of them will fail in Sprint-3/2-practice-tdd folder indicating that some more work needs to be done.

const str = "hello";
const count = 1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hello");
});

// case: Handle Count of 0:
// Given a target string str and a count equal to 0,
// When the repeat function is called with these inputs,
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
// case: Handle Count of 0 :
// When count is 0, it should return an empty string.
test("should return an empty string when count is 0", () => {
const str = "hello";
const count = 0;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("");
});

// case: Negative Count:
// Given a target string str and a negative integer count,
// When the repeat function is called with these inputs,
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
// case: Negative Count :
// When count is negative, it should throw an error.
test("should throw an error when count is negative", () => {
const str = "hello";
const count = -2;
expect(() => repeat(str, count)).toThrow("Count must be a non-negative integer");
});


// case: Non-string input for str :
// When str is not a string (e.g., number), it should still repeat it as a string.
test("should convert non-string input to string before repeating", () => {
const str = 123;
const count = 2;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("123123");
});

// case: Non-integer count :
// When count is a non-integer (e.g., 2.5), it should repeat only the integer part.
test("should handle non-integer count by truncating it", () => {
const str = "hi";
const count = 2.5;
const repeatedStr = repeat(str, Math.floor(count));
expect(repeatedStr).toEqual("hihi");
});

// case: Empty string input :
// When str is empty, the result should always be empty, regardless of count.
test("should return an empty string when str is empty", () => {
const str = "";
const count = 5;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("");
});

// case: Undefined or missing arguments :
// When arguments are missing or undefined, it should throw an error.
test("should handle undefined inputs gracefully", () => {
expect(() => repeat(undefined, 3)).toThrow("argument must be defined");

});

// case: Boolean inputs :
// When str or count are booleans, it should convert str to string and handle count normally.
test("should handle boolean values as inputs", () => {
const str = true;
const count = 2;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("truetrue");
});