-
-
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 9 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,7 +8,14 @@ | |
// write one test at a time, and make it pass, build your solution up methodically | ||
|
||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
if (numerator === 0 && denominator === 0) return "put numbers above and below"; | ||
else if (numerator < denominator && numerator !== 0) return true; | ||
else if (numerator > denominator && denominator !== 0) return false; | ||
else if (numerator === denominator) return false; | ||
else if (numerator === 0) return "input non-zero above"; | ||
else if (denominator === 0) return "input non-zero below"; | ||
//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. | ||
} | ||
|
||
// here's our helper again | ||
|
@@ -40,14 +47,37 @@ assertEquals(improperFraction, false); | |
// 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); | ||
|
||
// Stretch: | ||
// What other scenarios could you test for? | ||
// We could test for if the numerator is zero | ||
|
||
// Zero Numerator check: | ||
// Input: numerator = 0, denominator = 3 | ||
// target output: true | ||
// Explanation: Even though this gives a zero value it still returns true | ||
//so we expect it to be true | ||
const zeroNumeratorFraction = isProperFraction(0, 3); | ||
assertEquals(zeroNumeratorFraction, "input non-zero above"); | ||
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. Would we expect |
||
|
||
// Zero Denominator check: | ||
// Input: numerator = 3, denominator = 0 | ||
// target output: undefined | ||
// Explanation: This gives an undefined value. | ||
const zeroDenominatorFraction = isProperFraction(3, 0); | ||
assertEquals(zeroDenominatorFraction, "input non-zero below"); | ||
|
||
// Zero Numerator and Zero Denominator check: | ||
// Input: numerator = 0, denominator = 0 | ||
// target output: false | ||
// Explanation: This actually outputs false even though the operation is practically impossible. | ||
const zeroZeroFraction = isProperFraction(0, 0); | ||
assertEquals(zeroZeroFraction, "put numbers above and below"); | ||
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. Does the numerator need to be non-zero? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,15 @@ | |
// 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; | ||
rank = card[0] | ||
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 is missing a declaration - what do we need to put in front of this variable assignment? |
||
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); | ||
//else return "Invalid card rank."; | ||
/* else if (card.length > 3 && !(card[0] === "1" && card[1] === "0" && isNaN(card[2]))) | ||
return "Invalid card 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?
|
||
|
@@ -33,12 +41,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 +60,5 @@ 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"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
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 < denominator && numerator !== 0) return true; | ||
else if (numerator > denominator && denominator !== 0) return false; | ||
else if (numerator === denominator) return false; | ||
else if (numerator === 0) return "input non-zero above"; | ||
else if (denominator === 0) return "input non-zero below"; | ||
} | ||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,17 @@ test("should return true for a proper fraction", () => { | |
}); | ||
|
||
// 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 |
||
}); | ||
|
||
|
||
// 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,9 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
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); | ||
} | ||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,25 @@ 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"); | ||
}); |
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?