-
-
Notifications
You must be signed in to change notification settings - Fork 391
Manchester | 26-ITP-May |Abdu Hassen | Sprint 3 |implement and rewrite tests #1486
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,13 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| // TODO: Implement this function | ||
| if (Math.abs(numerator) < Math.abs(denominator)) { | ||
| return true; | ||
| } else if (denominator === 0) { | ||
| return false; | ||
| } else { | ||
| return false; | ||
| } | ||
|
Comment on lines
+16
to
+20
Contributor
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. Code on lines 16-20 could further be simplified. |
||
| } | ||
|
|
||
| // The line below allows us to load the isProperFraction function into tests in other files. | ||
|
|
@@ -31,3 +37,9 @@ function assertEquals(actualOutput, targetOutput) { | |
|
|
||
| // Example: 1/2 is a proper fraction | ||
| assertEquals(isProperFraction(1, 2), true); | ||
| assertEquals(isProperFraction(0, 0.2), true); | ||
| assertEquals(isProperFraction(2, 0), false); | ||
| assertEquals(isProperFraction(11, 8), false); | ||
| assertEquals(isProperFraction(0, 1), true); | ||
| assertEquals(isProperFraction(10, 25), true); | ||
| assertEquals(isProperFraction(0, 0), false); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,9 +22,39 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| const validRank = [ | ||
|
Contributor
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. It's common practice to use plural names for arrays. |
||
| "A", | ||
| "2", | ||
| "3", | ||
| "4", | ||
| "5", | ||
| "6", | ||
| "7", | ||
| "8", | ||
| "9", | ||
| "10", | ||
| "J", | ||
| "Q", | ||
| "K", | ||
| ]; | ||
| const validSuits = ["♠", "♣", "♦", "♥"]; | ||
| let rank = card.slice(0, -1); | ||
| let suit = card.slice(-1); | ||
| if (!validSuits.includes(suit)) { | ||
| throw new Error("Invalid Cards"); | ||
| } | ||
| if (!validRank.includes(rank)) { | ||
| throw new Error("Invalid Cards"); | ||
| } | ||
| if (rank === "A") { | ||
| return 11; | ||
| } | ||
| if (["J", "Q", "K"].includes(rank)) { | ||
| return 10; | ||
| } else { | ||
| return Number(rank); | ||
| } | ||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
| // This will be useful in the "rewrite tests with jest" step. | ||
| module.exports = getCardValue; | ||
|
|
@@ -40,7 +70,13 @@ 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("K♦"), 10); | ||
| assertEquals(getCardValue("Q♦"), 10); | ||
| assertEquals(getCardValue("7♣"), 7); | ||
| assertEquals(getCardValue("10♦"), 10); | ||
| assertEquals(getCardValue("2♣"), 2); | ||
| // Handling invalid cards | ||
| try { | ||
| getCardValue("invalid"); | ||
|
|
@@ -52,3 +88,51 @@ try { | |
| } | ||
|
|
||
| // What other invalid card cases can you think of? | ||
| try { | ||
| getCardValue("1♥"); | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
| try { | ||
| getCardValue(" "); | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
| try { | ||
| getCardValue("Z♠"); | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
| try { | ||
| getCardValue("G♠"); | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
| try { | ||
| getCardValue("10X"); | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
| try { | ||
| getCardValue("B♠"); | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
| try { | ||
| getCardValue("♠"); | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
| try { | ||
| getCardValue("B♠♠"); | ||
| 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 |
|---|---|---|
|
|
@@ -14,7 +14,34 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { | |
| }); | ||
|
|
||
| // 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 angles" when (90 < angle < 180)`, () => { | ||
| expect(getAngleType(91)).toEqual("Obtuse angles"); | ||
| expect(getAngleType(179)).toEqual("Obtuse angles"); | ||
| expect(getAngleType(145)).toEqual("Obtuse angles"); | ||
| expect(getAngleType(92)).toEqual("Obtuse angles"); | ||
| expect(getAngleType(178)).toEqual("Obtuse angles"); | ||
| }); | ||
| // 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 angles" when (180 < angle < 360)`, () => { | ||
| expect(getAngleType(181)).toEqual("Reflex angles"); | ||
| expect(getAngleType(190)).toEqual("Reflex angles"); | ||
| expect(getAngleType(345)).toEqual("Reflex angles"); | ||
| expect(getAngleType(359)).toEqual("Reflex angles"); | ||
| expect(getAngleType(277)).toEqual("Reflex angles"); | ||
| }); | ||
| // Case 6: Invalid angles | ||
| test(`should return "Invalid angles" when (angle )`, () => { | ||
| expect(getAngleType(-60)).toEqual("Invalid angles"); | ||
| expect(getAngleType(450)).toEqual("Invalid angles"); | ||
| expect(getAngleType(-2)).toEqual("Invalid angles"); | ||
| expect(getAngleType(361)).toEqual("Invalid angles"); | ||
| expect(getAngleType(890)).toEqual("Invalid angles"); | ||
| }); | ||
|
Contributor
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.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,14 @@ 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 false when the denominator less nominator`, () => { | ||
| expect(isProperFraction(7, 2)).toEqual(false); | ||
| expect(isProperFraction(-17, -2)).toEqual(false); | ||
| expect(isProperFraction(0.5, 0.1)).toEqual(false); | ||
| }); | ||
| test(`should return true when denominator is greater than nominator`, () => { | ||
| expect(isProperFraction(2, 8)).toEqual(true); | ||
|
Comment on lines
+11
to
+17
Contributor
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.
Note: The correct term is numerator (not nominator). |
||
| expect(isProperFraction(-3, -10)).toEqual(true); | ||
| expect(isProperFraction(-3, 7)).toEqual(true); | ||
| expect(isProperFraction(8, 17)).toEqual(true); | ||
| }); | ||
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.
Should some in singular form and some in plural form?