Skip to content

Conversation

@M-Abdoon
Copy link

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

I implemented and rewrote tests, figured the errors and tested the code. modified the files to meet the test requirements.

Questions

No questions for now, thank you.

@M-Abdoon M-Abdoon added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 10, 2025
@cjyuan cjyuan added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 17, 2025
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.

  • The files in 2-practice-tdd subfolder are not related to this exercise. Can you revert the changes made in that folder to keep this branch clean?

  • Can you rename this branch to the name specified in the backlog?

Comment on lines 11 to 18
if(typeof(numerator) != "number" || typeof(denominator) != "number") {
return "[ wrong input ]";
}
if (numerator < denominator ) {
return true;
}
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In mathematics, -A/B == A/-B == -(A/B), and -A/-B == A/B for any integers A and B (B ≠ 0).
They represent a proper fraction if A < B and B ≠ 0.

So isProperFraction(-4, 3) should return false because 4 >= 3.

So isProperFraction(-2, 5) should return true because 2 < 5.

Consider comparing the absolute value of the numerator and the denominator instead.

In addition, to indicate errors, it is best practices to throw an error (instead of returning an error message).
If you have time, you should check out how to throw an error in JS.

Alternatively, you can choose to return false to indicate something is not a fraction.

Copy link
Author

Choose a reason for hiding this comment

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

I made the required changes, I used the method Math.abs() to fix the bug and used error throwing when inputs are not valid. also the function should return 0 when denominator is 0;

