-
-
Notifications
You must be signed in to change notification settings - Fork 197
Manchester | ITP-May-2025 | Chukwuemeke Ajuebor | Module-Structuring-and-Testing-Data | Sprint 3 #674
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?
Manchester | ITP-May-2025 | Chukwuemeke Ajuebor | Module-Structuring-and-Testing-Data | Sprint 3 #674
Changes from all commits
3a0c9d0
f586e60
59d50b8
a0349bc
7452269
71764ee
099824c
cbdfa96
7d1d62c
10d7b40
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,8 +8,19 @@ | |
// 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) { | ||
if (rank === "A") return 11; | ||
} | ||
let rank; | ||
if (card.startsWith("10")) { | ||
rank = 10; | ||
} else { | ||
rank = card[0]; | ||
} | ||
if ((card.length > 3) || (card.length === 3 && !(card[0] === "1" && card[1] === "0" && isNaN(card[2])))) | ||
return "Invalid card rank"; | ||
else if (rank === "A") return 11; | ||
else if (rank === "K" || rank === "Q" || rank === "J" ) return 10; | ||
else if (Number(rank) >= 2 && Number(rank) <= 10) return Number(rank); | ||
|
||
} | ||
|
||
// You need to write assertions for your function to check it works in different cases | ||
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. Could you add this test case & see what it returns?
|
||
// we're going to use this helper function to make our assertions easier to read | ||
|
@@ -33,12 +44,15 @@ assertEquals(aceofSpades, 11); | |
// When the function is called with such a card, | ||
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). | ||
const fiveofHearts = getCardValue("5♥"); | ||
assertEquals(fiveofHearts, 5); | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
|
||
// 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 QueenofDiamonds = getCardValue("Q♦"); | ||
assertEquals(QueenofDiamonds, 10); | ||
|
||
// Handle Ace (A): | ||
// Given a card with a rank of "A", | ||
|
@@ -49,3 +63,9 @@ const fiveofHearts = getCardValue("5♥"); | |
// Given a card with an invalid rank (neither a number nor a recognized face card), | ||
// When the function is called with such a card, | ||
// Then it should throw an error indicating "Invalid card rank." | ||
const seventySevenofDiamonds = getCardValue("77♦"); | ||
assertEquals(seventySevenofDiamonds, "Invalid card rank"); | ||
|
||
//Handle cards with value of ten | ||
const tenOfHearts = getCardValue("10♥"); | ||
assertEquals(tenOfHearts, 10); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (numerator === 0 && denominator === 0) return "put numbers above and below"; | ||
//else if (numerator === 0) return "input non-zero above"; -- not needed as numerator can be zero | ||
else if (denominator === 0) return "input non-zero below"; | ||
else if (numerator < denominator) return true; | ||
else if (numerator > denominator) return false; | ||
else if (numerator === denominator) return false; | ||
//else if (numerator === 0 && denominator === 0) return "put numbers above and below"; | ||
// the above line of code did not work here it had to go to the top as it is a most specific case considering our function. | ||
} | ||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,27 @@ test("should return true for a proper fraction", () => { | |
expect(isProperFraction(2, 3)).toEqual(true); | ||
}); | ||
|
||
//we can write the functions that we expect to out true using .toBeTruthy() | ||
test("should return true for a proper fraction", () => { | ||
expect(isProperFraction(7, 11)).toBeTruthy(); | ||
}); | ||
|
||
// Case 2: Identify Improper Fractions: | ||
test("should return false for an improper fraction", () => { | ||
expect(isProperFraction(7, 3)).toEqual(false); | ||
}); | ||
|
||
// Case 3: Identify Negative Fractions: | ||
test("should return true for a negative fraction", () => { | ||
expect(isProperFraction(-2, 3)).toEqual(true); | ||
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. Stretch question: this library also has |
||
}); | ||
|
||
//This type of case that outputs true can also use .toBeTruthy() | ||
test("should return true for a negative fraction", () => { | ||
expect(isProperFraction(-4, 9)).toBeTruthy(); | ||
}); | ||
|
||
// Case 4: Identify Equal Numerator and Denominator: | ||
test("should return false if numerator and denominator are equal", () => { | ||
expect(isProperFraction(3, 3)).toEqual(false); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
let rank; | ||
if (card.startsWith("10")) { | ||
rank = "10"; | ||
} else { | ||
rank = card[0]; | ||
} | ||
if ((card.length > 3) || (card.length === 3 && !card.startsWith("10")) || (isNaN(rank) && !"AKQJ".includes(rank)) || rank === "0") | ||
return "Invalid card rank"; | ||
else if (rank === "A") return 11; | ||
else if (rank === "K" || rank === "Q" || rank === "J" ) return 10; | ||
else if (Number(rank) >= 2 && Number(rank) <= 10) return Number(rank); | ||
} | ||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,43 @@ test("should return 11 for Ace of Spades", () => { | |
}); | ||
|
||
// Case 2: Handle Number Cards (2-10): | ||
test("should return number value for card 2-10", () => { | ||
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. What would you expect for the input |
||
const sevenofHearts = getCardValue("7♥"); | ||
expect(sevenofHearts).toEqual(7); | ||
}); | ||
|
||
// Case 3: Handle Face Cards (J, Q, K): | ||
test(" should return 10 for JQK cards", () => { | ||
const kingofDiamonds = getCardValue("K♦"); | ||
expect(kingofDiamonds).toEqual(10); | ||
}); | ||
|
||
// Case 4: Handle Ace (A): | ||
test(" should return 11 for Ace cards", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
|
||
// Case 5: Handle Invalid Cards: | ||
test(" should return a message that card is not valid", () => { | ||
const ninetynineLove = getCardValue("99♥"); | ||
expect(ninetynineLove).toEqual("Invalid card rank"); | ||
}); | ||
|
||
// Case 6: Handle Ten Cards: | ||
test(" should return 10", () => { | ||
const tenOfHearts = getCardValue("10♥"); | ||
expect(tenOfHearts).toEqual(10); | ||
}); | ||
|
||
//Case 7: more invalid cards: | ||
test(" should return a message that card not valid", () => { | ||
const zeroOfHearts = getCardValue("0♥"); | ||
expect(zeroOfHearts).toEqual("Invalid card rank"); | ||
}); | ||
|
||
//Case 8: more invalid cards: | ||
test(" should return a message that card not valid", () => { | ||
const xOfHearts = getCardValue("X♥"); | ||
expect(xOfHearts).toEqual("Invalid card 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.
Stretch: if we re-order these
if
statements, could we reduce the number of conditions we need to check? Each condition adds complexity to our codeFor example, if I check
numerator === 0
first, will I need to checknumerator !== 0
later?