-
-
Notifications
You must be signed in to change notification settings - Fork 195
WESTMIDLANDS | ITP-MAY-25 | AHMAD EHSAS | MODULE STRUCTURING AND TESTING DATA SPRINT-3 #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…, and invalid cards
…he goal of this function is to count how many times a specific character appears in a given string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (rank === "A") return 11; | ||
if (["K", "Q", "J"].includes(rank)) return 10; | ||
|
||
const number = parseInt(rank); |
There was a problem hiding this comment.
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("2.1♠");
getCardValue("0002♠");
getCardValue("3ABC♠");
Consider looking up how parseInt()
work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the function returns the card value based on the card's rank.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt()
can return an integer but do you consider the values I suggested valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As parseInt()
returns Integers, and the values with decimal numbers can only return an integer, not the decimal part. So technically, the values you suggested are valid in the sense that it doesn't cause an error. But it does not reflect the true value of the number. It truncates the decimal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The objective of the function is to determine the value of the rank of a card.
If you were to design a card game, would you allow the card to be displayed as
"2.9999999999999999999999♠", "3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA♠"?
test("should return 5 for 5 of Hearts", () => { | ||
const fiveofHearts = getCardValue("5♥"); | ||
expect(fiveofHearts).toEqual(5); | ||
}); | ||
|
||
test("should return 10 for 10 of Diamonds", () => { | ||
const tenofDiamonds = getCardValue("10♦"); | ||
expect(tenofDiamonds).toEqual(10); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When preparing tests, we should ensure the tests cover all possible cases. If we specify a test for individual card, we will need about 53 tests to cover all possible cases. Instead, we could consider classifying all possible values into different categories, and then within each category we test some samples.
For example, one possible category for getCardValue()
is, "should return the value of number cards (2-10)", and we can prepare the test as
test("should return the value of number cards (2-10)", () => {
expect(getCardValue("2♣︎")).toEqual(2);
expect(getCardValue("5♠")).toEqual(5);
expect(getCardValue("10♥")).toEqual(10);
// Note: We could also use a loop to check all values from 2 to 10.
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not make any change to your code accordingly.
test("should return 10 for Jack of Clubs", () => { | ||
const jackofClubs = getCardValue("J♣"); | ||
expect(jackofClubs).toEqual(10); | ||
}); | ||
|
||
test("should return 10 for Queen of Hearts", () => { | ||
const queenofHearts = getCardValue("Q♥"); | ||
expect(queenofHearts).toEqual(10); | ||
}); | ||
|
||
test("should return 10 for King of Spades", () => { | ||
const kingofSpades = getCardValue("K♠"); | ||
expect(kingofSpades).toEqual(10); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could combine these tests and place them under the category "should return 10 for face cards (J, Q, K)".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests in this Jest script are incomplete. When you have fully implemented the function in Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
, can you prepare tests in this script to cover all valid integers in the following way:
Group all possible input values into meaningful categories, and then, select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain.
For example, we can prepare a test for numbers 2, 22, 132, etc. as
test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
expect( getOrdinalNumber(2) ).toEqual("2nd");
expect( getOrdinalNumber(22) ).toEqual("22nd");
expect( getOrdinalNumber(132) ).toEqual("132nd");
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not update the tests in Sprint-3/3-mandatory-practice/implement/repeat.test.js
to check your implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is updated, and all the tests have been passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still could not see an updated Sprint-3/3-mandatory-practice/implement/repeat.test.js
file. Did you forget to push your changes to GitHub?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies, the tests are now updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files in "Sprint-1" folder not yet reverted.
if (rank === "A") return 11; | ||
if (["K", "Q", "J"].includes(rank)) return 10; | ||
|
||
const number = parseInt(rank); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt()
can return an integer but do you consider the values I suggested valid?
test("should return 5 for 5 of Hearts", () => { | ||
const fiveofHearts = getCardValue("5♥"); | ||
expect(fiveofHearts).toEqual(5); | ||
}); | ||
|
||
test("should return 10 for 10 of Diamonds", () => { | ||
const tenofDiamonds = getCardValue("10♦"); | ||
expect(tenofDiamonds).toEqual(10); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not make any change to your code accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the tests in this script so that they cover all valid integers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still could not see an updated Sprint-3/3-mandatory-practice/implement/repeat.test.js
file. Did you forget to push your changes to GitHub?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted files are still considered "changed files", and they will still show up in the "Files changed" tab, making code reviewing inconvenience. (In practice, it would also make merging difficult.)

One way to revert the changes is to do the following (to restore the files to their original version):
-
Download your
main
branch as a ZIP file. -
In VSCode, switch to this branch (
coursework/sprint-3
). -
Copy these two files from the ZIP file to this branch (make sure they are copied to the right folder).
Sprint-1/1-key-exercises/1-count.js
Sprint-1/readme.md
-
Verify and commit the change.
-
Push the change to Github.
//test("should return '1st' for 1", () => { | ||
//expect(getOrdinalNumber(1)).toEqual("1st"); | ||
//}); | ||
|
||
test("append 'st' to numbers ending in 1, except those ending in 11", () => { | ||
expect(getOrdinalNumber(1)).toEqual("1st"); | ||
expect(getOrdinalNumber(21)).toEqual("21st"); | ||
expect(getOrdinalNumber(121)).toEqual("121st"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the tests in this script so that they cover all valid integers?
if (rank === "A") return 11; | ||
if (["K", "Q", "J"].includes(rank)) return 10; | ||
|
||
const number = parseInt(rank); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The objective of the function is to determine the value of the rank of a card.
If you were to design a card game, would you allow the card to be displayed as
"2.9999999999999999999999♠", "3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA♠"?
Self checklist
Changelist
Briefly explain your PR.
Completed sprint-3, dealing with errors and understanding the flow of a program
Questions