-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
base: main
Are you sure you want to change the base?
Conversation
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. |
There was a problem hiding this 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.
if (denominator === 0) return "Error: Denominator cannot be 0"; | ||
if (Math.abs(numerator) < denominator) return true; | ||
if (Math.abs(numerator) >= denominator) return false; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
test("should identify reflex angle (> 180° but < 360°)", () => { | ||
expect(getAngleType(270)).toEqual("Reflex angle"); | ||
}); |
There was a problem hiding this comment.
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");
});
There was a problem hiding this comment.
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.
test('should throw "Invalid card rank" for X♠', () => { | ||
expect(() => getCardValue("X♠")).toThrow("Invalid card rank"); | ||
}); |
There was a problem hiding this comment.
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♠")
There was a problem hiding this comment.
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", () => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it.
if (cardNum % 2 !== 0) { | ||
return false; | ||
} |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it.
test("valid passwords", () => { | ||
expect (isValidPassword("1Aa2345!")).toEqual(true); | ||
}) | ||
test("valid passwords", () => { | ||
expect (isValidPassword("1Aa2345")).toEqual(false); | ||
}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I added more testing examples.
add more testing examples.
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.