-
-
Notifications
You must be signed in to change notification settings - Fork 219
London | Phone_Naing |Module-structuring-and-testing-data/ sprint 3 #180
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
London | Phone_Naing |Module-structuring-and-testing-data/ sprint 3 #180
Conversation
Sprint-3/implement/rotate-char.js
Outdated
return capitalLetter[capitalLetterIndex]; | ||
} else if (isAlphabetSmall) { | ||
const smallLetterIndex = | ||
(capitalSplit.indexOf(alphabet) + number) % smallLetter.length; |
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.
Correct Indexing for Lowercase Letters. Replace: smallSplit
Because here you are checking Lowercase Letters.
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.
Thanks you are Legend i did change :)
Sprint-3/implement/rotate-char.js
Outdated
const smallSplit = smallLetter.split(""); | ||
const isAlphabetCapital = capitalSplit.includes(alphabet); | ||
const isAlphabetSmall = smallSplit.includes(alphabet); | ||
if (typeof number !== "number") { |
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.
It seems unnecessary based on the acceptance criteria.
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.
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; |
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 code does not check if any of the sides are less than or equal to zero.
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 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);
});
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 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?
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.
@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
.
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.
Thanks, that mean my code for javascript is correct right :)
expect(isValidTriangle(3, 3, 3)).toBe(true); | ||
}); | ||
|
||
test("Invalid Triangle with Negative", () => { |
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 test is correct. However, your code would not pass this test because it doesn't include a check for negative side lengths.
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 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", () => { |
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.
Your code will fail this test because it doesn't check for zero side lengths.
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 just add to >0 to check negative
Sprint-3/implement/get-card-value.js
Outdated
: !isNaN(checkingCard) && checkingCard >= 2 && checkingCard <= 10 | ||
? Number(checkingCard) | ||
: false; | ||
return isEmojiValid && valueOfCard ? valueOfCard : "Invalid card rank"; |
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 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.
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.
Sure I can do with One Parameter Pass 💯 instead of two parameter pass
@@ -0,0 +1,4 @@ | |||
const getCardValue = require("../get-card-value"); |
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 function is not designed to take two separate parameters, so the test is inconsistent with the current implementation.
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.
change it to one parameter
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 added my comment in your code.
? 11 | ||
: ["K", "Q", "J", "10"].includes(rank) | ||
? 10 | ||
: !isNaN(rank) && rank >= 2 && rank <= 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.
Why do you decide to treat "02❤️", "002❤️", and "0x02❤️" the same as "2❤️", but does treat "010❤️" the same as "10❤️"?
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.
yeah i did check and all have got same value :)
} | ||
console.log(isValidTriangle(3, 3, 3)); | ||
|
||
module.exports = isValidTriangle; |
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.
@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"); | ||
}); |
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 test also 9, 10, J, Q, K, A (and maybe some of the wild cases I suggested earlier) to make the test more comprehensive?
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.
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"); |
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 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?
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.
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) => { |
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 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", () => { |
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.
Is 1 a prime number? Is 0 a prime number?
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.
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); | ||
}); |
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.
Can also test composite numbers in the following manner:
expect(isPrimeNumber(7*11)).toBe(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.
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); |
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.
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" |
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.
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")
...
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.
@cjyuan that is good to know ,i should avoid to use ! true
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 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"); | ||
}); | ||
|
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 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?
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 check it for A$.$$$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.
password-validator.test.js
can use some improvement.
isCharContainOneNumber && | ||
isCharContainOneSpecialLetter && | ||
!isPasswordMatchOld | ||
? "Password Valid" |
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 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"); | ||
}); |
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.
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);
});
...
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.