-
-
Notifications
You must be signed in to change notification settings - Fork 240
West Midlands | ITP-Sept-2025 | Ali Naru | Sprint 3 | Coursework/sprint 3 implement and rewrite #845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
West Midlands | ITP-Sept-2025 | Ali Naru | Sprint 3 | Coursework/sprint 3 implement and rewrite #845
Changes from all commits
6082322
2e97a22
d75ebfb
878d49e
6032ba9
cc9f8f2
6a9a7cd
ccd4e00
9ddec99
484ee5b
b489194
5c0c597
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,94 @@ | ||
| // Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js | ||
|
|
||
| // This statement loads the isProperFraction function you wrote in the implement directory. | ||
| // We will use the same function, but write tests for it using Jest in this file. | ||
| const isProperFraction = require("../implement/2-is-proper-fraction"); | ||
|
|
||
| test("should return true for a proper fraction", () => { | ||
| test("should return true for a proper fraction (numerator < denominator)", () => { | ||
| expect(isProperFraction(2, 3)).toEqual(true); | ||
| }); | ||
|
|
||
| // Case 2: Identify Improper Fractions: | ||
| // When the numerator is greater than or equal to the denominator, | ||
| // Then the function should return false | ||
| test("should return false for an improper fraction (numerator > denominator)", () => { | ||
| expect(isProperFraction(5, 2)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 3: Identify Negative Fractions: | ||
| // When the numerator is negative but absolute value < denominator, | ||
| // Then the function should return true | ||
| test("should return true for a negative proper fraction (|numerator| < denominator)", () => { | ||
| expect(isProperFraction(-4, 7)).toEqual(true); | ||
| }); | ||
|
Comment on lines
+19
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make the tests cover all possible categories, you can consider including a test for negative improper fractions.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ve updated the implementation based on feedback to make it more robust and complete. For |
||
|
|
||
| // Case 4: Identify Equal Numerator and Denominator: | ||
| // When the numerator is equal to the denominator, | ||
| // Then the function should return false | ||
| test("should return false when numerator equals denominator", () => { | ||
| expect(isProperFraction(3, 3)).toEqual(false); | ||
| }); | ||
|
|
||
| // When the numerator is negative but |numerator| >= denominator, | ||
| // Then the function should return false | ||
| test("should return false for a negative improper fraction (|numerator| >= denominator)", () => { | ||
| expect(isProperFraction(-8, 7)).toEqual(false); | ||
| }); | ||
|
|
||
| // When the numerator is zero, | ||
| // Then the function should return true | ||
| test("should return true when numerator is zero", () => { | ||
| expect(isProperFraction(0, 5)).toEqual(true); | ||
| }); | ||
|
|
||
| // When the denominator is zero, | ||
| // Then the function should throw an error | ||
| test("should throw an error when denominator is zero", () => { | ||
| expect(() => { | ||
| isProperFraction(3, 0); | ||
| }).toThrow("Denominator cannot be zero"); | ||
| }); | ||
|
|
||
| // When the numerator or denominator is not an integer, | ||
| // Then the function should throw an error | ||
| test("should throw an error when numerator or denominator is not an integer", () => { | ||
| expect(() => { | ||
| isProperFraction(2.5, 4); | ||
| }).toThrow("Numerator and denominator must be integers"); | ||
|
|
||
| expect(() => { | ||
| isProperFraction(3, "5"); | ||
| }).toThrow("Numerator and denominator must be integers"); | ||
| }); | ||
|
|
||
|
|
||
| // Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js | ||
| // This function takes a card string (e.g., "A♠", "10♥", "K♦") and returns its value in a game of cards. | ||
| function getCardValue(card) { | ||
| // Extract rank by removing suit symbol (last character) | ||
| const rank = card.slice(0, -1); | ||
|
|
||
| // Map face cards to values | ||
| const faceValues = { | ||
| J: 10, | ||
| Q: 10, | ||
| K: 10, | ||
| A: 11, | ||
| }; | ||
|
|
||
| // Return mapped value if rank is a face card | ||
| if (faceValues[rank]) { | ||
| return faceValues[rank]; | ||
| } | ||
|
|
||
| // Convert to number and validate numeric cards (2–10) | ||
| const numericValue = Number(rank); | ||
| if (!isNaN(numericValue) && numericValue >= 2 && numericValue <= 10) { | ||
| return numericValue; | ||
| } | ||
|
|
||
| // Invalid card | ||
| throw new Error("Invalid card rank"); | ||
| } | ||
|
|
||
| module.exports = getCardValue; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec wasn't clear enough.
How would you change your code if
denominatorcan also be negative?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the denominator might also be negative, we should compare absolute values. A proper fraction is defined by the absolute value of the numerator being smaller than the absolute value of the denominator, regardless of sign.