Repository navigation
London | 26-Sept | Hugh Mills | Sprint 2 | Implement and rewrite tests #1670
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
e8606f9
53621cd
5721c8b
5e692d8
b61b4b4
7ccf911
426aabb
1c3277f
c4786d8
707ac48
16f4f20
e3a8f17
ae7ef77
d4db679
9970ef6
2830bf3
c7af1dd
2fc4cd2
8662c14
6ae03b0
3727932
5d6c6ef
b155253
6f64f2e
b37a765
9770764
67f4dd7
77cf05b
3f42554
328f3c1
0cca1dc
2633baa
9cf8fc2
876923e
899e435
248c2e8
e6b8b53
23c6ee7
1236e2f
0845379
0569019
1a20c17
ba66435
cdd5f00
8b09c49
f78ab0d
7046cb7
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 |
|---|---|---|
|
|
@@ -6,7 +6,63 @@ 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", () => { | ||
| test("Basic proper fraction: Numerator < Denominator", () => { | ||
| // Example: 1/2 is a proper fraction | ||
| assert.equal(isProperFraction(1, 2), true); | ||
| }); | ||
|
|
||
| test("Improper fraction: Numerator = Denominator", () => { | ||
| assert.equal(isProperFraction(2, 2), false); | ||
| }); | ||
|
|
||
| test("Improper negative fraction: Numerator = Denominator", () => { | ||
| assert.equal(isProperFraction(-2, -2), false); | ||
| }); | ||
|
|
||
| test("improper fraction: Numerator > Denominator", () => { | ||
| assert.equal(isProperFraction(2, 1), false); | ||
| }); | ||
|
|
||
| test("Improper fraction: Denominator = 0", () => { | ||
| assert.equal(isProperFraction(1, 0), false); | ||
| }); | ||
|
|
||
| test("Improper fraction: Nominator = 0", () => { | ||
| assert.equal(isProperFraction(0, 2), false); | ||
| }); | ||
|
|
||
| test("Proper fraction with negative number: -Numerator < Denominator", () => { | ||
| assert.equal(isProperFraction(-1, 2), true); | ||
| }); | ||
|
|
||
| test("Proper fraction with negative number: Numerator < -Denominator", () => { | ||
| assert.equal(isProperFraction(1, -2), true); | ||
| }); | ||
|
|
||
| test("Improper fraction with negative number: -Numerator > Denominator", () => { | ||
| assert.equal(isProperFraction(-2, 1), false); | ||
| }); | ||
|
Comment on lines
+26
to
+44
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 3 more test suites related to either zero or negative values. Can you think of them? Please add them back. Thank you.
Author
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. I did not have 0 denominator, both numerator and denominator as negative and negative denominator 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. For positive numbers and zero, there is enough coverage.
For negative numbers, you have (-1, -2) and should still have one more case, what is it?
Author
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. Do you mean something like: -1,0 and 0,-1?
Author
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. I did add them into the tests... ahh... Both negative? >.< 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. Hmm... good try, just still not enough coverage. When we design test cases, we need to consider the context of the program. In your solution, you compared the absolute value of numerator and denominator. Therefore, the only possibilities are
As a result, there should be at least 12 (or 13 if also testing 0/0) test cases to cover all unique combinations. Please fix this file by adding the missed test cases. Thanks a lot. I hope you learnt the test case "design process", especially how to use minimum number of tests to provide maximum coverage. If you want to learn more about designing test cases, please feel free to book a mentored coding session with a volunteer. |
||
|
|
||
| test("Improper fraction with negative number: Numerator > -Denominator", () => { | ||
| assert.equal(isProperFraction(2, -1), false); | ||
| }); | ||
|
|
||
| test("Proper fraction with negative numbers: -Numerator < -Denominator", () => { | ||
| assert.equal(isProperFraction(-1, -2), true); | ||
| }); | ||
|
|
||
| test("Proper fraction with negative Numerator and Zero: -Numerator < 0", () => { | ||
| assert.equal(isProperFraction(-1, 0), false); | ||
| }); | ||
|
|
||
| test("Proper fraction with Zero and negative Denominator: 0 < -Denominator", () => { | ||
| assert.equal(isProperFraction(0, -2), false); | ||
| }); | ||
|
|
||
| test("Proper fraction with both being Zero", () => { | ||
| assert.equal(isProperFraction(0, 0), false); | ||
| }); | ||
|
|
||
| test("Improper fraction with negative numbers: -Numerator > -Denominator", () => { | ||
| assert.equal(isProperFraction(-3, -2), false); | ||
| }); | ||
|
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. Both valid and invalid cards, there should be more test cases covering various combinations. Please add them. Thank you. |
| 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 | ||
| // Case 4: Straight angle | ||
| test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { | ||
| expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(167)).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 "Right angle" when (180 < angle < 360)`, () => { | ||
| expect(getAngleType(186)).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 (0 > angle > 360)`, () => { | ||
| expect(getAngleType(361)).toEqual("Invalid angle"); | ||
| expect(getAngleType(396)).toEqual("Invalid angle"); | ||
| expect(getAngleType(-57)).toEqual("Invalid angle"); | ||
| }); | ||
|
Comment on lines
+35
to
+39
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 two boundary cases in this test suite. Can you think of them? Please add them. Thank you.
Author
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. Ah I see, I did not have Zero angle and Full angle. Was just looking at what was mentioned for the tests. 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. Just they should be counted as invalid (per question's definition). |
||
| // Case 7: Zero angles | ||
| test(`should return "Invalid angle" when (angle = 0)`, () => { | ||
| expect(getAngleType(0)).toEqual("Invalid angle"); | ||
| }); | ||
| // Case 8: Full angles | ||
| test(`should return "Invalid angle" when (angle = 360)`, () => { | ||
| expect(getAngleType(360)).toEqual("Invalid angle"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,107 @@ 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`, () => { | ||
| test(`should return false when numerator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: denominator is zero | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(0, 1)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: both are zero | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(0, 0)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: Basic proper fraction: Numerator < Denominator | ||
| test(`should return true when: Numerator < Denominator`, () => { | ||
| expect(isProperFraction(1, 2)).toEqual(true); | ||
| expect(isProperFraction(3, 6)).toEqual(true); | ||
| expect(isProperFraction(45, 60)).toEqual(true); | ||
| }); | ||
|
|
||
| // Special case: Basic proper negative fraction: -Numerator < Denominator | ||
| test(`should return true when: Numerator < Denominator`, () => { | ||
| expect(isProperFraction(-1, 2)).toEqual(true); | ||
| expect(isProperFraction(-3, 6)).toEqual(true); | ||
| expect(isProperFraction(-45, 60)).toEqual(true); | ||
| }); | ||
|
|
||
| // Special case: Basic proper negative fraction: Numerator < -Denominator | ||
| test(`should return true when: Numerator < Denominator`, () => { | ||
| expect(isProperFraction(1, -2)).toEqual(true); | ||
| expect(isProperFraction(3, -6)).toEqual(true); | ||
| expect(isProperFraction(45, -60)).toEqual(true); | ||
| }); | ||
|
|
||
| // Special case: Improper fraction: Numerator = Denominator | ||
| test(`should return false when: Numerator = Denominator`, () => { | ||
| expect(isProperFraction(1, 1)).toEqual(false); | ||
| expect(isProperFraction(12, 12)).toEqual(false); | ||
| expect(isProperFraction(56, 56)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: Improper negative fraction: -Numerator = -Denominator | ||
| test(`should return false when: Numerator = Denominator`, () => { | ||
| expect(isProperFraction(-1, -1)).toEqual(false); | ||
| expect(isProperFraction(-12, -12)).toEqual(false); | ||
| expect(isProperFraction(-56, -56)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: Improper fraction: Numerator > Denominator | ||
| test(`should return false when: Numerator > Denominator`, () => { | ||
| expect(isProperFraction(3, 2)).toEqual(false); | ||
| expect(isProperFraction(7, 4)).toEqual(false); | ||
| expect(isProperFraction(30, 20)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: Proper fraction with negative number: -Numerator < Denominator | ||
| test(`should return true when: -Numerator < Denominator`, () => { | ||
| expect(isProperFraction(-1, 2)).toEqual(true); | ||
| expect(isProperFraction(-6, 8)).toEqual(true); | ||
| expect(isProperFraction(-10, 20)).toEqual(true); | ||
| }); | ||
|
|
||
| // Special case: Proper fraction with both negative number: -Numerator < -Denominator | ||
| test(`should return true when: -Numerator < -Denominator`, () => { | ||
| expect(isProperFraction(-1, -2)).toEqual(true); | ||
| expect(isProperFraction(-6, -8)).toEqual(true); | ||
| expect(isProperFraction(-10, -20)).toEqual(true); | ||
| }); | ||
|
|
||
| // Special case: Improper fraction with negative number: Numerator > -Denominator | ||
| test(`should return false when: -Numerator > Denominator`, () => { | ||
| expect(isProperFraction(2, -1)).toEqual(false); | ||
| expect(isProperFraction(5, -4)).toEqual(false); | ||
| expect(isProperFraction(20, -10)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: Improper fraction with negative number: Numerator > -Denominator | ||
| test(`should return false when: -Numerator > Denominator`, () => { | ||
| expect(isProperFraction(-2, 1)).toEqual(false); | ||
| expect(isProperFraction(-5, 4)).toEqual(false); | ||
| expect(isProperFraction(-20, 10)).toEqual(false); | ||
| }); | ||
|
Comment on lines
+62
to
+95
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 two more negative test suites and two zero related test suites. Please add them back. Thank you.
Author
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. I did not have 0 denominator, both numerator and denominator as negative and negative denominator 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
Author
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. Ah seen, fixed the error. |
||
|
|
||
| // Special case: Improper fraction with both negative: -Numerator > -Denominator | ||
| test(`should return false when: -Numerator > Denominator`, () => { | ||
| expect(isProperFraction(-2, -1)).toEqual(false); | ||
| expect(isProperFraction(-5, -4)).toEqual(false); | ||
| expect(isProperFraction(-20, -10)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: Improper fraction with negative Numerator and 0: -Numerator > 0 | ||
| test(`should return false when: -Numerator > Denominator`, () => { | ||
| expect(isProperFraction(-2, 0)).toEqual(false); | ||
| expect(isProperFraction(-5, 0)).toEqual(false); | ||
| expect(isProperFraction(-20, 0)).toEqual(false); | ||
| }); | ||
|
|
||
| // Special case: Improper fraction with 0 and negative Denominator: 0 > -Denominator | ||
| test(`should return false when: -Numerator > Denominator`, () => { | ||
| expect(isProperFraction(0, -1)).toEqual(false); | ||
| expect(isProperFraction(0, -4)).toEqual(false); | ||
| expect(isProperFraction(0, -10)).toEqual(false); | ||
| }); | ||
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.
There should be one more boundary case for invalid angle. Can you think of it? Please add it back. 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.
Added invalid angle for negative numbers.