Skip to content

Commit 3965407

Browse files
committed
Refine proper fraction comments and clarify invalid angle test description
1 parent 3f0d84e commit 3965407

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed
Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,61 @@
1-
// Implement a function isProperFraction.
2-
// When given two numbers, a numerator and a denominator, it should return true
3-
// if the given numbers form a proper fraction, and false otherwise.
1+
// Implement a function isProperFraction,
2+
// when given two numbers, a numerator and a denominator, it should return true if
3+
// the given numbers form a proper fraction, and false otherwise.
44

55
// Assumption: The parameters are valid numbers (not NaN or Infinity).
66

7-
// Definition:
8-
// A proper fraction is a fraction where:
9-
// - the denominator is not zero
10-
// - both numbers are non-negative
11-
// - the numerator is smaller than the denominator
7+
// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition.
128

139
// Acceptance criteria:
14-
// After implementing the function, write tests to cover all cases
15-
// and run the code to ensure all tests pass.
10+
// After you have implemented the function, write tests to cover all the cases, and
11+
// execute the code to ensure all tests pass.
1612

1713
function isProperFraction(numerator, denominator) {
18-
// A fraction with denominator 0 is invalid
14+
// A fraction with denominator 0 is invalid.
1915
if (denominator === 0) {
2016
return false;
2117
}
2218

23-
// Negative values are not allowed
19+
// For this implementation, proper fractions are positive fractions
20+
// where the numerator is smaller than the denominator.
2421
if (numerator < 0 || denominator < 0) {
2522
return false;
2623
}
2724

28-
// A proper fraction must have numerator smaller than denominator
2925
if (numerator < denominator) {
3026
return true;
3127
}
3228

33-
// All other cases are not proper fractions
3429
return false;
3530
}
3631

3732
// The line below allows us to load the isProperFraction function into tests in other files.
3833
// This will be useful in the "rewrite tests with jest" step.
3934
module.exports = isProperFraction;
4035

41-
// Helper function for simple assertions in this file
36+
// Here's our helper again
4237
function assertEquals(actualOutput, targetOutput) {
4338
console.assert(
4439
actualOutput === targetOutput,
4540
`Expected ${actualOutput} to equal ${targetOutput}`
4641
);
4742
}
4843

49-
// Tests to cover different combinations of numerators and denominators
44+
// TODO: Write tests to cover all cases.
45+
// What combinations of numerators and denominators should you test?
5046

5147
// Example: 1/2 is a proper fraction
5248
assertEquals(isProperFraction(1, 2), true);
5349

54-
// Proper fractions (numerator smaller than denominator)
50+
// Proper fractions
5551
assertEquals(isProperFraction(3, 5), true);
56-
assertEquals(isProperFraction(2, 7), true);
52+
assertEquals(isProperFraction(0, 5), true);
5753

58-
// Improper fractions (numerator greater than or equal to denominator)
54+
// Improper fractions
5955
assertEquals(isProperFraction(5, 5), false);
6056
assertEquals(isProperFraction(7, 3), false);
6157

62-
// Negative numbers should return false
63-
assertEquals(isProperFraction(-2, 7), false);
64-
assertEquals(isProperFraction(2, -7), false);
65-
66-
// Zero numerator is allowed if denominator is positive
67-
assertEquals(isProperFraction(0, 5), true);
68-
69-
// Invalid fraction (denominator is zero)
58+
// Invalid fractions
7059
assertEquals(isProperFraction(2, 0), false);
60+
assertEquals(isProperFraction(-1, 2), false);
61+
assertEquals(isProperFraction(1, -2), false);

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const getAngleType = require("../implement/1-get-angle-type");
66
// including boundary and invalid cases.
77

88
// Case 1: Acute angles
9-
test(`should return "Acute angle" when (0 < angle < 90)`, () => {
9+
test(`should return "Acute angle" when 0 < angle < 90`, () => {
1010
// Test various acute angles, including boundary cases
1111
expect(getAngleType(1)).toEqual("Acute angle");
1212
expect(getAngleType(45)).toEqual("Acute angle");
@@ -19,7 +19,7 @@ test(`should return "Right angle" when angle is exactly 90`, () => {
1919
});
2020

2121
// Case 3: Obtuse angles
22-
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
22+
test(`should return "Obtuse angle" when 90 < angle < 180`, () => {
2323
expect(getAngleType(91)).toEqual("Obtuse angle");
2424
expect(getAngleType(120)).toEqual("Obtuse angle");
2525
expect(getAngleType(179)).toEqual("Obtuse angle");
@@ -31,14 +31,14 @@ test(`should return "Straight angle" when angle is exactly 180`, () => {
3131
});
3232

3333
// Case 5: Reflex angles
34-
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
34+
test(`should return "Reflex angle" when 180 < angle < 360`, () => {
3535
expect(getAngleType(181)).toEqual("Reflex angle");
3636
expect(getAngleType(270)).toEqual("Reflex angle");
3737
expect(getAngleType(359)).toEqual("Reflex angle");
3838
});
3939

4040
// Case 6: Invalid angles
41-
test(`should return "Invalid angle" for angles outside valid range`, () => {
41+
test(`should return "Invalid angle" for angles less than or equal to 0, or greater than or equal to 360`, () => {
4242
expect(getAngleType(0)).toEqual("Invalid angle");
4343
expect(getAngleType(360)).toEqual("Invalid angle");
4444
expect(getAngleType(-10)).toEqual("Invalid angle");

0 commit comments

Comments
 (0)