-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-is-proper-fraction.test.js
More file actions
67 lines (54 loc) · 2.42 KB
/
2-is-proper-fraction.test.js
File metadata and controls
67 lines (54 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const isProperFraction = require("../implement/2-is-proper-fraction");
// Case 1: Proper Fraction
// Given a numerator smaller than denominator (2/3),
// When the function is called,
// Then it should return true because it's a proper fraction.
test("should return true for a proper fraction (2/3)", () => {
expect(isProperFraction(2, 3)).toEqual(true);
});
// Case 2: Improper Fraction
// Given a numerator greater than denominator (5/2),
// When the function is called,
// Then it should return false because it's an improper fraction.
test("should return false for an improper fraction (5/2)", () => {
expect(isProperFraction(5, 2)).toEqual(false);
});
// Case 3: Negative Proper Fraction
// Given a negative proper fraction (-1/2),
// When the function is called,
// Then it should return true because the value is between -1 and 1.
test("should return true for a negative proper fraction (-1/2)", () => {
expect(isProperFraction(-1, 2)).toEqual(true);
});
// Case 4: Equal Numerator and Denominator
// Given a numerator equal to denominator (3/3),
// When the function is called,
// Then it should return false because it's equal to 1 (not proper).
test("should return false for equal numerator and denominator (3/3)", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
// Case 5: Zero numerator
// 0 divided by any non-zero denominator is a proper fraction.
test("should return true for zero numerator", () => {
expect(isProperFraction(0, 5)).toEqual(true);
});
// Case 6: Negative denominator
// When denominator is negative, the fraction is still valid, so check absolute values.
test("should return true when denominator is negative but |numerator| < |denominator|", () => {
expect(isProperFraction(2, -3)).toEqual(true);
});
// Case 7: Denominator is zero
// Division by zero is undefined, should return false.
test("should return false when denominator is zero", () => {
expect(isProperFraction(3, 0)).toEqual(false);
});
// Case 8: Both numerator and denominator are negative but |numerator| < |denominator|
// Negative/negative cancels out, still a proper fraction.
test("should return true when both numerator and denominator are negative and |numerator| < |denominator|", () => {
expect(isProperFraction(-3, -7)).toEqual(true);
});
// Case 9: Large numbers
// It should handle large numbers correctly.
test("should return true for large proper fractions", () => {
expect(isProperFraction(999, 1000)).toEqual(true);
});