Skip to content

Birmingham | ITP-Jan | Ahmad Roman Sanaye | Sprint 3 | Implement functions and rewrite tests #1119

Open
RomanSanaye wants to merge 7 commits intoCodeYourFuture:mainfrom
RomanSanaye:coursework/sprint-3-implement-and-rewrite
Open

Birmingham | ITP-Jan | Ahmad Roman Sanaye | Sprint 3 | Implement functions and rewrite tests #1119
RomanSanaye wants to merge 7 commits intoCodeYourFuture:mainfrom
RomanSanaye:coursework/sprint-3-implement-and-rewrite

Conversation

@RomanSanaye
Copy link

@RomanSanaye RomanSanaye commented Mar 1, 2026

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

  • Updated getCardValue function to properly validate card ranks using /^[JQK]$/ for face cards instead of /J|Q|K/.
  • Added Jest tests for edge cases mentioned by the reviewer: "0x02♠", "QQ♠", "2.1♠".
  • Refactored existing tests for clarity and full coverage of:
    • Ace cards (A)
    • Number cards (2–10)
    • Face cards (J, Q, K)
    • Invalid cards
  • Formatted the get-angle-type code using Prettier extension for consistent style.
  • Completed the second part of the Implement and Rewrite Test folder, including proper test coverage and organization.

Testing

  • All Jest tests pass locally, including the new edge case tests.

@github-actions

This comment has been minimized.

@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 1, 2026
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.

This exercise has a second part, where you are expected to implement Jest tests on the files in Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest.


Can you also include a Changelist section in the PR description?

// TODO: Implement this function
if(numerator <= 0 || denominator <= 0){
return false;
}else if(numerator < denominator){
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check if 1/-2, -1/2, -1/-2 are consider proper fractions, and then update the implementation and tests accordingly?

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

Comment on lines +38 to +40
}else if(rank.match(/J|Q|K/)){
return 10;
}else if(rank.match(/^(10|[2-9])$/)){
Copy link
Contributor

Choose a reason for hiding this comment

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

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

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

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

@cjyuan cjyuan 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 Mar 9, 2026
@github-actions
Copy link

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: ^Sprint-3/1-implement-and-rewrite-tests/

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is this file?

Comment on lines +36 to +43
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");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

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:

  1. Use "Format document" to format the JS file. Sometimes, VSCode will ask you to choose a formatter, and you can manually select "Prettier".
  2. Edit settings.json and set Prettier as the default formatter for JS.
    See: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode

Comment on lines +11 to +25
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
Copy link
Contributor

Choose a reason for hiding this comment

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

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

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