-
-
Notifications
You must be signed in to change notification settings - Fork 395
Manchester | 26-ITP-May | Szidonia Bodo | Sprint 3 | Implement and review test #1520
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
f0ca3d7
5ad372d
5c0d472
b28e30e
241ef30
f0b6faa
10d37a8
1230568
26a0fed
9c84e3d
cb7b6ef
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 |
|---|---|---|
|
|
@@ -22,7 +22,16 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| const removeSuit = card.slice(0, -1); | ||
| if (removeSuit === "A") { | ||
| return 11; | ||
| } else if (removeSuit === "J" || removeSuit === "Q" ||removeSuit === "K") { | ||
| return 10; | ||
| } else if (removeSuit > 1 && removeSuit < 11) { | ||
| return Number(removeSuit); | ||
| } else { | ||
| throw new Error("Error") | ||
| } | ||
|
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. A great solution, very readable 👌 Just one point, you've declared |
||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
|
|
@@ -40,15 +49,29 @@ 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("J♦"), 10); | ||
| assertEquals(getCardValue("7♥"), 7); | ||
| assertEquals(getCardValue("A♥"), 11); | ||
| assertEquals(getCardValue("8♥"), 8); | ||
|
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. When writing a test suite, we want to try and cover all possible "behaviours" of our function. Here I can see you've covered:
Looking at that list, what have you not covered? |
||
| assertEquals(getCardValue("Q♠"), 10); | ||
| assertEquals(getCardValue("K♦"), 10); | ||
|
|
||
| // Handling invalid cards | ||
| try { | ||
| getCardValue("invalid"); | ||
|
|
||
| // This line will not be reached if an error is thrown as expected | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
|
|
||
| // What other invalid card cases can you think of? | ||
| try { | ||
| getCardValue("15♥"); | ||
| // This line will not be reached if an error is thrown as expected | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,19 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); | |
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| }); | ||
| test(`should return true when denominator is smaller or equal to the numerator`,() =>{ | ||
| expect(isProperFraction(2, 4)).toEqual(true); | ||
| expect(isProperFraction(3, 3)).toEqual(true); | ||
| expect(isProperFraction(5, 10)).toEqual(true); | ||
| expect(isProperFraction(2, 2)).toEqual(true); | ||
| }); | ||
|
|
||
| test(`should return false when denominator is bigger than the numerator`, () => { | ||
| expect(isProperFraction(12, 4)).toEqual(false); | ||
| }); | ||
|
|
||
| test("should return false when the numerator or denominator is not a positive number", () => { | ||
| expect(isProperFraction(5, -2)).toEqual(false); | ||
| expect(isProperFraction(-1, 0)).toEqual(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. This test case, which test does it belong in? What grouping of behaviours does it fall into? |
||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
If you were to check the case of
isProperFraction(-1, 2), what do we want to see as the answer? And would that test pass?(Things get a little awkwardly mathsy with negative fractions, I recognise)