Skip to content

Commit c874085

Browse files
committed
add more test cases for proper fraction
1 parent 5768ab4 commit c874085

2 files changed

Lines changed: 28 additions & 30 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,11 @@ assertEquals(isProperFraction(-9, 10), true);
5151
assertEquals(isProperFraction(-5, -5), false);
5252
assertEquals(isProperFraction(-1, 0), false);
5353
assertEquals(isProperFraction(-1, -5), true);
54-
assertEquals(isProperFraction(-1, -5), true);
55-
assertEquals(isProperFraction(1, -5), true);
54+
assertEquals(isProperFraction(1, -5), true);
55+
assertEquals(isProperFraction(0, 0), false);
56+
assertEquals(isProperFraction(-1, 2), true);
57+
assertEquals(isProperFraction(1, -2), true);
58+
assertEquals(isProperFraction(-1, -2), true);
59+
assertEquals(isProperFraction(-2, 1), false);
60+
assertEquals(isProperFraction(2, -1), false);
61+
assertEquals(isProperFraction(-2, -1), false);

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,41 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
77
// Denominator is zero
88
test("should return false when denominator is zero", () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
10+
expect(isProperFraction(-1, 0)).toEqual(false);
11+
expect(isProperFraction(0, 0)).toEqual(false);
1012
});
1113

12-
// Proper fractions
13-
test("should return true when numerator is less than denominator", () => {
14+
// Proper fractions with positive values
15+
test("should return true when the absolute value of the numerator is less than the absolute value of the denominator", () => {
1416
expect(isProperFraction(1, 2)).toEqual(true);
1517
expect(isProperFraction(2, 4)).toEqual(true);
1618
expect(isProperFraction(15, 30)).toEqual(true);
1719
});
1820

1921
// Numerator is zero
20-
test("should return true when numerator is zero", () => {
22+
test("should return true when numerator is zero and denominator is non-zero", () => {
2123
expect(isProperFraction(0, 9)).toEqual(true);
24+
expect(isProperFraction(0, -9)).toEqual(true);
2225
});
2326

2427
// Equal numerator and denominator
25-
test("should return false when numerator is equal to denominator", () => {
28+
test("should return false when numerator and denominator have equal absolute values", () => {
2629
expect(isProperFraction(5, 5)).toEqual(false);
30+
expect(isProperFraction(-5, -5)).toEqual(false);
2731
});
2832

29-
// Numerator is greater than denominator
30-
test("should return false when numerator is greater than denominator", () => {
31-
expect(isProperFraction(6, 3)).toEqual(false);
32-
expect(isProperFraction(10, 4)).toEqual(false);
33-
});
34-
35-
// Negative numerator
36-
test("should return true when numerator is negative and forms a proper fraction", () => {
37-
expect(isProperFraction(-1, 5)).toEqual(true);
38-
expect(isProperFraction(-9, 10)).toEqual(true);
39-
});
40-
41-
// Negative denominator
42-
test("should return true when denominator is negative and forms a proper fraction", () => {
43-
expect(isProperFraction(1, -5)).toEqual(true);
44-
});
45-
46-
// Both numerator and denominator are negative
47-
test("should handle both numerator and denominator being negative", () => {
48-
expect(isProperFraction(-1, -5)).toEqual(true);
49-
expect(isProperFraction(-5, -5)).toEqual(false);
33+
// Negative values that form proper fractions
34+
test("should return true for negative values when the absolute numerator is less than the absolute denominator", () => {
35+
expect(isProperFraction(-1, 2)).toEqual(true);
36+
expect(isProperFraction(1, -2)).toEqual(true);
37+
expect(isProperFraction(-1, -2)).toEqual(true);
5038
});
5139

52-
// Negative numerator with zero denominator
53-
test("should return false when denominator is zero with a negative numerator", () => {
54-
expect(isProperFraction(-1, 0)).toEqual(false);
40+
// Positive and negative values that do not form proper fractions
41+
test("should return false when the absolute numerator is greater than or equal to the absolute denominator", () => {
42+
expect(isProperFraction(-2, 1)).toEqual(false);
43+
expect(isProperFraction(2, -1)).toEqual(false);
44+
expect(isProperFraction(-2, -1)).toEqual(false);
45+
expect(isProperFraction(6, 3)).toEqual(false);
46+
expect(isProperFraction(10, 4)).toEqual(false);
5547
});

0 commit comments

Comments
 (0)