Skip to content

Conversation

Mgphone
Copy link

@Mgphone Mgphone commented Nov 21, 2024

Learners, PR Template

Self checklist
[x] I have committed my files one by one, on purpose, and for a reason
[x] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
[x] I have tested my changes
[x] My changes follow the style guide
[x] My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@Mgphone Mgphone changed the title London | Phone_Naing |Module-structuring-and-testing-data/ sprint 3| Week1 London | Phone_Naing |Module-structuring-and-testing-data/ sprint 3 Nov 21, 2024
@Mgphone Mgphone added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 21, 2024
return capitalLetter[capitalLetterIndex];
} else if (isAlphabetSmall) {
const smallLetterIndex =
(capitalSplit.indexOf(alphabet) + number) % smallLetter.length;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct Indexing for Lowercase Letters. Replace: smallSplit
Because here you are checking Lowercase Letters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you are Legend i did change :)

const smallSplit = smallLetter.split("");
const isAlphabetCapital = capitalSplit.includes(alphabet);
const isAlphabetSmall = smallSplit.includes(alphabet);
if (typeof number !== "number") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems unnecessary based on the acceptance criteria.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that is truth , I added the number check just in case. I can commented out to keep the code simple

}
console.log(isValidTriangle(3, 3, 3));

module.exports = isValidTriangle;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does not check if any of the sides are less than or equal to zero.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please guide me, when i check jest all are correct...
test("Is a valid triangle", () => {
expect(isValidTriangle(3, 3, 3)).toBe(true);
});

test("Invalid Triangle with Negative", () => {
expect(isValidTriangle(1, -2, 1)).toBe(false);
});

test("Invalid checking triangle with zero sides", () => {
expect(isValidTriangle(0, 1, 2)).toBe(false);
});
test("checking invalid", () => {
expect(isValidTriangle(1, 2, 3)).toBe(false);
});

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return a + b > c && b + c > a && a + c > b;
to make it clear you want me to check if any parameter is zero or minus make it return to false?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MonaZaresh
Yesterday, while trying to find some non-positive values that could fail the test a + b > c && b + c > a && a + c > b, I realised that in JS checking if a, b, c are all positives is not needed. This is because JS uses only double precision floating point type to represent numbers, so we don't have to worry about "integer overflow".

In other programming languages that support integer types, if a, b, c are integer types, then we would need to check if a, b, c are all positives in addition to checking a + b > c && b + c > a && a + c > b.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that mean my code for javascript is correct right :)

expect(isValidTriangle(3, 3, 3)).toBe(true);
});

test("Invalid Triangle with Negative", () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is correct. However, your code would not pass this test because it doesn't include a check for negative side lengths.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return a > 0 && b > 0 && c > 0 && a + b > c && b + c > a && a + c > b;
is it good right ? for negative check

expect(isValidTriangle(1, -2, 1)).toBe(false);
});

test("Invalid checking triangle with zero sides", () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code will fail this test because it doesn't check for zero side lengths.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just add to >0 to check negative

: !isNaN(checkingCard) && checkingCard >= 2 && checkingCard <= 10
? Number(checkingCard)
: false;
return isEmojiValid && valueOfCard ? valueOfCard : "Invalid card rank";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the code does not properly handle multi-character ranks (like "10") or validate the full card format (rank + suit), and it only checks the rank and emoji separately, rather than together as a complete card.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I can do with One Parameter Pass 💯 instead of two parameter pass

@@ -0,0 +1,4 @@
const getCardValue = require("../get-card-value");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is not designed to take two separate parameters, so the test is inconsistent with the current implementation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change it to one parameter

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 added my comment in your code.

? 11
: ["K", "Q", "J", "10"].includes(rank)
? 10
: !isNaN(rank) && rank >= 2 && rank <= 9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you decide to treat "02❤️", "002❤️", and "0x02❤️" the same as "2❤️", but does treat "010❤️" the same as "10❤️"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i did check and all have got same value :)

}
console.log(isValidTriangle(3, 3, 3));

module.exports = isValidTriangle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MonaZaresh
Yesterday, while trying to find some non-positive values that could fail the test a + b > c && b + c > a && a + c > b, I realised that in JS checking if a, b, c are all positives is not needed. This is because JS uses only double precision floating point type to represent numbers, so we don't have to worry about "integer overflow".

