-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
CYF ITP South Africa - Cape Town | Emmanuel Siziba | Module-Structuring-and-Testing-Data | Week 3 #217
base: main
Are you sure you want to change the base?
Conversation
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 left some comments in your code.
If you have any questions, feel free to ask on Slack or respond here.
return "Right angle"; | ||
} | ||
|
||
if(angle < 90){ |
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.
Technically, 0 < acute angle < 90. Since the spec didn't specify, we can assume angle is always a positive number.
You don't have to change your code.
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 so you are saying since an acute angle is any angle that measures form 0 to 90, I should leave my solution as it is .
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 was saying you can leave your solution as it is because the spec didn't say if the function needs to deal with angles that are negatives or angles that are more than or equal to 360.
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 have put in the else statement with the corresponding test case
if(angle < 360){ | ||
return "Reflex angle" | ||
} | ||
} |
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 it were up to you, what do think the function should return when angle is >= 360?
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 will give us an angle number equal to or greater than 360.
Honestly, I was confused here because I just couldn't figure a way to code this statement " angle is greater than 180 degrees and less than 360 degrees"
so I thought I would just focus on the last part that says less than 360 degrees but I see that was only half of the answer please check I fixed my if statement.
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 previous code is correct because the previous if statements have eliminated all the cases where angle
is less than or equal to 180. That is, if angle
is less than or equal to 180, one of the return
statements would have been executed.
What I was asking is that, what if angle
is more than 360? For example, 400. Someone could call your function as console.log( getAngleType(400) )
.
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 have put in the else statement with the corresponding test case
Sprint-3/implement/get-card-value.js
Outdated
|
||
|
||
function getCardValue(cardString) { | ||
const rank = cardString[0]; |
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.
Since the rank can possibly be any value, we cannot assume it contains only one character.
So the function should also expect values like 'AA♠', '1000♠', and '2.1♠' and consider them as invalid card rank.
Can you modify your code to report these as invalid card ranks?
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 have modified it, did I do it the right way?
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.
Now your function have syntax error. Have you tested your code after you modified it?
Your approach is still not correct; if you just check the first character in the rank, you won't be able to distinguish between "2♠'" and "22♠'"
Since there are so many possible invalid ranks, but there are only 13 valid ranks, you should focus on checking if the rank in the is given cardString
is exactly one of these 13 valid ranks. Any other ranks would be 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.
I have fixed it and now it can handle a invalid ranks
|
||
|
||
test('getCardValue returns 10 for J, Q or K', () => { | ||
expect(getCardValue('J, Q, K')).toBe(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.
The spec means
expect(getCardValue('J♠')).toBe(10);
expect(getCardValue('Q♠')).toBe(10);
expect(getCardValue('K♠')).toBe(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.
Thank you for this,i have edited my test case
|
||
|
||
test('getCardValue returns parseInt(rank) for 2 & 9', () => { | ||
expect(getCardValue('2')).toBe(parseInt('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.
Need to always include a suite character (or any character) as the last character in the "card string".
Also, "10" is a valid 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.
is this what you are saying i must do :
test('getCardValue returns parseInt(rank) for 2 to 10', () => {
expect(getCardValue('2♣')).toBe(2);
expect(getCardValue('3♥')).toBe(3);
expect(getCardValue('4♦')).toBe(4);
expect(getCardValue('5♠')).toBe(5);
expect(getCardValue('6♣')).toBe(6);
expect(getCardValue('7♥')).toBe(7);
expect(getCardValue('8♦')).toBe(8);
expect(getCardValue('9♠')).toBe(9);
expect(getCardValue('10♣')).toBe(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.
The function only needs to check the rank value and can assume the last character is a valid suite character.
So that means you can also set up tests like:
expect(getCardValue('2#')).toBe(2);
expect(getCardValue('9#')).toBe(9);
expect(getCardValue('10#')).toBe(10);
expect(getCardValue('Q#')).toBe(10);
expect(getCardValue('K#')).toBe(10);
expect(() => getCardValue('200♠')).toThrow('Invalid card rank.');
expect(() => getCardValue('2.1♠')).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.
I have fixed it
}); | ||
|
||
test('invalidates weak password', () => { | ||
const password = 'weak'; |
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 objective is not to test weak password, but to test if the function can correctly return true when the given password is valid, and return false when the given password is invalid.
For example, can your function return false when the given password is missing only lowercase letters?
}); | ||
|
||
//test('throws an error for negative count', () => { | ||
// expect((repeat) => repeat('hello', -1)).toThrow('Count cannot be 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 line should be
expect(() => repeat('hello', -1)).toThrow('Count cannot be negative');
Sprint-3/revise/implement/repeat.js
Outdated
@@ -0,0 +1,13 @@ | |||
function repeat(str, count){ | |||
if (count < 0) { | |||
throw new Error("Count cannot be nagative"); |
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.
Typo; the string value should be "'Count cannot be negative'"
Sprint-3/revise/investigate/find.js
Outdated
@@ -21,5 +21,11 @@ console.log(find("code your future", "z")); | |||
|
|||
// a) How the index variable updates during the call to find | |||
// b) What is the if statement used to check | |||
|
|||
//The if statement is used to determine or check if the string has the character that we are looking for |
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 (str[index] === char)
does not deal with the whole string but part of the string.
May I suggest you feed the code to ChatGPT and see how else the code can be explained? From time to time we can learn some new terms or more concise way to describe code.
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 noted, I am doing that.
I understand what you saying and I will feed it so I can learn more. So its safe to say it is very important is to learn to describe code in both simple and technical terms concisely.
Sprint-3/revise/investigate/find.js
Outdated
// c) Why is index++ being used? | ||
|
||
// I think it is used to locate the exact location of the character we will be looking for in our string. |
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 is designed to locate the given character in the given string, but the explanation you gave does not quite answer the questoin.
Can you also try asking ChatGPT the same question (after you feed it the code) so see how else one can answer this question?
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
Spelling error
fixing my test cases
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.
Some files still have bugs or not yet fully implemented.
if(angle < 360){ | ||
return "Reflex angle" | ||
} | ||
} |
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 previous code is correct because the previous if statements have eliminated all the cases where angle
is less than or equal to 180. That is, if angle
is less than or equal to 180, one of the return
statements would have been executed.
What I was asking is that, what if angle
is more than 360? For example, 400. Someone could call your function as console.log( getAngleType(400) )
.
return "Right angle"; | ||
} | ||
|
||
if(angle < 90){ |
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 was saying you can leave your solution as it is because the spec didn't say if the function needs to deal with angles that are negatives or angles that are more than or equal to 360.
Sprint-3/implement/get-card-value.js
Outdated
|
||
|
||
function getCardValue(cardString) { | ||
const rank = cardString[0]; |
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.
Now your function have syntax error. Have you tested your code after you modified it?
Your approach is still not correct; if you just check the first character in the rank, you won't be able to distinguish between "2♠'" and "22♠'"
Since there are so many possible invalid ranks, but there are only 13 valid ranks, you should focus on checking if the rank in the is given cardString
is exactly one of these 13 valid ranks. Any other ranks would be invalid.
|
||
|
||
test('getCardValue returns parseInt(rank) for 2 & 9', () => { | ||
expect(getCardValue('2')).toBe(parseInt('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.
The function only needs to check the rank value and can assume the last character is a valid suite character.
So that means you can also set up tests like:
expect(getCardValue('2#')).toBe(2);
expect(getCardValue('9#')).toBe(9);
expect(getCardValue('10#')).toBe(10);
expect(getCardValue('Q#')).toBe(10);
expect(getCardValue('K#')).toBe(10);
expect(() => getCardValue('200♠')).toThrow('Invalid card rank.');
expect(() => getCardValue('2.1♠')).toThrow('Invalid card rank.');
}); | ||
|
||
test('getCardValue throws error for invalid rank', () => { | ||
expect(() => getCardValue('invalid rank')).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.
Well, at least those invalid cases that I suggested.
}); | ||
|
||
test('converts 43 to an ordinal number', () => { | ||
expect(getOrdinalNumber(43)).toBe('43rd'); |
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.
Could group similar test in the following manner:
test("Expect 'st' as suffix when the number is 1", () => {
expect(getOrdinalNumber(1)).toBe('1st');
});
test("Expect 'st' as suffix when last digit is 1 but last two digits are not 11, 12, or 13", () => {
expect(getOrdinalNumber(21)).toBe('21st');
expect(getOrdinalNumber(131)).toBe('131st');
expect(getOrdinalNumber(1001)).toBe('1001st');
});
...
if (num === 2) return true; | ||
|
||
const sqrtNum = Math.sqrt(num); | ||
for (let i = 3; i <= sqrtNum; i += 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.
This is good.
if (!/[!#$%.*&]/.test(password)) { | ||
return 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.
Looks good. How do you plan to check if the password is one of the passwords already in used?
You can assume these "used passwords" are stored in some array.
const checkPassword = require('./password-validator'); | ||
|
||
test('checks if a password is valid', () => { | ||
const 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.
"valid!" is not a valid password according to the specified rules.
"description": "Like learning a musical instrument, programming requires daily practice.", | ||
"main": "index.js", | ||
"dependencies": { | ||
"ansi-escapes": "^4.3.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 do you need all these dependency packages for? "jest" would be enough.
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.