-
-
Notifications
You must be signed in to change notification settings - Fork 337
Birmingham | ITP-Jan-26 | Ayodeji Ayorinde | Sprint 3| 1-implement-and-rewrite-tests #1215
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 |
|---|---|---|
|
|
@@ -23,6 +23,16 @@ | |
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| rankCard = card.slice(0, 1); | ||
| if (rankCard === "A") { | ||
| return 11; | ||
| } else if (rankCard === "J" || rankCard === "Q" || rankCard === "K") { | ||
| return 10; | ||
| } else if (+rankCard >= 2 && +rankCard <= 10) { | ||
| return +rankCard; | ||
| } else { | ||
| return rankCard.toThrow(); | ||
| } | ||
| } | ||
|
Comment on lines
24
to
36
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.
|
||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
|
|
@@ -47,6 +57,6 @@ try { | |
|
|
||
| // This line will not be reached if an error is thrown as expected | ||
| console.error("Error was not thrown for invalid card"); | ||
| } catch (e) {} | ||
| } catch (e) { } | ||
|
|
||
| // What other invalid card cases can you think of? | ||
| // What other invalid card cases can you think of? "13♠" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { | |
| }); | ||
|
|
||
| // Case 2: Right angle | ||
| test(`should return "Right angle" when (angle === 90)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(90)).toEqual("Right angle"); | ||
| }); | ||
| // Case 3: Obtuse angles | ||
| test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(145)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(179)).toEqual("Obtuse angle"); | ||
| }); | ||
| // Case 4: Straight angle | ||
| test(`should return "Straight angle" when (angle === 180)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
| }); | ||
| // Case 5: Reflex angles | ||
| test(`should return "Reflex angle" when (180 < angle < 360)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(181)).toEqual("Reflex angle"); | ||
| expect(getAngleType(245)).toEqual("Reflex angle"); | ||
| expect(getAngleType(359)).toEqual("Reflex angle"); | ||
| }); | ||
| // Case 6: Invalid angles | ||
| test(`should return "Invalid angle" when (angle > 360)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(90)).toEqual("Invalid angle"); | ||
| }); | ||
|
Comment on lines
+41
to
+44
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,19 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); | |
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
| // Special case: positives | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 7)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: negatives | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, -7)).toEqual(false); | ||
| }); | ||
|
Comment on lines
+14
to
+21
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. The description of the tests do not match the tests being carried out. |
||
|
|
||
| // Special case: zero | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(10, 0)).toEqual(false); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,34 @@ test(`Should return 11 when given an ace card`, () => { | |
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
| // Number Cards (2-10) | ||
|
|
||
| test("Should return 2–10 for their respective card values", () => { | ||
| const cards = ["2", "3", "4", "5", "6", "7", "8", "9", "10"]; | ||
|
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. A valid card should also have a valid suit character. |
||
| cards.forEach(card => { | ||
| expect(getCardValue(card)).toEqual(Number(card)); | ||
| }); | ||
| }); | ||
|
|
||
| // Face Cards (J, Q, K) | ||
| test("Should return 2–10 for their respective card values", () => { | ||
| const cards = ["J", "Q", "K"]; | ||
| cards.forEach(card => { | ||
| expect(getCardValue(card)).toEqual(10); | ||
| }); | ||
| }); | ||
|
|
||
| // Invalid Cards | ||
|
|
||
| test("Should return invalid for their respective card values", () => { | ||
| const cards = ["L", "M", "N"]; | ||
| cards.forEach(card => { | ||
| expect(getCardValue(card)).toEqual(Number("Invalid")); | ||
|
|
||
| }); | ||
| }); | ||
|
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.
|
||
|
|
||
|
|
||
|
|
||
| // To learn how to test whether a function throws an error as expected in Jest, | ||
| // please refer to the Jest documentation: | ||
| // https://jestjs.io/docs/expect#tothrowerror | ||
|
|
||
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.
Can you lookup if -1/-2, 1/-2, -1/2, -1/0 are considered proper fractions, and then update
your implementation and tests accordingly?