Skip to content

London|May 2025|Alexandru Pocovnicu|Coursework/sprint 3 #639

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

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

Conversation

alexandru-pocovnicu
Copy link

@alexandru-pocovnicu alexandru-pocovnicu commented Jul 4, 2025

Learners, PR Template

Self checklist

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

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@alexandru-pocovnicu alexandru-pocovnicu added the Needs Review Participant to add when requesting review label Jul 4, 2025
@alexandru-pocovnicu alexandru-pocovnicu changed the title Coursework/sprint 3 London|May 2025|Alexandru Pocovnicu|Coursework/sprint 3 Jul 5, 2025
@cjyuan cjyuan added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Participant to add when requesting review labels Jul 15, 2025
Comment on lines 26 to 28
test("should identify reflex angle(230°)",()=>{
expect(getAngleType(230)).toEqual("Reflex angle")
});
Copy link
Contributor

Choose a reason for hiding this comment

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

To ensure thorough testing, we need broad scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases.
Instead of writing tests for individual angles, consider grouping all possible input values into meaningful categories. Then, select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain. For example,

test("should identify reflex angle (180 < angle < 360)", () => {
  expect(getAngleType(300)).toEqual("Reflex angle");
  expect(getAngleType(359.999)).toEqual("Reflex angle");
  expect(getAngleType(180.001)).toEqual("Reflex angle");
});

Choose a reason for hiding this comment

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

thank you...is it possible to test a negative in this case, if i add 'else' it affects the other tests

Copy link
Contributor

Choose a reason for hiding this comment

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

angle <= 0 should be considered as an invalid angle.

@@ -1,5 +1,9 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (isNaN(numerator) || isNaN(denominator)) return NaN;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also return false. Technically if any of the parameter is NaN, then it cannot represent a proper fraction.

Choose a reason for hiding this comment

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

Sorry but I do not understand, I don't seem to have this line if (numerator < denominator) return true; in my code

Copy link
Contributor

Choose a reason for hiding this comment

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

  • I mean, instead of returning NaN, you could return false.

  • Red-highlighted lines are removed lines, and green-highlighted lines are new additions to the file.

Comment on lines +4 to +5
if (rank === "A") return 11;
if(rank>=2 && rank<10)return Number(rank);
Copy link
Contributor

Choose a reason for hiding this comment

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

In JavaScript, strings that represent valid numeric literals in the language can be safely converted to equivalent numbers. For examples, "0x02", "2.1", or "00_02".

Does your function return the value you expected from each of the following function calls?

getCardValue("0x02♠");
getCardValue("2.1♠");
getCardValue("00_02♠");

Choose a reason for hiding this comment

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

getCardValue("00_02♠"); it doesn't for this one, from my understanding the result of that should be 2♠ , I wrote a test for 2♠, but i still cant figure it out, sorry

Copy link
Contributor

Choose a reason for hiding this comment

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

In your case "00_02" should not satisfy the condition at line 5. The other two do.

A few more cases:

getCardValue("3e0♠");
getCardValue("000002♠");

You would need a stricter check to ensure rank is one of the 9 possible number ranks before you convert it to a number.

Comment on lines +17 to +19
test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of writing tests for individual numbers, consider grouping all possible input values into meaningful categories. For example, we can prepare a test for numbers 2, 22, 132, etc. as

test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
    expect( getOrdinalNumber(2) ).toEqual("2nd");
    expect( getOrdinalNumber(22) ).toEqual("22nd");
    expect( getOrdinalNumber(132) ).toEqual("132nd");
});

Can you update the tests in this script so that they can cover all possible valid numbers?

Comment on lines +2 to +4
if (isNaN(num)) {
return NaN;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  • The function is expected to return a string, so even if the parameter is not an integer, it is better to return a string instead of NaN.

  • Could also consider using Number.isInteger() to check if a value is an integer.

Comment on lines +2 to +4
if(count<0){
return "negative number"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How would the caller distinguish the result of the following two function calls?

  1. repeat("negative number", 1)
  2. repeat("", -1)

Both function calls return the same value.

Comment on lines +46 to +51
test("should repeat the string count times", () => {
const str = "hello";
const count = -1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("negative number");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

If you modified repeat() to throw an error when count is negative, and you wanted to test if the function can throw an error as expected, you can use .toThrow(). You can find out more about how to use .toThrow() here: https://jestjs.io/docs/expect#tothrowerror (Note: Pay close attention to the syntax of the example)

Comment on lines 20 to 46
const password = "123bB45%";
// Act
const result = isValidPassword(password);
// Assert
expect(result).toEqual(true);
}
); No newline at end of file
);
test("password has at least one uppercase letter (A-Z)", () => {
const password = "abcB123%";
const result = isValidPassword(password);
expect(result).toEqual(true);
});
test("password has at least one lowercase letter (a-z)", () => {
const password = "abcB123%";
const result = isValidPassword(password);
expect(result).toEqual(true);
});
test("password has at least one number (0-9)", () => {
const password = "abcB123%";
const result = isValidPassword(password);
expect(result).toEqual(true);
});
test('password has at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&")', () => {
const password = "abcB123%";
const result = isValidPassword(password);
expect(result).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.

All these tests should also check if the function can return false when the password satisfies all other conditions except the one described in the test.

For example,

test("password has at least 5 characters", () => {
    // This password contains each of the required characters but is too short
    expect( isValidPassword("Aa1$") ).toEqual(false);
}

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jul 15, 2025
@alexandru-pocovnicu
Copy link
Author

Hi, I don't know what's happening, all the files in sprint 3 from my computer are empty, as if i haven't done any work in them , is there a way I could copy the ones on github, should i clone the whole PR and then push that , will i have to create a new PR?
Thank you.

@alexandru-pocovnicu
Copy link
Author

never mind the previous message , sorted....i was in the wrong branch

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