Birmingham | ITP-Jan | Ahmad Roman Sanaye | Sprint 3 | Implement functions and rewrite tests #1119
Conversation
This comment has been minimized.
This comment has been minimized.
Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
Outdated
Show resolved
Hide resolved
| // TODO: Implement this function | ||
| if(numerator <= 0 || denominator <= 0){ | ||
| return false; | ||
| }else if(numerator < denominator){ |
There was a problem hiding this comment.
Can you check if 1/-2, -1/2, -1/-2 are consider proper fractions, and then update the implementation and tests accordingly?
There was a problem hiding this comment.
Thank you for the suggestion — it was very useful. I checked 1/-2, -1/2, and -1/-2; all are proper fractions. I updated the isProperFraction function and tests using Math.abs() to handle these cases.
| }else if(rank.match(/J|Q|K/)){ | ||
| return 10; | ||
| }else if(rank.match(/^(10|[2-9])$/)){ |
There was a problem hiding this comment.
Does your function return the value you expected from each of the following function calls?
getCardValue("0x02♠");
getCardValue("QQ♠");
getCardValue("2.1♠");
There was a problem hiding this comment.
Thank you for pointing this out. I have tested the function with getCardValue("0x02♠"), getCardValue("QQ♠"), and getCardValue("2.1♠"); all now correctly throw an "Invalid card" error as expected. I also added Jest tests to cover these edge cases.
|
The changed files in this PR don't match what is expected for this task. Please check that you committed the right files for the task, and that there are no accidentally committed files from other sprints. Please review the changed files tab at the top of the page, we are only expecting changes in this directory: If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
| if (rank === "A"){ | ||
| return 11; | ||
| }else if(/^[JQK]$/.test(rank)){ | ||
| return 10; | ||
| }else if(rank.match(/^(10|[2-9])$/)){ | ||
| return Number(rank); | ||
| }else throw new Error("Invalid card"); | ||
| } |
There was a problem hiding this comment.
If you have successfully enabled "Format on save", and setup Prettier as your the default formatter in VSCode,
the formatter should have added a space between } and else, between if and (, and between ) and {.
If you have enabled "Format on save" but it is not working, it is likely that you haven't assign a formatter for JS file. This could happen if you have zero or multiple extensions that can format .js file.
If you have installed "Prettier" extension. To assign it as the formatter of JS code, you can try:
- Use "Format document" to format the JS file. Sometimes, VSCode will ask you to choose a formatter, and you can manually select "Prettier".
- Edit
settings.jsonand set Prettier as the default formatter for JS.
See: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
| test(`should return false when denominator is less than numerator`, () => { | ||
| expect(isProperFraction(2, 1)).toEqual(false); | ||
| }); | ||
| test("should return false when numerator is zero", ()=>{ | ||
| expect(isProperFraction(0, 1)).toEqual(false); | ||
| }); | ||
| test("should return false when numerator is a negative number", ()=>{ | ||
| expect(isProperFraction(-2, 2)).toEqual(false); | ||
| }); | ||
| test("should return false when denominator is a negative number", ()=>{ | ||
| expect(isProperFraction(2, -2)).toEqual(false); | ||
| }); | ||
| test("should return false where both numerator and denominator are negative numbers", ()=> { | ||
| expect(isProperFraction(-3, -4)).toEqual(false); | ||
| }) No newline at end of file |
There was a problem hiding this comment.
-
These descriptions are not quite accurate. Can you revise them?
-
Could consider testing all combination of positive and negative numerators and denominators.
-
It's ok to use symbols and notations in the description if they can help make the description more concise.
- To learn by examples, use an AI tool to discover how you can phrase the test descriptions concisely.
Learners, PR Template
Self checklist
Changelist
getCardValuefunction to properly validate card ranks using/^[JQK]$/for face cards instead of/J|Q|K/."0x02♠","QQ♠","2.1♠".A)2–10)J, Q, K)get-angle-typecode using Prettier extension for consistent style.Testing