Skip to content

Conversation

MarynaRomashca
Copy link

@MarynaRomashca MarynaRomashca commented Feb 26, 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 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

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

Copy link
Author

@MarynaRomashca MarynaRomashca left a comment

Choose a reason for hiding this comment

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

Please check my Sprint 3

@MarynaRomashca MarynaRomashca changed the title Coursework/sprint-3+ ITP-Jan 2025 | London | Maryna Romanova | Module-Structuring-and-Testing-Data | Week 6 | Sprint 3 Feb 26, 2025
@MarynaRomashca MarynaRomashca added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 26, 2025
@cjyuan
Copy link
Contributor

cjyuan commented Mar 8, 2025

Can you fix this branch so that it only contains modified files in the "Sprint-3" folder?

@alastair87 alastair87 added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 17, 2025
@MarynaRomashca
Copy link
Author

@cjyuan Done, the "Sprint-3" folder is fixed. Please review it. Many thanks.

Copy link
Contributor

@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.

Some of the functions could use some improvement or bug fix.

Most of my comments are related to Jest tests. Do you need assistance on using Jest?

Comment on lines 10 to 13
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
else return false;

Copy link
Contributor

Choose a reason for hiding this comment

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

Mathematically speaking, -3/2 and -1/0 are not proper fractions (but -3 < 2 and -1 < 0) and -2/-3 is a proper fraction (but -2 > -3).

We need to consider the cases that numerator and denominator can be negative, positive, or zero.

However, if we were to consider all possible combinations of negative/positive/zero numerator and denominator, we would have to use a lot of if-statements. One way to reduce the complexity of the code is to "remove the negative sign" in numerator and denominator. If both numerator and denominator are non-negative numbers, then the if-statements at lines 11-12 would work perfectly.

Input normalisation, the process of pre-processing the input values before they are used in computation, can often simplify complexity of code, improve performance, and prevent errors.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

if (rank === "A") return 11;
}
if (rank === "J" || rank === "Q" || rank === "K" || rank === "10") return 10;
if (rank >= "2" && rank <= "9") return parseInt(rank);
Copy link
Contributor

Choose a reason for hiding this comment

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

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

getCardValue("29♠");
getCardValue("0x02♠");
getCardValue("2.1♠")

Copy link
Author

Choose a reason for hiding this comment

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

No, the function does not return this numeric. In all three cases, the function throws an "Invalid card rank" error.

