Skip to content

Commit bc00dfc

Browse files
committed
adding 9 stretch tests in proper fraction
1 parent 5245e20 commit bc00dfc

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,52 @@ assertEquals(negativeDenominator, true);
7575
// Explanation: The fraction 0/5 is a proper fraction because the absolute value of numerator (0) is less than the denominator (5).
7676
const zeroNumerator = isProperFraction(0, 5);
7777
assertEquals(zeroNumerator, true);
78+
7879
// Stretch 3: zero denominator - this is mathematically undefined but we can decide how we want to handle it
80+
// Input: numerator = 5, denominator = 0
81+
// target output: false
82+
// Explanation: The fraction 5/0 is undefined in mathematics. In this implementation, we choose to return false.
7983
const zeroDenominator = isProperFraction(5, 0);
8084
assertEquals(zeroDenominator, false);
85+
8186
// Stretch 4: both zero
87+
// Input: numerator = 0, denominator = 0
88+
// target output: false
89+
// Explanation: The fraction 0/0 is indeterminate in mathematics. In this implementation, we choose to return false.
8290
const bothZero = isProperFraction(0, 0);
8391
assertEquals(bothZero, false);
92+
8493
// Stretch 5: negative numerator and denominator
94+
// Input: numerator = -3, denominator = -5
95+
// target output: true
96+
// Explanation: The fraction -3/-5 is a proper fraction because the absolute value of the numerator (3) is less than the absolute value of the denominator (5). The function should return true.
8597
const negativeNumeratorAndDenominator = isProperFraction(-3, -5);
8698
assertEquals(negativeNumeratorAndDenominator, true);
99+
87100
// Stretch 6: improper negative numerator and denominator
101+
// Input: numerator = -3, denominator = -2
102+
// target output: false
103+
// Explanation: The fraction -3/-2 is an improper fraction because the absolute value of the numerator (3) is greater than the absolute value of the denominator (2). The function should return false.
88104
const properNegativeNumeratorAndDenominator = isProperFraction(-3, -2);
89105
assertEquals(properNegativeNumeratorAndDenominator, false);
106+
90107
// Stretch 7: decimal values
108+
// Input: numerator = 2.5, denominator = 3.5
109+
// target output: true
110+
// Explanation: The fraction 2.5/3.5 is a proper fraction because the absolute value of the numerator (2.5) is less than the absolute value of the denominator (3.5). The function should return true.
91111
const decimalValues = isProperFraction(2.5, 3.5);
92112
assertEquals(decimalValues, true);
113+
93114
// Stretch 8: improper decimal values
115+
// Input: numerator = 3.5, denominator = 2.5
116+
// target output: false
117+
// Explanation: The fraction 3.5/2.5 is an improper fraction because the absolute value of the numerator (3.5) is greater than the absolute value of the denominator (2.5). The function should return false.
94118
const improperDecimalValues = isProperFraction(3.5, 2.5);
95119
assertEquals(improperDecimalValues, false);
120+
96121
// Stretch 9: invalid inputs (non-numeric values)
122+
// Input: numerator = "a", denominator = 2
123+
// target output: false
124+
// Explanation: The function should handle non-numeric inputs gracefully. In this case, we choose to return false.
97125
const invalidInputs = isProperFraction("a", 2);
98126
assertEquals(invalidInputs, false);

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,50 @@ test("should return false when numerator equals denominator", () => {
2222
});
2323

2424
// Stretch 1: Identify Negative Denominator:
25-
test("should return true when the absolute value of a negative denominator is larger than numerator", () => {
25+
test("should return true when 2 < |3|", () => {
2626
expect(isProperFraction(2, -3)).toEqual(true);
2727
});
28+
29+
// Stretch 2: Identify Zero Numerator:
30+
test("should return true when 0 < 5", () => {
31+
expect(isProperFraction(0, 5)).toEqual(true);
32+
});
33+
34+
// Stretch 3: Handle Zero Denominator:
35+
// This test checks how the function handles a zero denominator, which is mathematically undefined.
36+
// We expect the function to return false in this case.
37+
test("should return false when 3 > 0", () => {
38+
expect(isProperFraction(3, 0)).toEqual(false);
39+
});
40+
41+
// Stretch 4: Handle Both Numerator and Denominator as Zero:
42+
// This test checks how the function handles both numerator and denominator being zero.
43+
// We expect the function to return false in this case as well.
44+
test("should return false when both numerator and denominator are zero", () => {
45+
expect(isProperFraction(0, 0)).toEqual(false);
46+
});
47+
48+
// Stretch 5: Identify Negative Numerator and Negative Denominator:
49+
test("should return true when |3| < |5|", () => {
50+
expect(isProperFraction(-3, -5)).toEqual(true);
51+
});
52+
53+
// Stretch 6: Identify Improper Negative Numerator and Negative Denominator:
54+
test("should return false when |3| > |2|", () => {
55+
expect(isProperFraction(-3, -2)).toEqual(false);
56+
});
57+
58+
// Stretch 7: Identify Decimal Values:
59+
test("should return true when 2.5 < 3.5", () => {
60+
expect(isProperFraction(2.5, 3.5)).toEqual(true);
61+
});
62+
63+
// Stretch 8: Identify Improper Decimal Values:
64+
test("should return false when 3.5 > 2.5", () => {
65+
expect(isProperFraction(3.5, 2.5)).toEqual(false);
66+
});
67+
68+
// Stretch 9: Identify invalid Inputs (Non-numeric Values):
69+
test("should return false for non-numeric inputs", () => {
70+
expect(isProperFraction("a", 2)).toEqual(false);
71+
});

0 commit comments

Comments
 (0)