Skip to content

London | 26-ITP-May | Dipa Sarker | Sprint 3 | Implement and rewrite final#1470

Open
Dipa-Sarker wants to merge 10 commits into
CodeYourFuture:mainfrom
Dipa-Sarker:Coursework/sprint-3-implement-and-rewrite-final
Open

London | 26-ITP-May | Dipa Sarker | Sprint 3 | Implement and rewrite final#1470
Dipa-Sarker wants to merge 10 commits into
CodeYourFuture:mainfrom
Dipa-Sarker:Coursework/sprint-3-implement-and-rewrite-final

Conversation

@Dipa-Sarker

Copy link
Copy Markdown

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

  1. Implemented the required functionality for the angle type, proper fraction and card value logic.
  2. Rewrote and expanded the tests using Jest.
  3. Added test cases to verify expected behavior and improve test coverage.
  4. Refactored the implementation where needed to ensure the code passes all Jest tests.

@Dipa-Sarker

Copy link
Copy Markdown
Author

Hello Reviewers,
I just wanted to inform that, I made several mistakes creating branching for each of the sprints (Sprint-1, Sprint-2, Sprint-3/implement and re-write tests, Sprint-3/Practice-tdd. After so many attempts I was able to create separate branches and for that reason I named this branch "implement and re-write final". I hope I will more conscious about this issue in near future. Thank you.

@Dipa-Sarker Dipa-Sarker added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jul 6, 2026
if (angle <= 0 || angle >= 360) {
return "Invalid angle";
}
else if (angle == 90) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Whats the difference between == and === and why are you using == here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

== converts and compares operands that are of different types and === always considers operands of different types to be different. In this case, angle == 90 which means LHS is compared with RHS and it is equal. I can also use ===.

Comment on lines +83 to +97
//module.exports = getAngleType;

// This helper function is written to make our assertions easier to read.
// If the actual output matches the target output, the test will pass
// function assertEquals(actualOutput, targetOutput) {
//console.assert(
//actualOutput === targetOutput,
//`Expected ${actualOutput} to equal ${targetOutput}`
//);
//}

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
//const right = getAngleType(90);
//assertEquals(right, "Right angle"); No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is there commented out code?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In my file there is no commented code showing. I have attached the screenshot.
Screenshot 2026-07-12 222351

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Did you commit and push all code?
If you check on the remote (for example in the PR diff view on Github) you' ll see the code: https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/pull/1470/changes#diff-714a296fc0e0b2cf1e44da9dcbd08ccd678295a69af1884e7f2e1686aaef8626R81

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Now I erased commented code and then did commit and push code correctly. If there is anything wrong again, please let me know.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Screenshot 2026-07-14 220401

Comment on lines +12 to +22
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});
test(`should return "Straight angle" when (0 == 180)`, () => {
expect(getAngleType(180)).toEqual("Straight angle");
});
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job on testing the border cases here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you!

Comment on lines +25 to +26
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(370)).toEqual("Invalid angle");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Which border cases can you test here? (Which numbers are closest to the condition?)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I tested for the invalid case when (angle <= 0 || angle >= 360). So, when i considered -1 and 370, the closest number for this condition is -1 and 361. Because -1 is closest to 0 and 361 is closest to 360.

Comment on lines +23 to +28
test(`should return false when numerator is negative`, () => {
expect(isProperFraction(-1, 1)).toEqual(false);
});
test(`should return false when denominator is negative`, () => {
expect(isProperFraction(1, -1)).toEqual(false);
}); No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What about values like -1/2 or 1/-2. What should the function return for them?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think for values like -1/2 or 1/-2, the function will also return false because proper fractions normally require positive numerator and denominator.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I believe a proper fraction can also include negative values
In general, a common fraction is said to be a proper fraction if the absolute value of the fraction is strictly less than one—that is, if the fraction is greater than −1 and less than 1.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh! now I am clear about the concept of proper fraction. So -1/2 or 1/-2 can be proper fraction cause both of these absolute value is 1/2 which is -1<1/2<1.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct. Please adjust the tests accordingly.