In other programming languages that support integer types, if a, b, c are integer types, then we would need to check if a, b, c are all positives in addition to checking a + b > c && b + c > a && a + c > b.

});
test("Invalid card rank", () => {
expect(() => getCardValue("l❤️")).toThrow("Invalid card rank");
});
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 test also 9, 10, J, Q, K, A (and maybe some of the wild cases I suggested earlier) to make the test more comprehensive?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks and all working fine :)

@@ -0,0 +1,8 @@
const rotateCharacter = require("../rotate-char");
test("first argument Invalid Alphabet", () => {
expect(rotateCharacter("2", 2)).toBe("2");
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 test if the function can really rotate a letter (uppercase and lowercase), and also rotate correctly when shift is a large number such as 100?

I wonder what would happen if shift is -1. Can the function rotate a letter in the opposite direction?

Copy link
Author

@Mgphone Mgphone Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I did add more to check :) and correct

// 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.
const countChar = (str, char) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you overdone. The function is expected only to return the value of count as a number, and not as a nicely formatted string. (You don't have to make any changes)

}
return true;
};
test("checking negative number", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 1 a prime number? Is 0 a prime number?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow thanks very much.. i am wrong and i fixed it zero and 1 is not prime

});
test("checking not prime number", () => {
expect(isPrimeNumber(4)).toBe(false);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also test composite numbers in the following manner:
expect(isPrimeNumber(7*11)).toBe(false);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay i just knew i can check like this as well :)

// return newPassword;
//this is for upperCase Regex
const upperCaseRegex = /[A-Z]/g;
const isCharContainOneCapital = !!newPassword.match(upperCaseRegex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also use the .test() method of a regular expression to check if part of a string matches the regular expression in the following manner:

! /[A-Z]/.test(newPassword)

isCharContainOneNumber &&
isCharContainOneSpecialLetter &&
!isPasswordMatchOld
? "Password Valid"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the function returns a Boolean value true or false, then the function could be used in the following manner:

if (checkPasswordValidation("aA123$"))
    ...

instead of

if (checkPasswordValidation("aA123$") == "Password Valid")
  ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjyuan that is good to know ,i should avoid to use ! true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to say, it is ok to keep const isPasswordMatchOld = previousPassword.includes(newPassword);

but return true/false from your function, as in

return isCharAtLeaseFive && ... && !isPasswordMatchOld ? true : false;

or even

return isCharAtLeaseFive && ... && !isPasswordMatchOld;

test("Checking Invalid", () => {
expect(checkPasswordValidation("abcd")).toBe("Password Invalid");
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more invalid cases to test. Otherwise how can we be sure the implemented function can correctly identify "aA12314" and "A$.$$$A" are an invalid password?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i check it for A$.$$$A :)

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Dec 1, 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.

password-validator.test.js can use some improvement.

isCharContainOneNumber &&
isCharContainOneSpecialLetter &&
!isPasswordMatchOld
? "Password Valid"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to say, it is ok to keep const isPasswordMatchOld = previousPassword.includes(newPassword);

but return true/false from your function, as in

return isCharAtLeaseFive && ... && !isPasswordMatchOld ? true : false;

or even

return isCharAtLeaseFive && ... && !isPasswordMatchOld;

Comment on lines +67 to +69
test("Checking Invalid", () => {
expect(checkPasswordValidation("abcd")).toBe("Password Invalid");
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming you have changed your function to return true/false.

expect(checkPasswordValidation("abcd")).toBe(false);
When this test fails (that is, checkPasswordValidation("abcd") returns true), we cannot be certain exactly why the function returns true; it could be one or more of the following reasons:

  • The function fails to check if the password is long enough.
  • The function fails to check if the password contains a digit.
  • The function fails to check if the password contains an non-alphanumeric character.
  • The function fails to check if the password contains an uppercase letter.

A better test setup would be

test("Expect false when password does not contain any uppercase letter", () => {
  // "ab$1xyz" meets all requirements except that is does not contain
  // an uppercase letter.
  expect(checkPasswordValidation("ab$1xyz")).toBe(false); 
});

test("Expect false when password length is less than 5", () => {
   // "aB$1" has all the required characters but too short
  expect(checkPasswordValidation("aB$1")).toBe(false);   
});
...

@Mgphone Mgphone added the Complete Volunteer to add when work is complete and all review comments have been addressed. label Dec 16, 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 all review comments have been addressed. Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants