-
-
Notifications
You must be signed in to change notification settings - Fork 158
London | Saba Farjamfard |Module-Structuring-and-Testing-data | Sprint 3 | Week 3 #160
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?
London | Saba Farjamfard |Module-Structuring-and-Testing-data | Sprint 3 | Week 3 #160
Conversation
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.
Hi @sabafarjamfard , thanks for this.
Instead of reviewing this file by file, I am just stopping here to say that you are writing console.log instead of writing assertions thoughout.
I think this coursework's underlying goal is to practice writing test first or "TDD" style code, where you make an assertion "I assert x is true/false", write a test for that assertion, then write just enough code to pass the test.
This is the real goal - these exercises are just to explore, practice, and develop this habit. I wouldn't redo the whole thing. My suggestion here is to pick one or two of these exercises and redo them, using this strategy explicitly, so you get the learning value out of this work. Good luck! Let me know how you find it.
Sprint-3/implement/get-angle-type.js
Outdated
if (require.main === module) { | ||
const getAngleType = require('./get-angle-type'); | ||
|
||
console.log(getAngleType(90) === "Right angle" ? "Pass" : "Fail"); |
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.
There aren't any assertions in here. Can you go through a bit what your goal is here?
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.
hello
Thanks for reviewing, I created a test file and I did all
Sprint-3/implement/get-angle-type.js
Outdated
|
||
|
||
//Test code | ||
if (require.main === module) { |
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.
Oh hm, what's going on here?
Sprint-3/implement/get-card-value.js
Outdated
|
||
|
||
|
||
if (require.main === module) { |
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 think we've got in a bit of a muddle here! 😅
It doesn't need to be this complicated. You can just write your assertions (and they should be assertions, not logs) without this check.
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.
Hi,
Thank you for your feedback! As you suggested, I’ve simplified the code and ensured that all assertions are written properly without unnecessary checks
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 left the comments in the code.
Why not prepare a Jest test script for every function you implemented in the revise
folder?
Sprint-3/implement/get-angle-type.js
Outdated
if (require.main === module) { | ||
const getAngleType = require('./get-angle-type'); | ||
|
||
console.log(getAngleType(90) === "Right angle" ? "Pass" : "Fail"); |
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.
Could also test 0, a borderline case.
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.
hello
thanks for reviewing , I create a test file for all
Sprint-3/implement/get-card-value.js
Outdated
const cardRank = card[0]; // The first character represents the rank of the card | ||
|
||
// If the card is a number between 2 and 9 | ||
if (cardRank >= '2' && cardRank <= '9') { |
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.
Part of the description mentions:
// Handle Invalid Cards:
// Given a card with an invalid rank (neither a number nor a recognized face card),
So that implies the rank could possibly be "20" or "B", or "111".
If these ranks are possible, how would you modify your code to treat them as invalid rank? (Just checking the first character would not not be enough)
The description does not say anything about the suite (the last character), so we can presume the last character is always a valid suite character.
Sprint-3/implement/get-card-value.js
Outdated
if (require.main === module) { | ||
try { | ||
console.log(getCardValue("5") === 5 ? "Pass" : "Fail"); // Numeric card 5 | ||
console.log(getCardValue("9") === 9 ? "Pass" : "Fail"); // Numeric card 9 |
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 value passed to the function should always have a suite character as the last character. For examples, "A♠", "10♠". You can copy the character in the description (or just substitute the suite character by another character since the function is not required to validate the suite character).
Using a boundary value such as "2♠" as a test case is always a good idea. Many program fails because they do not check the boundary cases properly.
} | ||
|
||
// Check if numerator and denominator are equal (not a proper fraction) | ||
if (Math.abs(numerator) === Math.abs(denominator)) { |
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 check is optional because Math.abs(numerator) < Math.abs(denominator)
is false
when both values are equal.
} | ||
|
||
// Check the Triangle Inequality conditions | ||
if (a + b > c && a + c > b && b + c > a) { |
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.
Since after line 45, the return value is determined only by the value of (a + b > c && a + c > b && b + c > a)
, we can also just write return (a + b > c && a + c > b && b + c > a);
.
} | ||
|
||
// Check if num is divisible by any number between 2 and sqrt(num) | ||
for (let i = 2; i <= Math.sqrt(num); i++) { |
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 can possibly improve the performance of the code in the following manners:
- Check if num is 2, and check only odd numbers >= 3 in the loop
- Avoid calling
Math.sqrt(num)
repeatedly by assigning the value ofMath.sqrt(num)
to a variable once, and then refer to the variable in the condition of the loop.- Note: The condition is checked at the start of every iteration.
} | ||
|
||
// Rule 5: It must have at least one non-alphanumeric symbol (e.g., !, #, $, %, etc.) | ||
if (!/[\W_]/.test(password)) { |
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.
Please note that \W
also matches spaces. It real application, we would probably want to avoid using it.
} | ||
|
||
// Example of usage: | ||
const previousPasswords = ["Password123!", "12345678", "helloWorld!"]; |
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.
Some of the passwords in this array are invalid passwords.
const previousPasswords = ["Password123!", "12345678", "helloWorld!"]; | ||
console.log(isValidPassword("NewPassword1!", previousPasswords)); // Expected: true | ||
console.log(isValidPassword("password123", previousPasswords)); // Expected: false | ||
console.log(isValidPassword("1234", previousPasswords)); // Expected: 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.
These test cases are not comprehensive.
Because the function can return false
as soon as one of the checks in the function fails,
even if isValidPassword("1234", previousPasswords)
returns false, the test cannot indicate exactly why the function returns false. For example, the function actually failed to check for "password too short" but it still returned false because "1234" does not contain any letter.
We should use test values that only test a specific case. For example, to test if the function can correctly check "password has >= 5 characters", we should use a string like "Ab1$" as test value because it should pass all other checks in the function except check for "password >= 5".
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.
Hi,
Thank you for your feedback earlier! I’ve reviewed and updated the code and test cases to ensure that each condition is tested individually. The tests comprehensively cover all the validation rules, including cases like length, uppercase, lowercase, digits, special characters, and previously used passwords.
} | ||
|
||
// Return the repeated string | ||
return str.repeat(count); |
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.
Why not simply use str.repeat(count)
when count >= 0?
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.