function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (numerator <= 0 || denominator <= 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why does the numerator be bigger than 0?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry I cannot understand your question. It says, the numerator is less than or equal to 0.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry I was missing a word. Why can the numerator not be 0?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Okay, yes for proper fraction numerator can be 0 but denominator cannot. Another thing is, negative value can be acceptable if the absolute value of the fraction meet the condition for proper fraction -1<fraction<1. So, for example when numerator = 0 and denominator = 6, then fraction = 0 which meets -1<0<1.
Is my thought now correct? please let me know. I also made the necessary correction in the code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I was confused at first that's why I left (numerator <= 0 || denominator <= 0) and the return value numerator < denominator.

Comment on lines +31 to +44
if (!validRank.includes(rank) || !validSuit.includes(suit)) {
throw new Error("Invalid Card");
}

if (rank === "A") {
return 11;
}
else if (rank === "J" || rank=== "Q" || rank === "K") {
return 10;
}

// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getCardValue;
else if (rank >= 2 && rank <= 10) {
return Number(rank);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The indentation is a bit off. How can you ensure consistent formatting in your code?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I used prettier tool to fix the formation of the entire code. Please let me know if it is okay or not.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't see any changes on this file. Did you push the changes?

Comment on lines +28 to +29
const validRank = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"];
const validSuit = ["♠","♥","♦","♣"];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job on explicitly listing all allowed ranks and suits. This makes the code easier to read and the logic for checking easier as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you!

// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getCardValue;
else if (rank >= 2 && rank <= 10) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens if the condition is false?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If rank >= 2 && rank <= 10 is false, suppose if rank = 11, the function does not return Number(rank). For invalid rank throw new Error("Invalid Card") check before reaching this point.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So when the code reaches this point you can already be certain that the rank is between 2 and 10. You did the checks earlier so this condition is not needed and can be removed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh, yes I got your point and made correction.

expect(getCardValue("K♦")).toEqual(10);
});
});
describe("Invalid Cards", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Which part of the condition is not covered by the invalid test cases yet?
if (!validRank.includes(rank) || !validSuit.includes(suit)) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Is it for Invalid suit?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes exactly. Please add some test cases for verifying teh valid suit check works correctly

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added some test cases for invalid suits and also run the code.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done now both conditions are tetseted

@Luro91 Luro91 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 Jul 10, 2026
@Dipa-Sarker Dipa-Sarker 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 Jul 13, 2026
@Luro91

Luro91 commented Jul 13, 2026

Copy link
Copy Markdown

It seems some of your changes are not pushed. Please always ensure the changes are pushed correctly by checking the diff view of the PR in Github directly

@Luro91 Luro91 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 Jul 13, 2026
@Dipa-Sarker

Copy link
Copy Markdown
Author

Every time after completing my task I try to maintain git add, git commit & git push. But now I cannot figure out how can I made such mistakes of not pushing. I think I done this by mistakenly. I am extremely sorry for that. Now I correctly pushed all the changes I made. If there is anything wrong again please let me know. Thank you again for your feedback!

@Dipa-Sarker Dipa-Sarker 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 Jul 14, 2026

@Luro91 Luro91 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The part about negative numerator or denominator is not working correctly yet

if (denominator === 0) {
return false;
}
else if (numerator >= 0 && denominator !== 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this check for denomitor !== 0 really needed?

I think the numerator could also be negative.

Comment on lines +23 to +28
test(`should return false when numerator is negative`, () => {
expect(isProperFraction(-1, 1)).toEqual(false);
});
test(`should return false when denominator is negative`, () => {
expect(isProperFraction(1, -1)).toEqual(false);
}); No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct. Please adjust the tests accordingly.

@Luro91 Luro91 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 Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants