Skip to content

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

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

Conversation

sabafarjamfard
Copy link

@sabafarjamfard sabafarjamfard commented Nov 18, 2024

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.

@sabafarjamfard sabafarjamfard added the Needs Review Participant to add when requesting review label Nov 18, 2024
@sabafarjamfard sabafarjamfard added Needs Review Participant to add when requesting review and removed Needs Review Participant to add when requesting review labels Nov 27, 2024
Copy link
Member

@SallyMcGrath SallyMcGrath left a 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.

if (require.main === module) {
const getAngleType = require('./get-angle-type');

console.log(getAngleType(90) === "Right angle" ? "Pass" : "Fail");
Copy link
Member

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?

Copy link
Author

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



//Test code
if (require.main === module) {
Copy link
Member

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?




if (require.main === module) {
Copy link
Member

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.

Copy link
Author

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

@SallyMcGrath SallyMcGrath added 👀 Review Testing Changes requested to do with testing Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Nov 30, 2024
Copy link
Contributor

@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.

I left the comments in the code.

Why not prepare a Jest test script for every function you implemented in the revise folder?

if (require.main === module) {
const getAngleType = require('./get-angle-type');

console.log(getAngleType(90) === "Right angle" ? "Pass" : "Fail");
Copy link
Contributor

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.

Copy link
Author

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

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') {
Copy link
Contributor

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.

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
Copy link
Contributor

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)) {
Copy link
Contributor

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) {
Copy link
Contributor

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++) {
Copy link
Contributor

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 of Math.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)) {
Copy link
Contributor

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!"];
Copy link
Contributor

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
Copy link
Contributor

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".

Copy link
Author

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);
Copy link
Contributor

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?

@sabafarjamfard sabafarjamfard added Needs Review Participant to add when requesting review and removed Needs Review Participant to add when requesting review labels Dec 2, 2024
@sabafarjamfard sabafarjamfard added the Complete Volunteer to add when work is complete and review comments have been addressed label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Volunteer to add when work is complete and review comments have been addressed 👀 Review Testing Changes requested to do with testing Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants