Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f17635b
Implement getAngleType function and add assertion tests
Iswanna Oct 20, 2025
3766d27
Add assertions to test function outputs
Iswanna Oct 20, 2025
f9eea26
Add test for when numerator is zero for stretch task
Iswanna Oct 20, 2025
cfda58c
Update getCardValue function to return correct numerical values and t…
Iswanna Oct 20, 2025
b7a2183
Add and verify Jest test cases for the function
Iswanna Oct 22, 2025
f028f06
Include package-lock.json to ensure consistent dependency versions
Iswanna Oct 22, 2025
fec9455
Write Jest tests to verify function behavior
Iswanna Oct 22, 2025
0032765
Change random number check to return a string instead of throwing an …
Iswanna Oct 22, 2025
69ddec4
Write Jest test cases for getCardValue function implementation
Iswanna Oct 22, 2025
8c717df
Add more Jest test cases for getCardValue implementation
Iswanna Oct 22, 2025
028ec7d
Update getAngleType implementation and add more test cases to verify …
Iswanna Oct 28, 2025
6bcf17a
Fix inconsistent code indentation
Iswanna Oct 28, 2025
00515f5
Add test cases for negative numerator/denominator and other edge case…
Iswanna Oct 28, 2025
31446ec
Remove console.log debugging code from 3-get-card-value.js file
Iswanna Oct 28, 2025
121ebe4
Add test cases and update getCardValue to handle all card ranks
Iswanna Oct 28, 2025
b46a6d3
Add additional test to verify getAngleType correctly handles float in…
Iswanna Oct 29, 2025
273a36a
Update getAngleType and tests to classify zero degree as "Zero angle"…
Iswanna Oct 29, 2025
48f2143
Add more Jest test cases for acute angles in getAngleType
Iswanna Oct 29, 2025
9705d12
Add more jest test cases for obtuse angles in getAngleType
Iswanna Oct 29, 2025
5c5e00b
Add a Jest test case for straight angle in getAngleType
Iswanna Oct 29, 2025
a66ab62
Add more Jest test cases for reflex angles in getAngleType
Iswanna Oct 29, 2025
3b9f415
Add Jest test case for full rotation (360°) in getAngleType
Iswanna Oct 29, 2025
5e0b672
Add more Jest test cases for invalid angles in getAngleType
Iswanna Oct 29, 2025
8daafbd
Add test for 0 input to verify getAngleType returns 'Zero angle'
Iswanna Oct 29, 2025
050e86a
Change expected output from true to false in isProperFraction test fo…
Iswanna Oct 29, 2025
df7ccfb
Add more Jest test cases for getCardValue to include 2 and 10
Iswanna Oct 29, 2025
46aee35
Add tests for getCardValue with "1♠" and empty string arguments to en…
Iswanna Oct 29, 2025
47809af
Change expected output to true for proper fractions with negative num…
Iswanna Oct 29, 2025
cfecb6c
Add edge case test cases for isProperFraction: floats, large numbers,…
Iswanna Oct 29, 2025
9a88261
Change expected output to true for proper fraction with negative nume…
Iswanna Oct 29, 2025
7a4e526
Refactor isProperFraction to improve readability and reduce repetition
Iswanna Oct 29, 2025
5411c34
Change the target output in the comment to true for proper fraction w…
Iswanna Oct 29, 2025
3b5e67d
Change false to true in the test description for proper fraction with…
Iswanna Oct 29, 2025
bbde7ad
Test multiple values in each test case
Iswanna Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@
// complete the rest of the tests and cases
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
// Invalid input: must be integers
if (!Number.isInteger(numerator) || !Number.isInteger(denominator)) {
return false;
}

// Denominator cannot be zero
if (denominator === 0) {
return false;
}

