-
-
Notifications
You must be signed in to change notification settings - Fork 337
Sheffield | ITP-Jan-26 | Hayriye Saricicek | Sprint 3 | Implement and rewrite tests #1230
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
61d68a8
70c2e4f
a979c91
73862c5
44c463c
e3943d2
bddc0bb
e235397
97db101
de2ab2f
002f8fe
d074c28
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 |
|---|---|---|
|
|
@@ -2,19 +2,48 @@ | |
| // We will use the same function, but write tests for it using Jest in this file. | ||
| const getAngleType = require("../implement/1-get-angle-type"); | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all cases/outcomes, | ||
| // including boundary and invalid cases. | ||
|
|
||
| // 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"); | ||
| expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
| }); | ||
|
|
||
| // Case 2: Right angle | ||
| test(`should return "Right angle" when (angle === 90)`, () => { | ||
| // Test various right angles, including boundary cases | ||
| expect(getAngleType(90)).toEqual("Right angle"); | ||
| expect(getAngleType(89)).toEqual("Acute angle"); | ||
| expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
| }); | ||
|
|
||
| // Case 3: Obtuse angles | ||
| test(`should return "Obtuse angle" when (angle > 90) && when (angle < 180)`, () => { | ||
| // Test various obtuse angles, including boundary cases | ||
| expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(150)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(189)).toEqual("Reflex angle"); | ||
| }); | ||
|
|
||
| // Case 4: Straight angle | ||
| test(`should return "Straight angle" when (angle === 180)`, () => { | ||
| // Test various straight angles, including boundary cases | ||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
| expect(getAngleType(179)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(181)).toEqual("Reflex angle"); | ||
| }); | ||
|
|
||
| // Case 5: Reflex angles | ||
| test(`should return "Reflex angle" when (angle > 180)`, () => { | ||
| 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 || angle >= 360)`, () => { | ||
| expect(getAngleType(-1)).toEqual("Invalid angle"); | ||
| expect(getAngleType(360)).toEqual("Invalid angle"); | ||
| }); | ||
|
Comment on lines
+46
to
+49
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 is great that you tested one of the boundary cases. Why not test also the other one? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,27 @@ | |
| // We will use the same function, but write tests for it using Jest in this file. | ||
| const isProperFraction = require("../implement/2-is-proper-fraction"); | ||
|
|
||
| // 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 false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 2)).toEqual(true); | ||
| }); | ||
|
|
||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(2, 2)).toEqual(false); | ||
| }); | ||
|
|
||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(2, 1)).toEqual(false); | ||
| }); | ||
|
|
||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(0, 0)).toEqual(false); | ||
| }); | ||
|
|
||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(0, 1)).toEqual(true); | ||
| }); | ||
|
Comment on lines
+10
to
+28
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. These test descriptions do not quite match the tests being carried out. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,54 @@ | ||
| // This statement loads the getCardValue function you wrote in the implement directory. | ||
| // We will use the same function, but write tests for it using Jest in this file. | ||
| const { createTestScheduler } = require("jest"); | ||
| const getCardValue = require("../implement/3-get-card-value"); | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all possible outcomes. | ||
|
|
||
| // Case 1: Ace (A) | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| }); | ||
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
| // Number Cards (2-10) | ||
| // Face Cards (J, Q, K) | ||
| // Invalid Cards | ||
| // Case 2: Face Cards (J, Q, K) | ||
| test(`Should return 10 when given a Jack card`, () => { | ||
| expect(getCardValue("J♥")).toEqual(10); | ||
| }); | ||
|
|
||
| // 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 | ||
| test(`Should return 10 when given a Queen card`, () => { | ||
| expect(getCardValue("Q♦")).toEqual(10); | ||
| }); | ||
|
|
||
| test(`Should return 10 when given a King card`, () => { | ||
| expect(getCardValue("K♣")).toEqual(10); | ||
| }); | ||
|
|
||
| // Case 3: Number Cards (2-10) | ||
| test(`Should return 2 when given a 2 card`, () => { | ||
| expect(getCardValue("2♠")).toEqual(2); | ||
| }); | ||
|
|
||
| test(`Should return 10 when given a 10 card`, () => { | ||
| expect(getCardValue("10♥")).toEqual(10); | ||
| }); | ||
|
Comment on lines
+25
to
+31
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. When preparing tests, we should ensure the tests cover all possible cases. If we specify a test for individual card, we will need about 53 tests to cover all possible cases. Instead, we could consider classifying all possible values into different categories, and then within each category we test some samples. For example, one possible category for Can you practice preparing tests in this fashion? |
||
|
|
||
| // Case 4: Invalid Cards | ||
| test(`Should throw an error when given an invalid card`, () => { | ||
| expect(() => getCardValue("♠J")).toThrow(); | ||
| }); | ||
|
|
||
| test(`Should throw an error when given an invalid card`, () => { | ||
| expect(() => getCardValue("invalid")).toThrow(); | ||
| }); | ||
|
|
||
| test(`Should throw an error when given an invalid card`, () => { | ||
| expect(() => getCardValue("12♠")).toThrow(); | ||
| }); | ||
|
|
||
| test(`Should throw an error when given an invalid card`, () => { | ||
| expect(() => getCardValue("1")).toThrow(); | ||
| }); | ||
|
|
||
| // when I tested with test(`Should throw an error when given an invalid card`, () => { | ||
| // expect(() => getCardValue("22")).toThrow(); it did not throw an error because 22 passes the | ||
| // test of first number between and 9 and being 2 characters long, | ||
| // but it is not a valid card because the second character is not a valid suite. | ||
| // The second character is not checked. | ||
This file was deleted.
This file was deleted.
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.
These are all good advice and you should pay attention to them. :)