Skip to content
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

Open
wants to merge 63 commits into
base: main
Choose a base branch
from

Conversation

EmmanuelSiziba
Copy link

Learners, PR Template

Self checklist

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

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@EmmanuelSiziba EmmanuelSiziba added the Needs Review Participant to add when requesting review label Dec 4, 2024
Copy link

@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 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){
Copy link

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.

Copy link
Author

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 .

Copy link

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.

Copy link
Author

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"
}
}
Copy link

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?

Copy link
Author

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.

Copy link

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) ).

Copy link
Author

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



function getCardValue(cardString) {
const rank = cardString[0];
Copy link

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?

Copy link
Author

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?

Copy link

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.

Copy link
Author

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);
Copy link

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);

Copy link
Author

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'));
Copy link

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.

Copy link
Author

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);
});

Copy link

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.');

Copy link
Author

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';
Copy link

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');
Copy link

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');

@@ -0,0 +1,13 @@
function repeat(str, count){
if (count < 0) {
throw new Error("Count cannot be nagative");
Copy link

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'"

@@ -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
Copy link

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.

Copy link
Author

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.

// 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.
Copy link

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?

Copy link
Author

Choose a reason for hiding this comment

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

okay

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Dec 4, 2024
@EmmanuelSiziba EmmanuelSiziba reopened this Dec 8, 2024
Copy link

@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.

Some files still have bugs or not yet fully implemented.

if(angle < 360){
return "Reflex angle"
}
}
Copy link

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){
Copy link

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.



function getCardValue(cardString) {
const rank = cardString[0];
Copy link

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'));
Copy link

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.');
Copy link

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');
Copy link

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) {
Copy link

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;
}

Copy link

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!';
Copy link

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",
Copy link

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.

@EmmanuelSiziba EmmanuelSiziba added Complete Participant to add when work is complete and review comments have been addressed and removed Reviewed Volunteer to add when completing a review labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Participant to add when work is complete and review comments have been addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants