-
-
Notifications
You must be signed in to change notification settings - Fork 303
LONDON-JAN-25 | ANDREI FILIPPOV | Module-Structuring-and-Testing-Data | WEEK 3 #309
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
Changes from all commits
30382f5
b4796c5
4214ebf
fdd426e
0efcab3
0938167
dd11749
412a244
458b508
822c3aa
4d5092e
8d1fafd
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 |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| node_modules | ||
| .DS_Store | ||
| .vscode | ||
| **/.DS_Store | ||
| **/.DS_Store | ||
| package-lock.json | ||
| Sprint-3/3-mandatory-practice/implement/fffff.test.js |
| 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) { | ||
| if (rank === "A") return 11; | ||
| rank = card.slice(0, -1); | ||
| if (rank === "A") return 11; | ||
| else if (rank === "J" || rank === "Q" || rank === "K") return 10; | ||
| else if ( | ||
| Number.isInteger(+(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. Nice finds. Something you might be able to play with if you have time. Do you need both checks? Trial and error and find out :)
Author
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. Oh, thank you for the remark. Testing showed that
So |
||
| Number(rank) < 10 && | ||
| Number(rank) > 1 | ||
| ) | ||
| return Number(rank); | ||
| else return "Invalid card rank."; | ||
| } | ||
|
|
||
| // You need to write assertions for your function to check it works in different cases | ||
|
|
@@ -25,27 +34,38 @@ function assertEquals(actualOutput, targetOutput) { | |
| // Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A), | ||
| // When the function getCardValue is called with this card string as input, | ||
| // Then it should return the numerical card value | ||
| const aceofSpades = getCardValue("A♠"); | ||
| assertEquals(aceofSpades, 11); | ||
|
|
||
| // Handle Number Cards (2-10): | ||
| // Given a card with a rank between "2" and "9", | ||
| // 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♥"); | ||
| // ====> write your test here, and then add a line to pass the test in the function above | ||
| const fiveOfHearts = getCardValue("5♥"); | ||
| 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 jackOfSpades = getCardValue("J♠"); | ||
| assertEquals(jackOfSpades, 10); | ||
|
|
||
| // Handle Ace (A): | ||
| // Given a card with a rank of "A", | ||
| // When the function is called with an Ace, | ||
| // Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. | ||
| const aceOfSpades = getCardValue("A♠"); | ||
| assertEquals(aceOfSpades, 11); | ||
|
|
||
| // Handle Invalid Cards: | ||
| // 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 invalid = getCardValue("five of hearts"); | ||
|
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 should happens if I give you the input of "5.123♥"? Is that reflected in the program?
Author
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. Thank you for pointing this out! I hadn’t considered that case. I resolved it by adding an |
||
| assertEquals(invalid, "Invalid card rank."); | ||
|
|
||
| const invalidNumber = getCardValue("12♥"); | ||
| assertEquals(invalidNumber, "Invalid card rank."); | ||
|
|
||
| const FloatNumber = getCardValue("5.123♥"); | ||
| assertEquals(FloatNumber, "Invalid card rank."); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| function isProperFraction(numerator, denominator) { | ||
| if (numerator < denominator) return true; | ||
| // add your completed function from key-implement here | ||
| if (Math.abs(numerator) < Math.abs(denominator)) return true; | ||
| else if (Math.abs(numerator) > Math.abs(denominator)) return false; | ||
| else if (Math.abs(numerator) == Math.abs(denominator)) return false; | ||
| } | ||
|
|
||
| module.exports = isProperFraction; | ||
| module.exports = isProperFraction; |
| 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; | ||
| rank = card.slice(0, -1); | ||
| if (rank === "A") return 11; | ||
| else if (rank === "J" || rank === "Q" || rank === "K") return 10; | ||
| else if ( | ||
| typeof Number(rank) == "number" && | ||
| Number(rank) > 1 && | ||
| Number(rank) < 10 | ||
| ) | ||
| return Number(rank); | ||
| else return "Invalid card rank."; | ||
| } | ||
| module.exports = getCardValue; | ||
|
|
||
| module.exports = getCardValue; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,25 @@ | ||
| const getCardValue = require("./3-get-card-value"); | ||
|
|
||
| test("should return 11 for Ace of Spades", () => { | ||
| const aceofSpades = getCardValue("A♠"); | ||
| expect(aceofSpades).toEqual(11); | ||
| }); | ||
| const aceofSpades = getCardValue("A♠"); | ||
| expect(aceofSpades).toEqual(11); | ||
| }); | ||
|
|
||
| // Case 2: Handle Number Cards (2-10): | ||
|
|
||
| test("should return number for 9 of Spades", () => { | ||
| const aceofSpades = getCardValue("9♠"); | ||
| expect(aceofSpades).toEqual(9); | ||
| }); | ||
| // Case 3: Handle Face Cards (J, Q, K): | ||
| test("should return 10 for J of Spades", () => { | ||
| const aceofSpades = getCardValue("J♠"); | ||
| expect(aceofSpades).toEqual(10); | ||
| }); | ||
| // Case 4: Handle Ace (A): | ||
|
|
||
| // Case 5: Handle Invalid Cards: | ||
| test("should return 'Invalid card rank.' for invalid input", () => { | ||
| const aceofSpades = getCardValue("6478♠"); | ||
| expect(aceofSpades).toEqual("Invalid card rank."); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| } | ||
| charList = stringOfCharacters.split(""); | ||
| count = charList.filter((char) => char == findCharacter); | ||
|
|
||
| module.exports = countChar; | ||
| return count.length; | ||
| } | ||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| numToString = String(num); | ||
| lastDigit = numToString[numToString.length - 1] | ||
| if (lastDigit == 1 && num != 11) { | ||
| return `${num}st`; | ||
| } else if (lastDigit == 2 && num != 12) { | ||
| return `${num}nd`; | ||
| } else if (lastDigit == 3 && num != 13) { | ||
| return `${num}rd`; | ||
| } else { | ||
| return `${num}th`; | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str, count) { | ||
| if (count >= 0) { | ||
| return str.repeat(count); | ||
| } else if (count < 0) { | ||
| return "invalid number"; | ||
| } else { | ||
| return "invalid input"; | ||
| } | ||
| } | ||
|
|
||
| module.exports = repeat; | ||
| module.exports = repeat; |
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.
Good scenario to test for!