Repository navigation
London | 26-ITP-Sept | Fung Nin Lee | Sprint 2 | Implement and rewrite test #1678
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
ede90ec
c7e5979
6973f9e
855ddcc
56b9d32
f406580
70fd5b5
5b8ba78
09cd676
d8839f1
a0ed029
4c5ad3a
f0d67f2
5114047
c67d63d
ccb7a54
3334102
6f0f79f
ddb16d2
cd2a653
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 |
|---|---|---|
| @@ -1,12 +1,41 @@ | ||
| import { getAngleType } from "../implement/1-get-angle-type.js"; | ||
| import assert from "node:assert"; | ||
| import test from "node:test"; | ||
|
|
||
| import { getAngleType } from "../implement/1-get-angle-type.js"; | ||
|
|
||
| // TODO: Write tests to cover all cases, including boundary and invalid cases. | ||
| // Example: Identify Right Angles | ||
|
|
||
| test("Classifies right angles", () => { | ||
| const right = getAngleType(90); | ||
| assert.equal(right, "Right angle"); | ||
| test("Classifies acute angle", () => { | ||
| assert.equal(getAngleType(45), "Acute angle"); | ||
| }); | ||
|
|
||
| test("Classifies right angle", () => { | ||
| assert.equal(getAngleType(90), "Right angle"); | ||
| }); | ||
|
|
||
| test("Classifies obtuse angle", () => { | ||
| assert.equal(getAngleType(120), "Obtuse angle"); | ||
| }); | ||
|
|
||
| test("Classifies straight angle", () => { | ||
| assert.equal(getAngleType(180), "Straight angle"); | ||
| }); | ||
|
|
||
| test("Classifies reflex angle", () => { | ||
| assert.equal(getAngleType(200), "Reflex angle"); | ||
| }); | ||
|
|
||
| test("Classifies boundary and invalid angles", () => { | ||
| assert.equal(getAngleType(365), "invalid angle"); | ||
| assert.equal(getAngleType(-10), "invalid angle"); | ||
| assert.equal(getAngleType(0), "invalid angle"); | ||
| assert.equal(getAngleType(""), "invalid angle"); | ||
| assert.equal(getAngleType("angle"), "invalid angle"); | ||
| assert.equal(getAngleType("null"), "invalid angle"); | ||
| assert.equal(getAngleType(360), "invalid angle"); | ||
| assert.equal(getAngleType(181), "Reflex angle"); | ||
| assert.equal(getAngleType(91), "Obtuse angle"); | ||
| assert.equal(getAngleType(179), "Obtuse angle"); | ||
| assert.equal(getAngleType(89), "Acute angle"); | ||
| assert.equal(getAngleType(1), "Acute angle"); | ||
| }); | ||
|
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. how about numerator the same as denominator? how about zero in numerator or denominator? Should they return true or false? Please add them as well. Thank you. 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 is good that two new test cases about testing zero and negative have been added. How about numerator is equal to denominator? Please add it as well. Thank you. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,27 @@ | ||
| import { isProperFraction } from "../implement/2-is-proper-fraction.js"; | ||
| import assert from "node:assert"; | ||
| import test from "node:test"; | ||
|
|
||
| import { isProperFraction } from "../implement/2-is-proper-fraction.js"; | ||
|
|
||
| // TODO: Write tests to cover all cases. | ||
| // What combinations of numerators and denominators should you test? | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| // Example: 1/2 is a proper fraction | ||
| assert.equal(isProperFraction(1, 2), true); | ||
| }); | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(3, 2), false); | ||
| }); | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(0, 2), false); | ||
| }); | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(2, -5), false); | ||
| }); | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(1, 1), false); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,50 @@ | ||
| import { getCardValue } from "../implement/3-get-card-value.js"; | ||
| import assert from "node:assert"; | ||
| import test from "node:test"; | ||
|
|
||
| import { getCardValue } from "../implement/3-get-card-value.js"; | ||
|
|
||
| // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. | ||
|
|
||
| test("Valid single-digit card", () => { | ||
| test("Valid number card", () => { | ||
| assert.equal(getCardValue("9♠"), 9); | ||
| }); | ||
|
|
||
| test("Valid face card", () => { | ||
| assert.equal(getCardValue("K♦"), 10); | ||
| }); | ||
|
|
||
| test("Valid ace card", () => { | ||
| assert.equal(getCardValue("A♥"), 11); | ||
| }); | ||
|
|
||
| test("Arbitrary non-card string", () => { | ||
| assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error"); | ||
| assert.throws( | ||
| () => getCardValue("10"), | ||
| /Expected a number or face followed by a suit, but got "invalid"/, | ||
| "Expected clear error" | ||
| ); | ||
| assert.throws( | ||
| () => getCardValue("♥"), | ||
| /Expected a number or face followed by a suit, but got "invalid"/, | ||
| "Expected clear error" | ||
| ); | ||
| assert.throws( | ||
| () => getCardValue(""), | ||
| /Expected a number or face followed by a suit, but got "invalid"/, | ||
| "Expected clear error" | ||
| ); | ||
| assert.throws( | ||
| () => getCardValue("♥10"), | ||
| /Expected a number or face followed by a suit, but got "invalid"/, | ||
| "Expected clear error" | ||
| ); | ||
| }); | ||
|
|
||
| test("Invalid Rank", () => { | ||
| assert.throws( | ||
| () => getCardValue("12♥"), | ||
| /Valid rank: 2-10, A, J, Q, K only/, | ||
| "Expected clear error" | ||
| ); | ||
| }); | ||
|
|
||
| // TODO: What other invalid card cases can you think of? | ||
|
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. There should be more test cases for invalid card, how about a card with correct number/face without suit? how about a card with correct suit but no number/face? how about a card missing both number/face and suite? how about a card with suit followed by a number/face? would |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,36 @@ 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 angle" when (angle < 180 && angle > 90)`, () => { | ||
| 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" when (angle === 180)`, () => { | ||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
| }); | ||
|
|
||
| // Case 5: Reflex angles | ||
| test(`should return "Reflex angle" when (angle > 180 && angle < 360)`, () => { | ||
| expect(getAngleType(181)).toEqual("Reflex angle"); | ||
| expect(getAngleType(190)).toEqual("Reflex angle"); | ||
| expect(getAngleType(359)).toEqual("Reflex angle"); | ||
| }); | ||
|
|
||
| // Case 6: Invalid angles | ||
| test(`should return "Invalid value" when (angel >= 360 || angle <= 0 || angel = "")`, () => { | ||
| expect(getAngleType(-10)).toEqual("invalid angle"); | ||
| expect(getAngleType(365)).toEqual("invalid angle"); | ||
| expect(getAngleType(360)).toEqual("invalid angle"); | ||
| expect(getAngleType(0)).toEqual("invalid angle"); | ||
| expect(getAngleType()).toEqual("invalid angle"); | ||
| expect(getAngleType(null)).toEqual("invalid angle"); | ||
| expect(getAngleType("angle")).toEqual("invalid angle"); | ||
| }); | ||
|
Comment on lines
38
to
+47
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 two cases included here are general cases for invalid angles. There are two boundary cases as well. Can you think of them? If so, please add them as well. Thank you. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,10 +9,46 @@ 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 7 when given an seven card`, () => { | ||
| expect(getCardValue("7♥")).toEqual(7); | ||
| }); | ||
| // Face Cards (J, Q, K) | ||
| test(`Should return 10 when given J/Q/K`, () => { | ||
| expect(getCardValue("J♦")).toEqual(10); | ||
| expect(getCardValue("Q♣")).toEqual(10); | ||
| expect(getCardValue("K♠")).toEqual(10); | ||
| }); | ||
| // Invalid Cards | ||
| test(`Expected a number followed by a suit, but got invalid`, () => { | ||
| expect(() => getCardValue("10")).toThrow( | ||
| `Expected a number or face followed by a suit, but got "invalid"` | ||
| ); | ||
| }); | ||
|
|
||
| test(`Expected a number followed by a suit, but got invalid`, () => { | ||
| expect(() => getCardValue("")).toThrow( | ||
| `Expected a number or face followed by a suit, but got "invalid"` | ||
| ); | ||
| }); | ||
|
|
||
| test(`Expected a number followed by a suit, but got invalid`, () => { | ||
| expect(() => getCardValue("♥")).toThrow( | ||
| `Expected a number or face followed by a suit, but got "invalid"` | ||
| ); | ||
| }); | ||
|
|
||
| test(`Expected a number followed by a suit, but got invalid`, () => { | ||
| expect(() => getCardValue("♥10")).toThrow( | ||
| `Expected a number or face followed by a suit, but got "invalid"` | ||
| ); | ||
| }); | ||
|
|
||
| test(`Valid rank: 2-10, A, J, Q, K only`, () => { | ||
| expect(() => getCardValue("12♥")).toThrow( | ||
| `Valid rank: 2-10, A, J, Q, K only` | ||
| ); | ||
| }); | ||
|
Comment on lines
21
to
+50
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. Same as my another comment https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/pull/1678/changes#r4282076991 , please add more invalid card cases. Thank you. |
||
|
|
||
| // 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.
The two cases included here are general cases for invalid angles. There are two boundary cases as well. Can you think of them? If so, please add them as well. Thank you.