-
-
Notifications
You must be signed in to change notification settings - Fork 391
Manchester | 26-ITP-May | Yee Man Tsang | Sprint 3 | 1-implement-and-rewrite-tests #1496
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 all commits
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 |
|---|---|---|
|
|
@@ -11,7 +11,11 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| // TODO: Implement this function | ||
| if (numerator < denominator){ | ||
| return true; | ||
| }else{ | ||
| return false; | ||
| } | ||
|
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. I think there's a nice refactor we could do here... given that |
||
| } | ||
|
|
||
| // The line below allows us to load the isProperFraction function into tests in other files. | ||
|
|
@@ -31,3 +35,8 @@ function assertEquals(actualOutput, targetOutput) { | |
|
|
||
| // Example: 1/2 is a proper fraction | ||
| assertEquals(isProperFraction(1, 2), true); | ||
| assertEquals(isProperFraction(2, 3), true); | ||
| assertEquals(isProperFraction(499, 500), true); | ||
| assertEquals(isProperFraction(5, 2), false); | ||
| assertEquals(isProperFraction(5, 5), false); | ||
| assertEquals(isProperFraction(1, 0), false); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,35 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| const number = card.slice(0, -1); | ||
| const suit = card.slice(-1); | ||
| //console.log(`number is ${number}`); | ||
| //console.log(typeof suit); | ||
| //console.log(suit); | ||
|
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. Perfectly valid to use |
||
| if (suit == "♠" || suit == "♥" || suit == "♦" || suit == "♣"){ | ||
| switch (number) { | ||
| case "A": | ||
| return 11; | ||
| case "J": | ||
| case "Q": | ||
| case "K": | ||
| return 10; | ||
| case "2": | ||
| case "3": | ||
| case "4": | ||
| case "5": | ||
| case "6": | ||
| case "7": | ||
| case "8": | ||
| case "9": | ||
| return Number(number); | ||
| default: | ||
| return "invalid"; | ||
|
|
||
| } | ||
| }else{ | ||
| return "invalid"; | ||
| } | ||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
|
|
@@ -39,7 +67,19 @@ function assertEquals(actualOutput, targetOutput) { | |
|
|
||
| // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. | ||
| // Examples: | ||
| assertEquals(getCardValue("9♠"), 9); | ||
| assertEquals(getCardValue("A♠"), 11); | ||
| assertEquals(getCardValue("A♥"), 11); | ||
| assertEquals(getCardValue("J♦"), 10); | ||
| assertEquals(getCardValue("Q♦"), 10); | ||
| assertEquals(getCardValue("K♦"), 10); | ||
| assertEquals(getCardValue("2♣"), 2); | ||
| assertEquals(getCardValue("3♣"), 3); | ||
| assertEquals(getCardValue("4♦"), 4); | ||
| assertEquals(getCardValue("5♦"), 5); | ||
| assertEquals(getCardValue("6♦"), 6); | ||
| assertEquals(getCardValue("7♦"), 7); | ||
| assertEquals(getCardValue("8♣"), 8); | ||
| assertEquals(getCardValue("9♣"), 9); | ||
|
|
||
| // Handling invalid cards | ||
| try { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,38 @@ const getCardValue = require("../implement/3-get-card-value"); | |
| // Case 1: Ace (A) | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| expect(getCardValue("A♦")).toEqual(11); | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| }); | ||
|
|
||
| // Case 2: Face cards Jack, Queen, King (J,Q,K) | ||
| test(`Should return 10 when given a face card`, () => { | ||
| expect(getCardValue("J♠")).toEqual(10); | ||
| expect(getCardValue("J♦")).toEqual(10); | ||
| expect(getCardValue("Q♣")).toEqual(10); | ||
| expect(getCardValue("K♥")).toEqual(10); | ||
| }); | ||
|
|
||
| // Case 3: Number cards 2-10 (2,3,4,5,6,7,8,9) | ||
| test(`Should return the card value when given a number card`, () => { | ||
| expect(getCardValue("2♠")).toEqual(2); | ||
| expect(getCardValue("3♦")).toEqual(3); | ||
| expect(getCardValue("4♣")).toEqual(4); | ||
| expect(getCardValue("5♥")).toEqual(5); | ||
| expect(getCardValue("6♠")).toEqual(6); | ||
| expect(getCardValue("7♦")).toEqual(7); | ||
| expect(getCardValue("8♣")).toEqual(8); | ||
| expect(getCardValue("9♥")).toEqual(9); | ||
| }); | ||
|
|
||
| // Case 4: Invalid card | ||
| test(`Should return 10 when given an ace card`, () => { | ||
|
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. I'm not sure this test description matches what the test is checking for! |
||
| expect(getCardValue("invalid")).toEqual("invalid"); | ||
| expect(getCardValue("♦")).toEqual("invalid"); | ||
| expect(getCardValue("4")).toEqual("invalid"); | ||
| expect(getCardValue("")).toEqual("invalid"); | ||
| expect(getCardValue("m")).toEqual("invalid"); | ||
| expect(getCardValue("300")).toEqual("invalid"); | ||
|
Comment on lines
+38
to
+41
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. In an earlier comment I asked you to consider some further invalid cases for testing. You've added some nice ones here but I think there's still one thing you haven't covered that is worth checking for. Once you've figured that out, it should be included in your Jest tests also! |
||
| }); | ||
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
|
|
||
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.
What's the difference between
==and===? Which one do you think is more appropriate here?