West Midlands | 25 Sep ITP | Iswat Bello | Sprint 3 | Implement and rewrite tests#800
West Midlands | 25 Sep ITP | Iswat Bello | Sprint 3 | Implement and rewrite tests#800Iswanna wants to merge 34 commits intoCodeYourFuture:mainfrom
Conversation
…hrow an error for invalid cards
| if (numerator < denominator && numerator !== 0) { | ||
| return true; | ||
| } else if (numerator >= denominator) { | ||
| return false; | ||
| } else if (numerator === 0) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
The function won't work properly if numerator and denominator are allowed to be negatives.
For example -3 < 2 but -3/2 is not a proper fraction.
| function getCardValue(card) { | ||
| if (rank === "A") { | ||
| card = card.substring(0 , card.length -1); // Remove the suit emoji | ||
| console.log(card); |
There was a problem hiding this comment.
For best practices, we should ensure code submitted in a PR free of any debugging code.
Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
Outdated
Show resolved
Hide resolved
| // just make one change at a time -- don't rush -- programmers are deep and careful thinkers | ||
| function getCardValue(card) { | ||
| if (rank === "A") { | ||
| card = card.substring(0 , card.length -1); // Remove the suit emoji |
There was a problem hiding this comment.
Why not use a separate variable rank to represents the rank of a card?
We could reuse a variable but it is better not to use the same variable to store different kinds of value.
- "A♠" => represent the value of a card
- "A" ==> represent the value of a rank
| test("should identify reflex angle (>180° and <360°)", () => { | ||
| expect(getAngleType(250)).toEqual("Reflex angle"); | ||
| }); |
There was a problem hiding this comment.
To make a test more robust, 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° and <360°)", () => {
expect(getAngleType(300)).toEqual("Reflex angle");
expect(getAngleType(359.999)).toEqual("Reflex angle");
expect(getAngleType(180.001)).toEqual("Reflex angle");
});
| test("should return false for negative fractions", () => { | ||
| expect(isProperFraction(-4, 9)).toEqual(true); | ||
| }) |
There was a problem hiding this comment.
The test description does not quite match the test being performed.
| test("should return the numeric value for number cards from 2 to 10", () => { | ||
| const numberCard = getCardValue("7♥"); | ||
| expect(numberCard).toEqual(7); | ||
| }) |
There was a problem hiding this comment.
Could consider testing multiple values, especially the boundary cases "2♥" and "10♥".
|
Hi @cjyuan. Thank you so much for all the feedback. I will work on all of them and update all the necessary files. |
…s; update function to handle them
…put (90.0) for right angle
… instead of "Acute angle"
…r negative numerator
…sure proper handling of invalid card ranks
|
Hi @cjyuan. Thanks for your feedback! I’ve updated the code and tests to address all your suggestions. |
cjyuan
left a comment
There was a problem hiding this comment.
Changes look great.
You might have misunderstood the definition of proper fraction.
| let actualOutput; | ||
| // Denominator must be positive | ||
| if (denominator <= 0) { | ||
| actualOutput = false; | ||
| } | ||
| // Numerator must be positive and smaller than denominator | ||
| else if (numerator > 0 && numerator < denominator) { | ||
| actualOutput = true; | ||
| } | ||
| // All other cases are not proper fractions | ||
| else { | ||
| actualOutput = false; | ||
| } |
There was a problem hiding this comment.
-
In math, 2/-3 equals to -2/3, and -2/-3 is equal to 2/3. So a fraction could still be considered as a proper fraction even if its denominator is negative.
-
-2/3 is a proper fraction.
Suggestion: Lookup the definition of proper fraction. You may also need to update the tests accordingly.
There was a problem hiding this comment.
- In math, 2/-3 equals to -2/3, and -2/-3 is equal to 2/3. So a fraction could still be considered as a proper fraction even if its denominator is negative.
- -2/3 is a proper fraction.
Suggestion: Lookup the definition of proper fraction. You may also need to update the tests accordingly.
Hi @cjyuan.
Thank you for the clarification! You’re absolutely right. The sign of the denominator doesn’t affect whether a fraction is proper, and I should be comparing the absolute values instead.
I’ll update the function to handle negative denominators and negative numerators correctly and update the tests accordingly.
There was a problem hiding this comment.
- In math, 2/-3 equals to -2/3, and -2/-3 is equal to 2/3. So a fraction could still be considered as a proper fraction even if its denominator is negative.
- -2/3 is a proper fraction.
Suggestion: Lookup the definition of proper fraction. You may also need to update the tests accordingly.
Hi @cjyuan.
Thank you for the clarification! You’re absolutely right. The sign of the denominator doesn’t affect whether a fraction is proper, and I should be comparing the absolute values instead.
I’ll update the function to handle negative denominators and negative numerators correctly and update the tests accordingly.
Hi @cjyuan.
I have updated the function and tests to correctly handle proper fractions with negative numerators or denominators. I also added additional test cases to ensure the function produces the expected output.
Thank you.
…erators or denominators
… negative zero, and 2/4 fraction
cjyuan
left a comment
There was a problem hiding this comment.
Changes made to the function isProperFraction() looks good.
The test script could use some improvement. I will mark this PR as complete first.
| test("should return false for negative fractions", () => { | ||
| expect(isProperFraction(-4, 9)).toEqual(false); | ||
| expect(isProperFraction(-4, 9)).toEqual(true); | ||
| }) |
There was a problem hiding this comment.
-
The test description does not quite match the test being carried out.
-
Could also consider testing multiple values in each test.
There was a problem hiding this comment.
- The test description does not quite match the test being carried out.
- Could also consider testing multiple values in each test.
Hi @cjyuan.
Thank you for the feedback. I have updated the test description to match the test. I have also tested more values for each test case.
Hi @cjyuan. Thank you so much for the detailed feedback throughout the review of my code. I really appreciate it, and it has been a valuable learning experience for me. Thank you also for marking my PR as complete. |
…ith negative numerator
… negative numerator
Learners, PR Template
Self checklist
Changelist
This pull request involves modifications to two directories:
Implement directory: I added assertions using
console.assertand built the program case by case.Rewrite-tests-with-Jest directory: I rewrote the existing test cases using Jest and ran
npm testto verify the implementation of the getCardValue function.Questions
Hi. Please could you review my PR? I’d really appreciate your feedback?