function isProperFraction(numerator, denominator) {
let actualOutput;
// Denominator must be positive
if (denominator <= 0) {
actualOutput = false;
// Numerator cannot be zero
if (numerator === 0) {
return false;
}
// Numerator must be positive and smaller than denominator
else if (numerator > 0 && numerator < denominator) {
actualOutput = true;

// Proper fraction: absolute numerator smaller than absolute denominator
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
}

// All other cases are not proper fractions
else {
actualOutput = false;
}
return actualOutput;
return false;
}

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

// here's our helper again
Expand Down Expand Up @@ -60,7 +66,7 @@ assertEquals(improperFraction, false);
// Explanation: Negative numerator should not count as proper fraction.
const negativeFraction = isProperFraction(-4, 7);
// ====> complete with your assertion
assertEquals(negativeFraction, false);
assertEquals(negativeFraction, true);

// Equal Numerator and Denominator check:
// Input: numerator = 3, denominator = 3
Expand All @@ -85,18 +91,67 @@ assertEquals(zeroNumerator, false);
// Target output: false
// Explanation: Denominator must be positive for a proper fraction.
const negativeDenominator = isProperFraction(3, -5);
assertEquals(negativeDenominator, false);
assertEquals(negativeDenominator, true);

// Both Negative check:
// Input: numerator = -2, denominator = -3
// Target output: false
// Explanation: Proper fractions must have positive numerator and denominator.
const bothNegative = isProperFraction(-2, -3);
assertEquals(bothNegative, false);
assertEquals(bothNegative, true);

// Zero Denominator check:
// Input: numerator = 1, denominator = 0
// Target output: false
// Explanation: Division by zero is invalid; fraction cannot be proper.
const zeroDenominator = isProperFraction(1, 0);
assertEquals(zeroDenominator, false);

// Float Numerator check:
// Input: numerator = 2.5, denominator = 3
// Target output: false
// Explanation: Fractions with a non-integer numerator are not considered proper fractions.
const floatNumerator = isProperFraction(2.5, 3);
assertEquals(floatNumerator, false);

// Float Denominator check:
// Input: numerator = 2, denominator = 3.5
// Target output: false
// Explanation: Fractions with a non-integer denominator are invalid and should not be considered proper fractions.
const floatDenominator = isProperFraction(2, 3.5);
assertEquals(floatDenominator, false);

// Both Numerator and Denominator as Floats check:
// Input: numerator = 1.5, denominator = 2.5
// Target output: false
// Explanation: Fractions with both numerator and denominator as floats are invalid and should not be considered proper fractions.
const floatBoth = isProperFraction(1.5, 2.5);
assertEquals(floatBoth, false);

// Large Number check:
// Input: numerator = 99, denominator = 100
// Target output: true
// Explanation: 99/100 is a valid proper fraction, even with large values.
const largeNumbers = isProperFraction(99, 100);
assertEquals(largeNumbers, true);

// Negative Zero check:
// Input: numerator = -0, denominator = 5
// Target output: false
// Explanation: Negative zero is equivalent to zero; not a proper fraction.
const negativeZero = isProperFraction(-0, 5);
assertEquals(negativeZero, false);

// Denominator less than -1 check:
// Input: numerator = 1, denominator = -1
// Target output: false
// Explanation: Equal magnitude makes it improper, regardless of sign.
const negOneDenominator = isProperFraction(1, -1);
assertEquals(negOneDenominator, false);

// Proper Fraction check:
// Input: numerator = 2, denominator = 4
// Target output: true
// Explanation: 2/4 is a proper fraction because the absolute value of the numerator is less than the absolute value of the denominator.
const twoOverFour = isProperFraction(2, 4);
assertEquals(twoOverFour, true);
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test("should return false for improper fractions", () => {

// Case 3: Identify Negative Fractions:
test("should return false for negative fractions", () => {
expect(isProperFraction(-4, 9)).toEqual(false);
expect(isProperFraction(-4, 9)).toEqual(true);
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The test description does not quite match the test being carried out.

  • Could also consider testing multiple values in each test.

Copy link
Author

@Iswanna Iswanna Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The test description does not quite match the test being carried out.
  • Could also consider testing multiple values in each test.

Hi @cjyuan.

Thank you for the feedback. I have updated the test description to match the test. I have also tested more values for each test case.


// Case 4: Identify Equal Numerator and Denominator:
Expand Down