-
-
Notifications
You must be signed in to change notification settings - Fork 240
Glasgow | 25-ITP-SEP | Alaa Tagi | Sprint 3 | Coursework/sprint 3 implement and rewrite #756
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?
Changes from 6 commits
b5de08b
b5fa562
3898643
78d374a
d07dd99
a223e45
17435c8
63246ca
b5c55bd
a3c8fc8
991832e
f52bd8d
5274005
7bc1534
5e63f68
27f970f
5837808
28455ef
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 |
|---|---|---|
|
|
@@ -11,6 +11,13 @@ function isProperFraction(numerator, denominator) { | |
| if (numerator < denominator) { | ||
| return true; | ||
| } | ||
| if (numerator < 0 && Math.abs(numerator) < denominator) { | ||
| return false; | ||
| } | ||
| if (numerator >= denominator) { | ||
| return false; | ||
| } | ||
| // we could add more checks here for invalid input, but not required for this exercise | ||
|
||
| } | ||
|
|
||
| // The line below allows us to load the isProperFraction function into tests in other files. | ||
|
|
@@ -47,13 +54,55 @@ assertEquals(improperFraction, false); | |
| // Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. | ||
| const negativeFraction = isProperFraction(-4, 7); | ||
| // ====> complete with your assertion | ||
| assertEquals(negativeFraction, true); | ||
|
|
||
| // Equal Numerator and Denominator check: | ||
| // Input: numerator = 3, denominator = 3 | ||
| // target output: false | ||
| // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. | ||
| const equalFraction = isProperFraction(3, 3); | ||
| // ====> complete with your assertion | ||
| assertEquals(equalFraction, false); | ||
|
|
||
| // Stretch: | ||
| // What other scenarios could you test for? | ||
|
|
||
|
|
||
| // Zero Numerator check: | ||
| // Input: numerator = 0, denominator = 5 | ||
| // target output: true | ||
| // Explanation: The fraction 0/5 is a proper fraction because the numerator (0) is less than the denominator (5). The function should return true. | ||
| const zeroNumerator = isProperFraction(0, 5); | ||
| assertEquals(zeroNumerator, true); | ||
|
|
||
| // Negative Denominator check: | ||
| // Input: numerator = 2, denominator = -3 | ||
| // target output: false | ||
| // Explanation: The fraction 2/-3 is not a proper fraction because the denominator is negative. The function should return false. | ||
| const negativeDenominator = isProperFraction(2, -3); | ||
| assertEquals(negativeDenominator, true); | ||
|
|
||
| let numerator= 1; | ||
| let denominator= 7; | ||
| console.log(numerator + "/" + denominator + " check =", isProperFraction(numerator, denominator)); | ||
| numerator= 5; | ||
| denominator= 1; | ||
| console.log(numerator + "/" + denominator + " check =", isProperFraction(numerator, denominator)); | ||
| numerator= -4; | ||
| denominator= 9; | ||
| console.log(numerator + "/" + denominator + " check =", isProperFraction(numerator, denominator)); | ||
| numerator= 0; | ||
| denominator= 6; | ||
| console.log(numerator + "/" + denominator + " check =", isProperFraction(numerator, denominator)); | ||
| numerator= 4; | ||
| denominator= 4; | ||
| console.log(numerator + "/" + denominator + " check =", isProperFraction(numerator, denominator)); | ||
| numerator= -5; | ||
| denominator= 8; | ||
| console.log(numerator + "/" + denominator + " check =", isProperFraction(numerator, denominator)); | ||
| numerator= 4; | ||
| denominator= -2; | ||
| console.log(numerator + "/" + denominator + " check =", isProperFraction(numerator, denominator)); | ||
| numerator= -3; | ||
| denominator= -7; | ||
| console.log(numerator + "/" + denominator + " check =", isProperFraction(numerator, denominator)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,16 @@ test("should return true for a proper fraction", () => { | |
| }); | ||
|
|
||
| // Case 2: Identify Improper Fractions: | ||
| test("should return false for an improper fraction", () => { | ||
| expect(isProperFraction(5, 2)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 3: Identify Negative Fractions: | ||
| test("should return false for a negative fraction", () => { | ||
| expect(isProperFraction(-1, 2)).toEqual(true); | ||
| }); | ||
|
||
|
|
||
| // Case 4: Identify Equal Numerator and Denominator: | ||
| test("should return false for equal numerator and denominator", () => { | ||
| expect(isProperFraction(3, 3)).toEqual(false); | ||
| }); | ||
|
||
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.
Checking
angle > 90is optional because previous if-statements can guaranteeangleis always more than 90.