-
-
Notifications
You must be signed in to change notification settings - Fork 397
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
e569ea9
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,7 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| // TODO: Implement this function | ||
| return numerator <= denominator && numerator > 0 | ||
| } | ||
|
|
||
| // The line below allows us to load the isProperFraction function into tests in other files. | ||
|
|
@@ -31,3 +31,10 @@ function assertEquals(actualOutput, targetOutput) { | |
|
|
||
| // Example: 1/2 is a proper fraction | ||
| assertEquals(isProperFraction(1, 2), true); | ||
| assertEquals(isProperFraction(0, 4), false); | ||
| assertEquals(isProperFraction(5, 5), true); | ||
| assertEquals(isProperFraction(-8, 2), false); | ||
| assertEquals(isProperFraction(4, 0), false); | ||
| assertEquals(isProperFraction(0, 0), false); | ||
| assertEquals(isProperFraction(-2, -2), 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. If you were to check the case of (Things get a little awkwardly mathsy with negative fractions, I recognise)
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. Since the function requires the numerator to be greater than 0, a negative numerator should return false. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,19 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| if (Number(card) < 1 || Number(card) > 11) { | ||
| throw new Error("Error"); | ||
| } | ||
| 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"); | ||
| } | ||
|
Liam310 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
|
|
@@ -40,15 +52,28 @@ 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?
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. I haven't covered Clubs (♣) or the other face cards (Q and K). Although they are handled by the same logic as Jacks, adding test cases for them would improve coverage and help catch any mistakes in those specific conditions. 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. Still looks like there's one suit we haven't covered yet 👀
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. Added the missing suit and new test cases. |
||
| 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 |
|---|---|---|
|
|
@@ -7,14 +7,34 @@ const getAngleType = require("../implement/1-get-angle-type"); | |
|
|
||
| // Case 1: Acute angles | ||
| test(`should return "Acute angle" when (0 < angle < 90)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(1)).toEqual("Acute angle"); | ||
| expect(getAngleType(45)).toEqual("Acute angle"); | ||
| expect(getAngleType(89)).toEqual("Acute angle"); | ||
| }); | ||
|
|
||
| // Case 2: Right angle | ||
| test(`should return "Right angle" when (angle = 90)`, () => { | ||
| expect(getAngleType(90)).toEqual("Right angle"); | ||
| }); | ||
| // Case 3: Obtuse angles | ||
| test(`should return "Obtuse angle" when (angle < 180, angle > 90)`, () => { | ||
| expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(179)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(99)).toEqual("Obtuse angle"); | ||
| }); | ||
| // Case 4: Straight angle | ||
| test(`should return "Straight angle" when (angle = 180)`, () => { | ||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
| }); | ||
| // Case 5: Reflex angles | ||
| test(`should return "Reflex angle" when (angle < 360, angle > 180)`, () => { | ||
| expect(getAngleType(189)).toEqual("Reflex angle"); | ||
| expect(getAngleType(359)).toEqual("Reflex angle"); | ||
| expect(getAngleType(199)).toEqual("Reflex angle"); | ||
| }); | ||
| // Case 6: Invalid angles | ||
| test(`should return "Invalid angle" when (angle > 361, angle < 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. The test description doesn't match the cases are tested. Could you check the specification and check whether the boundary values are covered? |
||
| expect(getAngleType(505)).toEqual("Invalid angle"); | ||
| expect(getAngleType(0)).toEqual("Invalid angle"); | ||
| expect(getAngleType(699)).toEqual("Invalid angle"); | ||
| }); | ||
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.
A proper fraction is defined by:
|numerator| < |denominator|. What should returnisProperFraction(-2, 5)?