Skip to content

LONDON_JAN25 | KHALIL ALI | STRUCTURING_AND_TESTING_DATA | SPRINT 3 | WEEK 6 #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

khalil-ali1
Copy link

@khalil-ali1 khalil-ali1 commented Mar 13, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@cjyuan
Copy link

cjyuan commented Mar 24, 2025

Please follow the "Code Review Process" described here and add the appropriate label to your PR. Otherwise the volunteers will not know this PR needs a review.

@khalil-ali1 khalil-ali1 added the Needs Review Participant to add when requesting review label Apr 2, 2025
@cjyuan cjyuan added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Participant to add when requesting review labels Apr 2, 2025
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Most of the code is good.

There are a few bugs, and some of the code can use some improvement.

Comment on lines 4 to 6
if (denominator === 0) return "Error: Denominator cannot be 0";
if (Math.abs(numerator) < denominator) return true;
if (Math.abs(numerator) >= denominator) return false;
Copy link

Choose a reason for hiding this comment

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

We can also design the function to return false when the denominator is zero. Technically, anything divided by zero is not a proper fraction.

Denominator can also be negative. Mathematically speaking, 2/-3 and -2/-3 are proper fractions.

For any value that is not a proper fraction, we can just return false without an if-statement.

Copy link
Author

Choose a reason for hiding this comment

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

you are right,
now it is more concise and readable.

Comment on lines 33 to 35
test("should identify reflex angle (> 180° but < 360°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
});
Copy link

Choose a reason for hiding this comment

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

We can specify multiple expect(...) statements within each test() to cover multiple values that belong to the same case. For example,

test("should identify reflex angle (> 180° but < 360°)", () => {
  expect(getAngleType(300)).toEqual("Reflex angle");
  expect(getAngleType(359.999)).toEqual("Reflex angle");
  expect(getAngleType(180.001)).toEqual("Reflex angle");
});

Copy link
Author

Choose a reason for hiding this comment

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

thank you for your comment.
I added more examples to make a more comprehensive test.

Comment on lines 21 to 23
test('should throw "Invalid card rank" for X♠', () => {
expect(() => getCardValue("X♠")).toThrow("Invalid card rank");
});
Copy link

Choose a reason for hiding this comment

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

Does your function return the value you expected from each of the following function calls?

getCardValue("010♠");
getCardValue("02♠");
getCardValue("0x02♠");
getCardValue("2.1♠")

Copy link
Author

Choose a reason for hiding this comment

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

I fixed the bug.
now it returns like expected.

@@ -22,3 +22,9 @@ test("should count multiple occurrences of a character", () => {
// 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 count multiple occurrences of a character", () => {
Copy link

Choose a reason for hiding this comment

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

This description does not seem to match the test specified.

Copy link
Author

Choose a reason for hiding this comment

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

I fixed the description

@@ -1,5 +1,18 @@
function getOrdinalNumber(num) {
return "1st";
}
if (num === 11 || num === 12 || num === 13) {
Copy link

Choose a reason for hiding this comment

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

The ordinal numbers of 111, 312, 9913 are "111th", "312th", "9913th".

Copy link
Author

Choose a reason for hiding this comment

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

I fixed the bug.
I added more examples to the test function.

@@ -0,0 +1,37 @@
const isValidNumber = (cardNum) => {
const StrCardNum = cardNum.toString();
Copy link

Choose a reason for hiding this comment

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

Common convention is to start a variable name with a lowercase letter. Uppercase camel case is usually applied to Class or Type names.

Copy link
Author

Choose a reason for hiding this comment

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

I changed it.

Comment on lines 16 to 18
if (cardNum % 2 !== 0) {
return false;
}
Copy link

Choose a reason for hiding this comment

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

This approach is not safe. For example, 9999888877776665 % 2 == 0 is true.

Can you replace this check so that it will work on any 16 digit credit card number (regardless if the number is represented as a string or a value of type number)?

Copy link
Author

Choose a reason for hiding this comment

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

to check the last digit whether even or odd

});

test('Should return false if the sum < 16', () => {
expect(isValidNumber(1011111111111111)).toBe(false);
Copy link

Choose a reason for hiding this comment

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

  • Can you try also expect(isValidNumber(1111111111111110)).toBe(false);? It can reveal a bug in your code.

  • Also, 1111111111111110 is a more suitable test value than 1011111111111111 in this test case. Can you figure out why?

Copy link
Author

Choose a reason for hiding this comment

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

I fixed the bug.
I think because 1111111111111110 is even and the sum of all digits is<16.

@@ -0,0 +1,37 @@
const isValidNumber = (cardNum) => {
Copy link

Choose a reason for hiding this comment

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

Because of the limited precision of number type in JavaScript, I would assume cardNum is of type string.

Copy link
Author

Choose a reason for hiding this comment

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

I fixed it.

Comment on lines 26 to 32
test("valid passwords", () => {
expect (isValidPassword("1Aa2345!")).toEqual(true);
})
test("valid passwords", () => {
expect (isValidPassword("1Aa2345")).toEqual(false);
})
Copy link

Choose a reason for hiding this comment

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

We should also include tests to check if the function can return false when the password fails only one of the following conditions:

  • Have at least 5 characters.
  • Have at least one English uppercase letter (A-Z)
  • Have at least one English lowercase letter (a-z)
  • Have at least one number (0-9)
  • Have at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&")
  • Must not be any previous password in the passwords array.

Copy link
Author

Choose a reason for hiding this comment

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

I added 6 testing lines. Each one breaks only one condition.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Apr 2, 2025
@khalil-ali1 khalil-ali1 added the Complete Participant to add when work is complete and review comments have been addressed label Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Participant to add when work is complete and review comments have been addressed Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants