-
-
Notifications
You must be signed in to change notification settings - Fork 195
Sheffield | May-2025 | Hassan Osman | Sprint-3 #580
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?
Sheffield | May-2025 | Hassan Osman | Sprint-3 #580
Conversation
@@ -1,7 +1,10 @@ | |||
function getAngleType(angle) { | |||
if (angle === 90) return "Right angle"; | |||
// replace with your completed function from key-implement | |||
|
|||
if (angle < 90) return "Acute angle"; |
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.
angle <= 0 should also be considered as invalid angle.
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.
updated.
// Case 5: Identify Reflex Angles: | ||
// When the angle is greater than 180 degrees and less than 360 degrees, | ||
// Then the function should return "Reflex angle" | ||
|
||
|
||
test("should identify angle over 360", () => { |
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.
We could generalise this test to "should identify angle not in the range (0, 360) as 'invalid'")
if (numerator < denominator && (numerator/denominator) > 0) return true; | ||
if (numerator > denominator) return false; | ||
if (numerator < denominator && (numerator/denominator) < 0) return "Negative Fraction"; | ||
if (numerator === denominator ) return "Not really a fraction"; | ||
|
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 function should return either true
or false
.
true
means "the given numerator and denominator can form a proper fraction".false
means "the given numerator and denominator cannot form a proper fraction".
Note: If a function can possibly return different types of value, it would make consuming the return value difficult.
In mathematics, -4/7 == 4/-7, and -4/-7 == 4/7.
So, ideally isProperFraction()
should recognise all of them as proper fractions.
Hint: If you compute the absolute value of both parameters inside the function first, the code can become much simpler.
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.
That's totally ture CJ! I kept getting errors for some reason during tests, hence the multiple unnecessary scenarios I added. Anyway, function is now back to a simpler form.
test("should return true for an improper fraction", () => { | ||
expect(isProperFraction(11, 3)).toEqual(false); | ||
expect(isProperFraction(7, 2)).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.
The test description does not quite match the tests being performed.
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.
silly me! lol 😅 Changed this now
test("should return a negative fraction", () => { | ||
expect(isProperFraction(-11, 3)).toEqual("Negative Fraction"); | ||
}); | ||
|
||
|
||
// Case 4: Identify Equal Numerator and Denominator: | ||
|
||
test("should return a whole number", () => { | ||
expect(isProperFraction(4, 4)).toEqual("Not really a fraction"); | ||
}); |
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.
After you have updated the function implementation, you may want to update these tests accordingly.
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.
Done!
if (card === "Ace of Spades") return 11; | ||
if (card === "Number Cards") return "2-10"; | ||
if (card === "Ace") return "A"; | ||
if (card === "Face Cards") return "J, Q, K"; |
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.
You probably missed the spec of this function in Sprint-3/1-key-implement
.
The expected parameter is a string in this format: "A♠", "2♠", "10♥", "K♥", "Q♦", "J♣". The rank value can be an invalid string but the last character is always a valid suit character.
getCardValue("A♠")
should return 11.
getCardValue("K♠")
should return 10.
getCardValue("2♠")
should return 2.
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.
Complete!
if (str.includes(char) === true) { | ||
return str.split(char).length -1; | ||
} else { | ||
return 0; | ||
} |
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.
What is the value of str.split(char).length
when str
does not contain any character matching the value of char
?
Can we utilise the finding from the previous question to simplify our code?
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.
Simplified now.
if (num === 1) { | ||
return "1st"; | ||
} else if(num === 21) { | ||
return "21st"; | ||
} else if(num === 2) { | ||
return "2nd"; | ||
} else if(num === 22) { | ||
return "22nd"; | ||
} else { | ||
return `${num}th`; |
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.
getOrdinalNumber(101)
should return "101st".
Consider looking up the rules to clarify how ordinal numbers are formed.
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.
function has now been changed to accommodate all numbers.
if(count > 0) { | ||
return str.repeat(count); | ||
} else if (count === 0) { | ||
return " "; |
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.
" "
is a string containing one space. ""
is an empty string (a string containing 0 characters).
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.
corrected!
@@ -1,6 +1,10 @@ | |||
function isProperFraction(numerator, denominator) { | |||
if (numerator < denominator) return true; | |||
// add your completed function from key-implement here | |||
if (numerator >= denominator) { |
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.
A single comparison is enough if we can ensure the values being compared are positives.
That is, treat -2/3, 2/-3, and -2/-3 the same as 2/3. (They are all proper fractions).
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.
added Math.abs() in the hope it would sort out the issue.
return 11; | ||
break; | ||
case "2♠": | ||
return 2; |
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.
A card can have one of four possible suits; the last character can also be a heart, club, or diamond. Your approach works great if you can extract the rank from the parameter first.
// Case 3: Handle Face Cards (J, Q, K): | ||
test("should return 10 for K♠ card", () => { |
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.
We could generalise this test to "should return 10 for face cards (J, Q, K)" and check all three ranks J, Q, K). Same for "all number cards".
Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js
Outdated
Show resolved
Hide resolved
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.
Changes look good.
Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js
could still be improved.
test("should return 10 for face cards (J, Q, K)", () => { | ||
const faceCards = getCardValue("K♣︎"); | ||
expect(faceCards).toEqual(10); | ||
}); | ||
|
||
test("should return 10 for Q♠ card", () => { | ||
test("should return 10 for face cards (J, Q, K)", () => { | ||
const faceCards = getCardValue("Q♠"); | ||
expect(faceCards).toEqual(10); | ||
}); |
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.
We could combine these tests as
test("should return 10 for face cards (J, Q, K)", () => {
expect(getCardValue("J♣︎")).toEqual(10);
expect(getCardValue("Q♠")).toEqual(10);
expect(getCardValue("K♣︎")).toEqual(10);
});
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.
Done!
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.
I don't think your implementation can pass some of the tests in this script. Have you tried executing this script to test your function implementation?
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.
Yes, some mistakes in the 2 expected values which have now been corrected.
test("should append 'st' to numbers ending with 1 and not ending with 11", () => { | ||
expect(getOrdinalNumber(1)).toEqual("1st"); | ||
}); | ||
|
||
test("should append 'st' to numbers ending with 1 and not ending with 11", () => { | ||
expect(getOrdinalNumber(41)).toEqual("41st"); | ||
}); | ||
|
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.
Can be combined.
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.
done!
CJ, is there a way I could jests test a specific file, rather than running the whole test for all files? Tried doing so but keep ending up with errors :( |
Changes are good! Good job. You can run jest on a single file as |
Learners, PR Template
Self checklist
Changelist
In this PR, I implemented the functions and tested them using Jest.
Questions
Ask any questions you have for your reviewer.