Comment on lines 18 to 20
if ((rank => 2) && (rank <= 10)) {
return Number(rank);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In JavaScript, strings that represent valid numeric literals in the language can be safely converted to equivalent numbers. For examples, "0x02", "2.1", or "0002".

Does your function return the value you expected from each of the following function calls?

getCardValue("0x02♠");
getCardValue("2.1♠");
getCardValue("0002♠");

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 pointing that out. Yes, the function returns what is expected, but I used Math.floor() to exclude decimal numbers.

Comment on lines 24 to 26
test("should identify Reflex angle (greater than 180° and less than 360°)", () => {
expect(getAngleType(181)).toEqual("Reflex angle");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

We could specify multiple expect(...) statements within each test() to cover multiple values that belong to the same case. For example,

test("should identify reflex angle (180 < angle < 360)", () => {
  expect(getAngleType(300)).toEqual("Reflex angle");
  expect(getAngleType(359.999)).toEqual("Reflex angle");
  expect(getAngleType(180.001)).toEqual("Reflex angle");
});

Comment on lines 15 to 17
test("should return true for a negative Fractions", () => {
expect(isProperFraction(-6, 4)).toEqual(true);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

-6/4 is not a proper fraction.

You can test several "negative fractions in one test". For examples,

test("should return true for a negative Fractions", () => {
    expect(isProperFraction(-6, 4)).toEqual(false);
    expect(isProperFraction(-4, 6)).toEqual(true);
    expect(isProperFraction(6, -4)).toEqual(false);
    expect(isProperFraction(4, -6)).toEqual(true);   
    expect(isProperFraction(-6, -4)).toEqual(false);
    expect(isProperFraction(-4, -6)).toEqual(true);    
});

Copy link
Author

Choose a reason for hiding this comment

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

Done. I added more test cases to each category.

Comment on lines 11 to 15
test("should return the number entered as input", () => {
const numberCards = getCardValue("4♠");
expect(numberCards).toEqual(4);
});

Copy link
Contributor

Choose a reason for hiding this comment

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

When preparing tests, we should ensure the tests cover all possible cases. If we specify a test for individual card, we will need about 53 tests to cover all possible cases. Instead, we could consider classifying all possible values into different categories, and then within each category we test some samples.

For example, one possible category for getCardValue() is, "should return the value of number cards (2-10)", and we can prepare the test as

test("should return the value of number cards (2-10)", () => {
    expect(getCardValue("2♣︎")).toEqual(2);
    expect(getCardValue("5♠")).toEqual(5);
    expect(getCardValue("10♥")).toEqual(10);
    // Note: We could also use a loop to check all values from 2 to 10.
});

Copy link
Author

Choose a reason for hiding this comment

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

Ok. I changed the code and added more test cases + added different statements using for loop to test numbers from 2 to 10

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 17, 2025
@M-Abdoon M-Abdoon closed this Oct 17, 2025
@M-Abdoon M-Abdoon deleted the Sprint-3/1_implement_and_rewrite_tests branch October 17, 2025 21:32
@M-Abdoon M-Abdoon restored the Sprint-3/1_implement_and_rewrite_tests branch October 17, 2025 21:33
@M-Abdoon M-Abdoon reopened this Oct 17, 2025
@M-Abdoon
Copy link
Author

  • The files in 2-practice-tdd subfolder are not related to this exercise. Can you revert the changes made in that folder to keep this branch clean?
  • Can you rename this branch to the name specified in the backlog?

Ok, I will delete the unnecessery folder, thank you.
yes I can change the branch name, but if I do that, the pull request will be closed and I will have to make another pull request from the new branch, should I do that?
in the next pull request I`ll make sure that the branch is named as requested in the backlog.

@cjyuan
Copy link
Contributor

cjyuan commented Oct 19, 2025

We can rename the remote branch directly on GitHub and keep the PR stay opened.
However, we would also need to update our local branch to track the new remote name. (You will have to run some Git command on CLI). (Ask AI how to accomplish this).

Go ahead and backup your files and try. This is a learning experience and there won't be any penalty.

@M-Abdoon M-Abdoon closed this Oct 20, 2025
@M-Abdoon M-Abdoon deleted the Sprint-3/1_implement_and_rewrite_tests branch October 20, 2025 11:59
@M-Abdoon M-Abdoon restored the Sprint-3/1_implement_and_rewrite_tests branch October 20, 2025 12:07
@M-Abdoon M-Abdoon reopened this Oct 20, 2025
@M-Abdoon M-Abdoon changed the base branch from main to cjyuan-patch-1 October 20, 2025 12:38
@M-Abdoon M-Abdoon changed the base branch from cjyuan-patch-1 to main October 20, 2025 12:38
@M-Abdoon M-Abdoon closed this Oct 20, 2025
@M-Abdoon M-Abdoon deleted the Sprint-3/1_implement_and_rewrite_tests branch October 20, 2025 12:39
@M-Abdoon
Copy link
Author

We can rename the remote branch directly on GitHub and keep the PR stay opened. However, we would also need to update our local branch to track the new remote name. (You will have to run some Git command on CLI). (Ask AI how to accomplish this).

Go ahead and backup your files and try. This is a learning experience and there won't be any penalty.

It didn’t work. I tried renaming it directly on GitHub and also tried renaming it locally and pushing it, but the PR still gets closed. I even asked different AI tools, ChatGPT, Copilot, and Gemini, and they all ended up saying that if I want to keep my PR, I just don’t rename it! I guess I’ll need extra help; maybe I’ll ask a volunteer to help me during the workshop next Saturday.

@M-Abdoon M-Abdoon restored the Sprint-3/1_implement_and_rewrite_tests branch October 20, 2025 12:46
@M-Abdoon M-Abdoon reopened this Oct 20, 2025
@cjyuan
Copy link
Contributor

cjyuan commented Oct 20, 2025

You are right. The PR will be closed when the branch is renamed. I remembered incorrectly. Sorry about that. You can just keep this branch and PR (instead of opening a new one).

@M-Abdoon
Copy link
Author

No worries at all, I learned several things while trying to rename the branch without having it closed :)

The required changes have been made, thank you.

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

Changes look good. I have few more suggestions but I will go ahead and mark this PR as complete first as it has met all the basic requirements.

Comment on lines 19 to 23
rank = Number(Math.floor(rank));

if ((rank >= 2) && (rank <= 10)) {
return rank;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach ensures values like "3.1416" or "0x00002" get returned as an equivalent integer, but do you want to consider "3.1416♥" or "0x00002♠" valid card values?

Copy link
Author

Choose a reason for hiding this comment

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

I want to exclude them, so I added this condition :

if(!Number.isInteger(Number(rank) ) || /^0x/i.test(rank)) {
    return "Invalid card rank.";
  }

to ensure that the number is an integer without a decimal part, and to make sure it isn’t a hexadecimal value by using a regex with test().

Copy link
Contributor

@cjyuan cjyuan Oct 21, 2025

Choose a reason for hiding this comment

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

If you are using this approach (to consider what to reject), you would need to consider all valid numeric literal representations in the JS language. You can look up how numbers can be represented in the JS language.

Instead of focusing on what values are invalid, we could focus on what values are valid.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I understand.
Thank you so much.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 21, 2025
@M-Abdoon
Copy link
Author

Changes look good. I have few more suggestions but I will go ahead and mark this PR as complete first as it has met all the basic requirements.

Thank you so much. I applied your suggestions to my code and gained better knowledge from them. Thanks again :)

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants