-
-
Notifications
You must be signed in to change notification settings - Fork 196
London | May-2025 | Reza Jahanimir | Sprint-3 #576
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?
Changes from 4 commits
41faaac
fb392b3
52148a6
4d0497e
13220cd
396094b
ccf0768
686efb6
435f1dd
cb18deb
c13ebd3
37f8608
af01c38
2b3e360
8dd332e
e80b220
d32bc0c
ce330dd
c969da7
95c85ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ test("password has a unknown character", () => { | |
}) | ||
|
||
|
||
test("password has at least 5 characters", () => { | ||
test("password has more than 5 characters", () => { | ||
expect(isValidPassword("1£b4A")).toBe(false);// Fails because no letters or special chars | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This password have 5 characters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this test suppose to check? |
||
expect(isValidPassword("1@Qe")).toBe(false); // Fails because the password is less than 5 characters. | ||
}); | ||
|
@@ -64,6 +64,24 @@ test("password should not be a previously used password", () => { | |
expect(isValidPassword("Valid1!")).toBe(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we be testing if the function can return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ve reviewed why the test cases for reused passwords are failing, and it comes down to the design constraint of using bannedPassword = [] as a function parameter. Since the bannedPassword list is defined as a default parameter, each time the passwordValidator function is called without explicitly passing a shared array, it creates a new empty array. This means previously used passwords aren't remembered across calls — the validator is stateless unless we manage state externally. So in the current setup, calling passwordValidator("Valid1!") twice without passing the same bannedPassword array will always return true, because the function forgets the first password after each call. I understand the reasoning behind wanting to pass the banned list explicitly, but just wanted to clarify that the current test fails because the function isn’t tracking state unless we provide it manually. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. The purpose of using the 2nd parameter to accept an optional array of previous passwords is that the caller can supply the previous passwords to the function if needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to check in because I'm feeling a bit confused about the current direction. I'm unsure whether I should revert the function back to its original form (with internal state) or keep the current version that requires the bannedPassword array to be passed in externally. I’m also struggling to understand the core learning objective here — whether the focus is on function design, managing state, writing effective tests, or something else. I want to make sure I’m approaching this the right way and not just changing things without understanding the purpose behind them. Could you please clarify what I should be aiming to learn from this task, and how you'd like me to proceed with the code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spec says the function should return false when the password is one of the previous passwords. Your original method for handling previous passwords works (because the spec does not specify how they are supposed to be represented). I suggested a more flexible approach and you adopted it. However, doing so broke your test. So if you want to keep your current implementation (the one with 2nd parameter) , you have to fix the test. If not, you can revert the test and the implementation. |
||
}); | ||
|
||
// Shouldn't we be testing if the function can return false when a password is one of the previous passwords? | ||
test("should not accept a previously used password", () => { | ||
const banned = ["Valid1!"]; | ||
expect(isValidPassword("Valid1!", banned)).toBe(false); // Should return false | ||
}); | ||
|
||
// we care tring manually to add a password that has been used before | ||
test("valid password", () => { | ||
const banned = []; | ||
expect(isValidPassword("Valid1!", banned)).toBe(true); // first time, valid | ||
}); | ||
|
||
test("password should not be a previously used password", () => { | ||
const banned = []; | ||
isValidPassword("Valid1!", banned); // use it once | ||
expect(isValidPassword("Valid1!", banned)).toBe(false); // second use, now rejected | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could explicitly include |
||
|
||
|
||
|
||
// test("valid 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.
Almost. Any substring of "23456789" can satisfy the condition.
Uh oh!
There was an error while loading. Please reload this page.
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.
return the rank as a number if it's between 2 and 9
return Number(rank);
"23456789": This is a string made of all the single-digit card ranks from 2 to 9.
.includes(rank): Checks if the rank exists inside that string.
For example:
"23456789".includes("5") // → true
"23456789".includes("10") // → false
return Number(rank);
This converts the string "5" into the number 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.
"23456789".includes("45") // => true
"23456789".includes("12345") // => true