Skip to content

Conversation

@asaniDev
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

created functions and practiced test driven development by making tests for the functions.

@github-actions
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Sprint part (Sprint-3) doesn't match expected format (example: 'Sprint 2', without quotes)

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

@asaniDev asaniDev changed the title West Midlands | ITP-Sept-25 | Mustaf Asani | Sprint-3 | Coursework/sprint 3 implement and rewrite West Midlands | ITP-Sept-25 | Mustaf Asani | Sprint 3 | Coursework/sprint 3 implement and rewrite Oct 23, 2025
@asaniDev asaniDev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 23, 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 the Sprint-2 folder are not related to Sprint-3 exercise. Can you revert the changes made in the Sprint-2 folder?

// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
function getCardValue(card) {
if (rank === "A") {
const rank = card[0];
Copy link
Contributor

@cjyuan cjyuan Oct 27, 2025

Choose a reason for hiding this comment

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

card[0] yields only a string with the first character -- not necessary the whole rank.

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 do need to make my tests more robust. I managed to get the correct rank for single digit and multiple digit cards.

Comment on lines 15 to 17
test("should return true for a proper fraction based on the absolute values of the numerator and denominator", () => {
expect(isProperFraction(-3, 8)).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.

To make the test more comprehensive, we could test multiple samples like this:

test("should return true for a proper fraction based on the absolute values of the numerator and denominator", () => {
  expect(isProperFraction(-3, 8)).toEqual(true);
  expect(isProperFraction(-3, -8)).toEqual(true);
  expect(isProperFraction(3, -8)).toEqual(true);
  expect(isProperFraction(3, 8)).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.

added multiple test samples for this and other lines as well.

Comment on lines 26 to 29
test("should return 11 for Ace of Spades", () => {
const invalidCard = getCardValue("1♥");
expect(invalidCard).toEqual("Invalid card rank.");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The test description does not quite match what is being tested.

Copy link
Author

Choose a reason for hiding this comment

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

corrected the test description.

Comment on lines 11 to 14
test("should return a number matchig the rank value for given card", () => {
const numberCard = getCardValue("5♠");
expect(numberCard).toEqual(5);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

  • I think "... for number cards (2-10)" would be more informative than "... for given card")
  • Could test multiple values, especially the boundary cases like "2♠" and "10♠".

Copy link
Author

Choose a reason for hiding this comment

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

added a more informative description. also tested the 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 Oct 27, 2025
…orrected test description for invalid cards, used more informative descriptions
… for cards with more than 1 digit, removed check for negative value since im using maths.abs
@asaniDev asaniDev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 29, 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.

There are still three modified files in the "Sprint-2" folder. Can you revert the changes made to them?

Comment on lines 11 to 15
let rank = "";

if (card === "A♠") {
return 11;
} else if (Number(rank) > 1 && Number(rank) < 10) {
for (let i = 0; i < card.length - 1; i++) {
rank += card[i];
}
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 work.

You could also consider using built-in functions (methods) of String. Mastering these String's methods can simplify a lot of string processing tasks.

Comment on lines 17 to 18
if (Number.isInteger(Number(rank)) && Number(rank) > 1 && Number(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 or parsed into a valid integers.
Do you want to recognize these string values as valid ranks?

To find out what these strings are, you can ask AI

What kinds of string values would make Number(rank) evaluate to 2 in JS?

Copy link
Author

Choose a reason for hiding this comment

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

i added a regex to only allow specific numeric literals that convert to numbers which would be in our range 2 -10 and ignore all others.

Comment on lines 11 to 12
expect(isProperFraction(7, 4)).toEqual(false);
expect(isProperFraction(35, 8)).toEqual(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also test some negative improper fractions in this test.

Comment on lines 11 to 12
test("should return 10 for Face Cards", () => {
const faceCard = getCardValue("K♠");
const faceCard = getCardValue("10♠");
Copy link
Contributor

Choose a reason for hiding this comment

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

Face cards are J, Q, K. 10 is consider a number card.

Comment on lines 7 to 8
const numberCard = getCardValue("5♠");
expect(numberCard).toEqual(5);
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 test multiple samples (especially the boundary cases, "2♠" and "10♠") to make the test more robust.

Copy link
Author

Choose a reason for hiding this comment

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

added a suite of tests for different values to make the test more robust

Comment on lines 21 to 29
test("should return invalid card rank for cards that are not in the suite", () => {
const invalidCard = getCardValue("100♥");
expect(invalidCard).toEqual("Invalid card rank.");
});

test("should return invalid card rank for cards that are not in the suite", () => {
const invalidCard = getCardValue("3.1416♥");
expect(invalidCard).toEqual("Invalid card rank.");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

They both test "invalid case". Consider combine them into one test but using multiple samples.

Copy link
Author

Choose a reason for hiding this comment

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

combined the tests and added more tests for different values

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 29, 2025
@asaniDev asaniDev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 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 tests are now very solid. Well done.

  • This PR branch still contains unrelated changes in "Sprint-2" folder. Can you revert the changes made in the "Sprint-2" folder to make the PR branch clean?

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 17, 2025
@asaniDev asaniDev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 22, 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. Well done.

Comment on lines +21 to +25
if (strictNumber(rank)) {
if (pattern.test(Number(rank))) {
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.

Is the outer if statement necessary?


if (faceCardPattern.test(rank)) {
return 10;
} else if (/^A$/.test(rank)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also just write rank == 'A'.

@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. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 23, 2025
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