Repository navigation
Manchester | 26-ITP-Sep | Salah Alsabhi | Sprint 3 | Stretch coursework - #1751
salahalsabhi wants to merge 5 commits into
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Functions are correctly implemented. Good job.
| test("rejects non-digit characters", () => { | ||
| expect(isValidCardNumber("a92332119c011112")).toEqual(false); | ||
| }); | ||
|
|
||
| test("rejects all same digits", () => { | ||
| expect(isValidCardNumber("4444444444444444")).toEqual(false); | ||
| }); | ||
|
|
||
| test("rejects sum of 16 or less", () => { | ||
| expect(isValidCardNumber("1111111111111110")).toEqual(false); | ||
| }); | ||
|
|
||
| test("rejects odd final digit", () => { | ||
| expect(isValidCardNumber("6666666666666661")).toEqual(false); | ||
| }); |
There was a problem hiding this comment.
-
Could also test card numbers that do not have exactly 16 digits.
-
Some of the test descriptions are not yet properly phrased. Could you rephrase them? A common pattern you could try is "should ____________ when _________________".
| const previousPasswords = ["password", "12345", "qwerty"]; | ||
|
|
||
| export function isValidPassword(password) { |
There was a problem hiding this comment.
For higher flexibility, we could design the function to accept previousPasswords as an optional second parameter (with a default value).
| expect(isValidPassword("ABC1!")).toEqual(false); | ||
| }); | ||
|
|
||
| test("rejects password without number", () => { |
There was a problem hiding this comment.
Note: The term digit refers to a number in the range 0-9. A number may contain one or more digits.
|
Thanks for the feedback. I’ve updated the test names, added length checks for card numbers, and made previousPasswords an optional second parameter with a default. |
cjyuan
left a comment
There was a problem hiding this comment.
To test a function that could return false for multiple reasons, we should choose an input (argument) that satisfies all conditions except the one we're targeting.
This way, if the function returns false, we can confidently attribute the result to that specific condition.
To illustrate, consider this example:
test("returns false when the password has fewer than 5 characters", () => {
expect(isValidPassword("1234")).toBe(false);
});The test case "1234" is a poor choice because it violates multiple conditions, not just the minimum length requirement.
Even if the function incorrectly checks the password length, this test could still pass because the function returns false for one of the other reasons.
A better test case would be "Ab1!" because it satisfies all conditions except the minimum length requirement.
Could you review each test case to ensure it isolates the specific condition being tested? Make sure the input satisfies all the other conditions and violates only the target condition, so that if the test passes, you can be confident that the specific condition is being checked correctly.
| const defaultPreviousPasswords = ["password", "12345", "qwerty"]; | ||
|
|
||
| export function isValidPassword( | ||
| password, | ||
| previousPasswords = defaultPreviousPasswords | ||
| ) { |
There was a problem hiding this comment.
Why set these as default previous passwords? If the function is used in an application, how would these default passwords affect the application? If they are for testing purpose, why not declare them in the test script.
|
Updated tests so each invalid case only breaks one rule, and moved previous passwords out of the function default into the tests (default is now []). |
cjyuan
left a comment
There was a problem hiding this comment.
Some of the test cases in card-validator.test.js also violate more than one conditions. Could you fix them?
| test("should reject a previous password", () => { | ||
| expect(isValidPassword("password", previousPasswords)).toEqual(false); | ||
| }); |
There was a problem hiding this comment.
-
The function could also return
falsebecause"password"violates several other conditions. -
And this test is very similar to the next test (lines 50-52). You could consider grouping both tests into one category.
|
Isolated each card invalid case to a single rule, and reduced previous-password coverage to one test that only fails via the previousPasswords list. |
| const previousPasswords = ["password", "12345", "qwerty"]; | ||
|
|
There was a problem hiding this comment.
Larger array of previous passwords was a good for testing. It was just that all the previous passwords you chose were invalid.
Learners, PR Template
Self checklist
Task code
CYF-1065
Changelist
Questions
No questions.