Comment on lines 20 to 22
test("should identify right angle (90°)", () => {
expect(getAngleType(90)).toEqual("Right angle");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are all the tests testing the same thing (testing for "Right angle" 4 times) ?

Copy link
Author

@MarynaRomashca MarynaRomashca Apr 3, 2025

Choose a reason for hiding this comment

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

Sorry my mistake. Fixed

Comment on lines 6 to 12

function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
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 to be tested in 2-is-proper-fraction.test.js. So we don't need the assertEquals() at lines 6-12.

After you reimplemented isProperFraction() in 1-key-implement/2-is-proper-fractions.js, you can copy the code of that function here.

Copy link
Author

@MarynaRomashca MarynaRomashca Apr 3, 2025

Choose a reason for hiding this comment

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

I deleted the lines 6-12, and fix the test in the file ' 2-is-proper-fraction.test.js '

Comment on lines 8 to 9
const improperFraction = isProperFraction(5, 2);
assertEquals(improperFraction, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

This exercise expects us to write Jest test code to test the function.

So to test improper fraction, we can express our test code as

test("should return false for a improper fraction", () => {
 // We can test multiple sets of values belonging to the same case
  expect(isProperFraction(5, 2)).toEqual(false);  
  expect(isProperFraction(5, -2)).toEqual(false);
  expect(isProperFraction(-5, 2)).toEqual(false);    
  expect(isProperFraction(-5, -2)).toEqual(false);
});

Copy link
Author

Choose a reason for hiding this comment

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

got it

const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hihihi");
});

Copy link
Contributor

Choose a reason for hiding this comment

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

What about those cases described in the comments at lines 26-39?

For the negative count case, you can prepare your test as:

test("should throw an error when count is negative", () => {
    expect(() => {
      repeat('hi', -1)         
    }).toThrow();
});

Please note that when we expect a function to throw an error, we need to wrap the function call inside () => { ... }.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, very useful.

Comment on lines +22 to +25
// a) How the index variable updates during the call to find - index start with O and going on with +1 until not reach str.length
// b) What is the if statement used to check - in this situation "if" check if index finally the same with char, if it's the same the function returning index
// c) Why is index++ being used? - it's increases index after each one while so we can't get stuck.
// d) What is the condition index < str.length used for? - function doesn't work if the index higher then str.lenght. So function can understands in which limits need to work.
Copy link
Contributor

Choose a reason for hiding this comment

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

For question (d), suppose str is "ABCD" and char is 'a'.

  1. What is the value of index in the last iteration of the while-loop?
  2. What is the value of index when the execution reaches line 10?

Why not try using an AI tool such as ChatGPT to check grammar in your writings?

Copy link
Author

Choose a reason for hiding this comment

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

yes, I know that chat GPT is good for grammar correction, but I use it every day for my work, and I don't have enough practice to use my own brain, and I can't pass my Duo Lingo test (Just 80%), it's mean that I would be able to move to the another CYF's level. That why I'm trying to use my brain in the lessons to train my self.
Thanks for understanding and sorry for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't encourage you to blindly copy the answer prepared by ChatGPT.
When I used ChatGPT to check grammar in my writing or improve my writing, it always explained why the corrected version was better. I find the explanation helpful in improving my writing skills.

function passwordValidator(password) {
return password.length < 5 ? false : true
function passwordValidator(password, passwords) {
password.length < 5;
Copy link
Contributor

Choose a reason for hiding this comment

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

This statement does not do anything except comparing two values.

As a result, your function would not be able to return false when the given password is "Aa1$".

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

You must breakdown this problem in order to solve it. Find one test case first and get that working
*/
const isValidPassword = require("./password-validator");

Copy link
Contributor

Choose a reason for hiding this comment

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

The Jest test code is missing in this file.

Copy link
Author

Choose a reason for hiding this comment

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

Added

Comment on lines +11 to +17
function cardValidator (card_number) {
if (card_number.length === 16) {
return true;
} else {
return false;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In the card validation exercise, there are other requirements for a card number to be considered valid.
As this is the "stretch" part of the exercise, you can complete the implementation of this function when you have time.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed 👀 Review Git Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Mar 30, 2025
@MarynaRomashca
Copy link
Author

@cjyuan Dear Cjyuan, I fixed all mistakes, please review it.
I did not do the stretch as you mentioned, that I can do it later, when I have a time.
Thanks a lot for your time!

@MarynaRomashca MarynaRomashca added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Apr 4, 2025
Copy link
Contributor

@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 think getCardValue() can still use some improvement.

Comment on lines 26 to 29
// // Case 5: Handle Invalid Cards:
test("Handle Invalid Cards", () => {
expect(() => getCardValue("Z♥")).toThrow("Invalid");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you include these test values in this test, and then run this script using Jest? I don't think your script can recognise them as invalid cases (because of the way strings are compared).

getCardValue("29♠");
getCardValue("2.1♠");

If you have installed Jest, you can run this particular test script as npx jest 3-get-card-value.test.js in the folder where this file is located.

Copy link
Author

Choose a reason for hiding this comment

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

All tests pass !

test("should return '3rd' for 3", () => {


test("should return '3rd' for 3 and more", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The description of this test is not yet updated accordingly.

Copy link
Author

Choose a reason for hiding this comment

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

You are right.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Apr 4, 2025
@MarynaRomashca
Copy link
Author

@cjyuan All updated. Please approve it.

Copy link
Contributor

@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.

getCardValue() is solid now.

One of the test descriptions could be improved. You can mark this as "Complete" after you update the description.



test("should return '3rd' for 3 and more", () => {
test("should return all mentioned test bellow", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This description does not tell what is being tested in this particular test.

When there is an error, Jest will display this message but not all of the code at lines 14-16. The person running the test would have to take an extra step to view the code in the test script to find out what the tests are about.

@MarynaRomashca MarynaRomashca added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Volunteer to add when work is complete and all review comments have been addressed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants