Skip to content

Commit c852657

Browse files
committed
write a series of tests for isProperFraction() function
1 parent f5555b2 commit c852657

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,17 @@ function assertEquals(actualOutput, targetOutput) {
3131

3232
// Example: 1/2 is a proper fraction
3333
assertEquals(isProperFraction(1, 2), true);
34+
35+
assertEquals(isProperFraction(9, 10), true);
36+
37+
assertEquals(isProperFraction(0, 7), false);
38+
39+
assertEquals(isProperFraction(5, 0), false);
40+
41+
assertEquals(isProperFraction(3.5, 6), false);
42+
43+
assertEquals(isProperFraction(2, 1), false);
44+
45+
assertEquals(isProperFraction(9, 3), false);
46+
47+
assertEquals(isProperFraction(4, 4.67), false);

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
55
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
66

77
// Special case: numerator is zero
8+
9+
test(`should return true when numerator < denominator and both are integers`, () => {
10+
expect(isProperFraction(1, 2)).toEqual(true);
11+
expect(isProperFraction(3, 9)).toEqual(true);
12+
expect(isProperFraction(99, 100)).toEqual(true);
13+
});
14+
15+
test(`should return false when denominator = zero`, () => {
16+
expect(isProperFraction(1, 0)).toEqual(false);
17+
expect(isProperFraction(5, 0)).toEqual(false);
18+
});
19+
20+
test(`should return false when numerator = zero`, () => {
21+
expect(isProperFraction(0, 5)).toEqual(false);
22+
expect(isProperFraction(0, 7)).toEqual(false);
23+
});
24+
25+
test(`should return false when numerator > denominator`, () => {
26+
expect(isProperFraction(3, 2)).toEqual(false);
27+
expect(isProperFraction(9, 3)).toEqual(false);
28+
expect(isProperFraction(36, 7)).toEqual(false);
29+
});
30+
31+
test(`should return false when either numerator or denominator or both are float numbers`, () => {
32+
expect(isProperFraction(1.5, 2)).toEqual(false);
33+
expect(isProperFraction(6, 7.1)).toEqual(false);
34+
expect(isProperFraction(3.56, 2.4)).toEqual(false);
35+
});
36+
837
test(`should return false when denominator is zero`, () => {
938
expect(isProperFraction(1, 0)).toEqual(false);
1039
});

0 commit comments

Comments
 (0)