1+ /**
2+ * Original file:
3+ *
14// This statement loads the isProperFraction function you wrote in the implement directory.
25// We will use the same function, but write tests for it using Jest in this file.
36const isProperFraction = require("../implement/2-is-proper-fraction");
@@ -8,3 +11,121 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
811test(`should return false when denominator is zero`, () => {
912 expect(isProperFraction(1, 0)).toEqual(false);
1013});
14+ *
15+ */
16+
17+ // This statement loads the isProperFraction function written in the implement directory.
18+ const isProperFraction = require ( "../implement/2-is-proper-fraction" ) ;
19+
20+ // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
21+
22+ describe ( 'isProperFraction' , ( ) => {
23+ // Test 1: Proper fractions with positive numbers
24+ describe ( 'positive proper fractions' , ( ) => {
25+ test ( 'should return true when numerator < denominator' , ( ) => {
26+ expect ( isProperFraction ( 1 , 2 ) ) . toBe ( true ) ;
27+ expect ( isProperFraction ( 3 , 4 ) ) . toBe ( true ) ;
28+ expect ( isProperFraction ( 5 , 8 ) ) . toBe ( true ) ;
29+ } ) ;
30+ } ) ;
31+
32+ // Test 2: Improper fractions with positive numbers
33+ describe ( 'positive improper fractions' , ( ) => {
34+ test ( 'should return false when numerator > denominator' , ( ) => {
35+ expect ( isProperFraction ( 3 , 2 ) ) . toBe ( false ) ;
36+ expect ( isProperFraction ( 4 , 3 ) ) . toBe ( false ) ;
37+ } ) ;
38+
39+ test ( 'should return false when numerator = denominator' , ( ) => {
40+ expect ( isProperFraction ( 5 , 5 ) ) . toBe ( false ) ;
41+ expect ( isProperFraction ( 1 , 1 ) ) . toBe ( false ) ;
42+ } ) ;
43+ } ) ;
44+
45+ // Test 3: Fractions with negative numbers
46+ describe ( 'fractions with negative numbers' , ( ) => {
47+ test ( 'should return true when |numerator| < |denominator|' , ( ) => {
48+ expect ( isProperFraction ( - 1 , 2 ) ) . toBe ( true ) ;
49+ expect ( isProperFraction ( 1 , - 2 ) ) . toBe ( true ) ;
50+ expect ( isProperFraction ( - 3 , - 4 ) ) . toBe ( true ) ;
51+ } ) ;
52+
53+ test ( 'should return false when |numerator| >= |denominator|' , ( ) => {
54+ expect ( isProperFraction ( - 3 , 2 ) ) . toBe ( false ) ;
55+ expect ( isProperFraction ( 3 , - 2 ) ) . toBe ( false ) ;
56+ expect ( isProperFraction ( - 4 , - 3 ) ) . toBe ( false ) ;
57+ expect ( isProperFraction ( - 2 , - 2 ) ) . toBe ( false ) ;
58+ } ) ;
59+ } ) ;
60+
61+ // Test 4: Zero cases
62+ describe ( 'fractions with zero' , ( ) => {
63+ test ( 'should return true when numerator is zero and denominator non-zero' , ( ) => {
64+ expect ( isProperFraction ( 0 , 1 ) ) . toBe ( true ) ;
65+ expect ( isProperFraction ( 0 , - 5 ) ) . toBe ( true ) ;
66+ } ) ;
67+
68+ test ( 'should return false when denominator is zero' , ( ) => {
69+ expect ( isProperFraction ( 1 , 0 ) ) . toBe ( false ) ;
70+ expect ( isProperFraction ( 0 , 0 ) ) . toBe ( false ) ;
71+ expect ( isProperFraction ( - 5 , 0 ) ) . toBe ( false ) ;
72+ } ) ;
73+ } ) ;
74+
75+ // Test 5: Non-integer inputs
76+ describe ( 'non-integer inputs' , ( ) => {
77+ test ( 'should return false when numerator is not an integer' , ( ) => {
78+ expect ( isProperFraction ( 1.5 , 2 ) ) . toBe ( false ) ;
79+ expect ( isProperFraction ( 1.1 , 3 ) ) . toBe ( false ) ;
80+ } ) ;
81+
82+ test ( 'should return false when denominator is not an integer' , ( ) => {
83+ expect ( isProperFraction ( 1 , 2.5 ) ) . toBe ( false ) ;
84+ expect ( isProperFraction ( 3 , 4.2 ) ) . toBe ( false ) ;
85+ } ) ;
86+
87+ test ( 'should return false when both are not integers' , ( ) => {
88+ expect ( isProperFraction ( 1.5 , 2.5 ) ) . toBe ( false ) ;
89+ expect ( isProperFraction ( 3.14 , 1.5 ) ) . toBe ( false ) ;
90+ } ) ;
91+ } ) ;
92+
93+ // Test 6: Large numbers
94+ describe ( 'large numbers' , ( ) => {
95+ test ( 'should handle large proper fractions' , ( ) => {
96+ expect ( isProperFraction ( 100 , 101 ) ) . toBe ( true ) ;
97+ expect ( isProperFraction ( 1000 , 1001 ) ) . toBe ( true ) ;
98+ expect ( isProperFraction ( 999999 , 1000000 ) ) . toBe ( true ) ;
99+ } ) ;
100+
101+ test ( 'should handle large improper fractions' , ( ) => {
102+ expect ( isProperFraction ( 1000 , 999 ) ) . toBe ( false ) ;
103+ expect ( isProperFraction ( 1000000 , 999999 ) ) . toBe ( false ) ;
104+ } ) ;
105+ } ) ;
106+
107+ // Test 7: Edge cases with negative large numbers
108+ describe ( 'negative large numbers' , ( ) => {
109+ test ( 'should handle negative large proper fractions' , ( ) => {
110+ expect ( isProperFraction ( - 100 , 101 ) ) . toBe ( true ) ;
111+ expect ( isProperFraction ( 100 , - 101 ) ) . toBe ( true ) ;
112+ expect ( isProperFraction ( - 1000 , - 1001 ) ) . toBe ( true ) ;
113+ } ) ;
114+
115+ test ( 'should handle negative large improper fractions' , ( ) => {
116+ expect ( isProperFraction ( - 101 , 100 ) ) . toBe ( false ) ;
117+ expect ( isProperFraction ( 101 , - 100 ) ) . toBe ( false ) ;
118+ expect ( isProperFraction ( - 1001 , - 1000 ) ) . toBe ( false ) ;
119+ } ) ;
120+ } ) ;
121+
122+ // Test 8: Special cases with Number.MIN_SAFE_INTEGER and MAX_SAFE_INTEGER
123+ describe ( 'edge integer values' , ( ) => {
124+ test ( 'should handle minimum and maximum safe integers' , ( ) => {
125+ expect ( isProperFraction ( Number . MAX_SAFE_INTEGER - 1 , Number . MAX_SAFE_INTEGER ) ) . toBe ( true ) ;
126+ expect ( isProperFraction ( Number . MAX_SAFE_INTEGER , Number . MAX_SAFE_INTEGER - 1 ) ) . toBe ( false ) ;
127+ expect ( isProperFraction ( Number . MIN_SAFE_INTEGER , Number . MAX_SAFE_INTEGER ) ) . toBe ( false ) ;
128+ } ) ;
129+ } ) ;
130+ } ) ;
131+
0 commit comments