-
-
Notifications
You must be signed in to change notification settings - Fork 195
London|May-2025|KhilolaRustamova|Module-Structuring-&-Testing-Data|sprint 3 #636
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?
Changes from 13 commits
e896a1d
1f19e5f
027d9ce
8c4ec1d
06d34c1
f96e282
87c4741
1957cac
21b747c
d10259a
3f3ced1
d5d4140
bff571f
b9e25d5
7f9b036
859aa90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,16 @@ | |
// write one test at a time, and make it pass, build your solution up methodically | ||
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers | ||
function getCardValue(card) { | ||
|
||
const rank = card.slice(0, -1); // remove the suit emoji | ||
if (rank === "A") return 11; | ||
if (["K", "Q", "J", "10"].includes(rank)) return 10; | ||
|
||
const num = parseInt(rank); | ||
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, but: either of these lines of code could handle the value 10 - why did you decide to handle it in the K/Q/J case rather than the number case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By grouping "10" with "K", "Q", and "J", you make the intention clear:
It also avoids need of extra range check (num === 10) in the number parsing block, which could make the logic more complex. |
||
|
||
if (num >= 2 && num <= 9) return num; | ||
|
||
throw new Error("Invalid card rank"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this exception is thrown, it may not be clear to the caller what the invalid rank was - can you think how to make this more clear? |
||
} | ||
|
||
// You need to write assertions for your function to check it works in different cases | ||
|
@@ -34,12 +43,20 @@ assertEquals(aceofSpades, 11); | |
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). | ||
const fiveofHearts = getCardValue("5♥"); | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
assertEquals(fiveofHearts, 5); | ||
|
||
// Handle Face Cards (J, Q, K): | ||
// Given a card with a rank of "10," "J," "Q," or "K", | ||
// When the function is called with such a card, | ||
// Then it should return the value 10, as these cards are worth 10 points each in blackjack. | ||
const jackOfDiamonds = getCardValue("J♦"); | ||
assertEquals(jackOfDiamonds, 10); | ||
|
||
const queenOfClubs = getCardValue("Q♣"); | ||
assertEquals(queenOfClubs, 10); | ||
|
||
const kingOfSpades = getCardValue("K♠"); | ||
assertEquals(kingOfSpades, 10); | ||
// Handle Ace (A): | ||
// Given a card with a rank of "A", | ||
// When the function is called with an Ace, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,46 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
if (numerator >= denominator) return false; | ||
// add your completed function from key-implement here | ||
} | ||
|
||
// here's our helper again | ||
function assertEquals(actualOutput, targetOutput) { | ||
console.assert( | ||
actualOutput === targetOutput, | ||
`Expected ${actualOutput} to equal ${targetOutput}` | ||
); | ||
} | ||
|
||
// Acceptance criteria: | ||
|
||
// Proper Fraction check: | ||
// Input: numerator = 2, denominator = 3 | ||
// target output: true | ||
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true. | ||
const properFraction = isProperFraction(2, 3); | ||
assertEquals(properFraction, true); | ||
|
||
// Improper Fraction check: | ||
// Input: numerator = 5, denominator = 2 | ||
// target output: false | ||
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false. | ||
const improperFraction = isProperFraction(5, 2); | ||
assertEquals(improperFraction, false); | ||
|
||
// Negative Fraction check: | ||
// Input: numerator = -4, denominator = 7 | ||
// target output: true | ||
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. | ||
const negativeFraction = isProperFraction(-4, 7); | ||
// ====> complete with your assertion | ||
assertEquals(negativeFraction, true); | ||
// Equal Numerator and Denominator check: | ||
// Input: numerator = 3, denominator = 3 | ||
// target output: false | ||
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. | ||
const equalFraction = isProperFraction(3, 3); | ||
// ====> complete with your assertion | ||
assertEquals(equalFraction, false); | ||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,35 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
const rank = card.slice(0, -1); // remove the suit emoji | ||
if (rank === "A") return 11; | ||
if (["K", "Q", "J", "10"].includes(rank)) return 10; | ||
|
||
const num = parseInt(rank); | ||
|
||
if (num >= 2 && num <= 9) return num; | ||
|
||
throw new Error("Invalid card rank"); | ||
} | ||
function assertEquals(actualOutput, targetOutput) { | ||
console.assert( | ||
actualOutput === targetOutput, | ||
`Expected ${actualOutput} to equal ${targetOutput}` | ||
); | ||
} | ||
|
||
const aceofSpades = getCardValue("A♠"); | ||
assertEquals(aceofSpades, 11); | ||
const fiveofHearts = getCardValue("5♥"); | ||
assertEquals(fiveofHearts, 5); | ||
const jackOfDiamonds = getCardValue("J♦"); | ||
assertEquals(jackOfDiamonds, 10); | ||
|
||
const queenOfClubs = getCardValue("Q♣"); | ||
assertEquals(queenOfClubs, 10); | ||
|
||
const kingOfSpades = getCardValue("K♠"); | ||
assertEquals(kingOfSpades, 10); | ||
|
||
|
||
|
||
|
||
module.exports = getCardValue; |
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.
This comment explains clearly what's going on - nice comment!