Repository navigation
London | 26-ITP-Sep | Sakiya Mayow | Sprint 2 | Implement and rewrite tests #1766
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
bb5cc54
1cb8be0
e870389
2d1d1e0
515b79a
c677fa3
51135c2
d486f1c
fb8b1f4
22ee2ed
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 |
|---|---|---|
|
|
@@ -24,5 +24,19 @@ | |
| // execute the code to ensure all tests pass. | ||
|
|
||
| export function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| if (typeof card !== "string" || !/^(A|[2-9]|10|J|Q|K)[♠♥♦♣]$/.test(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. Your program is correct, and no need to change anything. Just I would like to know more about your program design process:
Thank you for adding a reply to this comment. |
||
| throw new Error(`Expected a number followed by a suit, but got "${card}"`); | ||
| } | ||
|
|
||
| if (card.startsWith("A")) { | ||
| return 11; | ||
| } | ||
| if (card.startsWith("J") || card.startsWith("Q") || card.startsWith("K")) { | ||
| return 10; | ||
| } | ||
|
|
||
| const value = parseInt(card); | ||
| if (!isNaN(value)) { | ||
| return value; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,37 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; | |
|
|
||
| // 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" for 90 degrees`, () => { | ||
| expect(getAngleType(90)).toEqual("Right angle"); | ||
| }); | ||
|
|
||
| // Case 3: Obtuse angles | ||
| test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { | ||
| expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(120)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(179)).toEqual("Obtuse angle"); | ||
| }); | ||
|
|
||
| // Case 4: Straight angle | ||
| test(`should return "Straight angle" for 180 degrees`, () => { | ||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
| }); | ||
| // Case 5: Reflex angles | ||
| test(`should return "Reflex angle" when (180 < angle < 360)`, () => { | ||
| expect(getAngleType(181)).toEqual("Reflex angle"); | ||
| expect(getAngleType(270)).toEqual("Reflex angle"); | ||
| expect(getAngleType(359)).toEqual("Reflex angle"); | ||
| }); | ||
|
|
||
| // Case 6: Invalid angles | ||
| test(`should return "Invalid angle" when ( angle <= 0 or angle >= 360)`, () => { | ||
| expect(getAngleType(181)).toEqual("Reflex angle"); | ||
| expect(getAngleType(270)).toEqual("Reflex angle"); | ||
| expect(getAngleType(359)).toEqual("Reflex angle"); | ||
| }); | ||
|
Comment on lines
+37
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. This seems like the duplicate of the Case 5 tests above. Please fix it, thank you. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,23 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js"; | |
|
|
||
| // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. | ||
|
|
||
| // Special case: numerator is zero | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| test("should return true for a proper fraction", () => { | ||
| expect(isProperFraction(1, 2)).toBe(true); | ||
| expect(isProperFraction(3, 5)).toBe(true); | ||
| }); | ||
|
|
||
| test("should return false when numerator equals denominator", () => { | ||
| expect(isProperFraction(2, 2)).toBe(false); | ||
| }); | ||
|
|
||
| test("should return false when numerator is greater than denominator", () => { | ||
| expect(isProperFraction(3, 2)).toBe(false); | ||
| }); | ||
|
|
||
| test("should return true when numerator is zero", () => { | ||
| expect(isProperFraction(0, 2)).toBe(true); | ||
| }); | ||
|
|
||
| test("should return false when denominator is zero", () => { | ||
| expect(isProperFraction(1, 0)).toBe(false); | ||
|
Comment on lines
+18
to
+23
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 only considering positive proper fraction, these two cases should both return false. Depends on how you fix https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/pull/1766/changes#r4423374448 , one of these test cases should be fixed as well. Thank you. |
||
| }); | ||
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.
Although there are different definitions for negative proper fractions (one definition returns true and another returns false) and I would treat both definitions as correct solution, these two cases should be consistently returned the same result regardless of which definition to follow. So please fix the test cases (and the program if necessary).
Also, how about both numerator and denominator are negative numbers (e.g. -1/-2 and -2/-1) ? Please add them to the test suite as well. Thank you.