Skip to content
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

CYF-ITP-South Africa | Natalie Patel | Module-Structuring-and-Testing-Data | Sprint 3 #229

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

NataliePatel
Copy link

@NataliePatel NataliePatel commented Dec 16, 2024

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

In this PR, I completed the exercises outlined in Sprint 3. I created .test files as well as .js files where applicable, ensuring that my code has been written in the right file formats which nearly caught me out.
I had to consult the documentation a lot and iterated through failed tests to reach tests that passed.

It has been interesting to learn how to write functions in different ways, especially as the use cases become larger or more advanced. I am expecting to learn more complex ways as I progress through my development.

@NataliePatel NataliePatel added the Needs Review Participant to add when requesting review label Dec 16, 2024
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

I left some comments and suggestions.
Changes which I think you should make are marked with "Todo" in my comments.

else if (angle > 180 && angle < 360) {
return "Reflex angle";
}
else if (angle <= 0 && angle >= 360) {
Copy link

Choose a reason for hiding this comment

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

If angle is not any of the valid value, then it must be invalid. So an else would be suffice.

}

//Handling when card inputs are 2-9
if (rank >= "2" && rank <= "9") {
Copy link

Choose a reason for hiding this comment

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

Todo

Can you also check if getCardValue("23♠") or getCardValue("8ABC♠") are returning the value you expect?


function isProperFraction (numerator, denominator) {
//Check if numerator OR denominator is 0, throw an error
if (numerator === 0 || denominator === 0) {
Copy link

Choose a reason for hiding this comment

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

0 can be considered a fraction. So numerator should be allowed to be 0.

let den = Math.abs(denominator);

if (num < den) {
return "True";
Copy link

Choose a reason for hiding this comment

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

Todo

Should return the Boolean value true or false instead of strings "True" or "False".

if (num < den) {
return "True";
}
else if (num > den) {
Copy link

Choose a reason for hiding this comment

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

Assuming num and den are finite numbers.
If num is not less than den, then it would mean num is either greater than or equal to den. As a result, an else would be suffice.

//This will isolate the last character and last two characters to handle what to add to the end of the returned string.
//1 will return 1st, 2 will return 2nd but 11, 12 and 13 with return 11th, 12th and 13th
const findLastCharacter = number % 10; //The remainder of the division is the last character
const findLastTwoCharacters = number % 100; //The remainder of the division are the last two characters
Copy link

Choose a reason for hiding this comment

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

lastDigit and lastTwoDigits would be shorter.

expect(getOrdinalNumber("23")).toBe("23rd");
});

test("should return a string ending in 'th' if any number containing 2 except 12 is input or 11, 12 and 13 are input", () => {
Copy link

Choose a reason for hiding this comment

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

A more concise description could be "Expect suffix 'th' if the last two digits of the number are 11, 12, or 13"

return false; //Numbers divisible by 2 or 3 with no remainder are prime numbers
}

return true; //All other instances are prime numbers
Copy link

Choose a reason for hiding this comment

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

Todo

5 is a prime numbers.
5 * 5 = 25 is not divisible by 2 or 3, but it is divisible by 5. So 25 is not a prime number.

You need additional code to make this function work for other integers.

test("should return false if input does not contain a lowercase letter", () => {
const previousPasswords = ["passWord55@", "Access1!Point", "#MarioBros3"]
expect(passwordValidator("TELEVISION", previousPasswords)).toBe(false);
expect(passwordValidator("01010101010", previousPasswords)).toBe(false);
Copy link

Choose a reason for hiding this comment

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

The test value "01010101010" is not specific enough. When this test fails, it could mean one or more of the followings:

  • The function failed to check if the password contain a non-alphanumeric character
  • The function failed to check if the password contain a lowercase letter
  • The function failed to check if the password contain an uppercase letter

which is not exactly "... does not contain a lowercase letter".

Ideally, when a test fails, we want to know exactly why the test failed.

Many of the test values (invalid passwords) in this file are not specific enough.

test('should return "Please enter a positive number" if a negative number, null or undefined is input', () => {
expect(() =>repeat("-1")).toThrow("Please enter a positive number");
expect(() =>repeat(null)).toThrow("Please enter a positive number");
expect(() =>repeat(undefined)).toThrow("Please enter a positive number");
Copy link

Choose a reason for hiding this comment

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

Why call repeat() with only one parameter?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Dec 16, 2024
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Just left you a suggestion on your recent change in get-card-value.js.

//Handling when card inputs are 2-9
if (rank >= "2" && rank <= "9") {
//Handling when card inputs are 2-10
if (!isNaN(rank) && rank.length<=2 && Number(rank) >= "2" && Number(rank) <= "10") {
Copy link

Choose a reason for hiding this comment

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

Do you want to accept rank such as "07" in your design?

When we treat strings as number, we have to consider a lot of possibilities.
It is easier to

  • First, ensure the string matches our expected pattern (e.g., one of 2", "3", ...., "10")
  • Next, convert the string to its equivalent numerical value.

Your previous code is actually quite solid.

//Handling when card input is 10
    if (rank === "10") {
        return 10;
    }    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants