-
-
Notifications
You must be signed in to change notification settings - Fork 262
Glasgow | 25-ITP-SEP | Alaa Tagi | Sprint 3 | Coursework/sprint 3 practice tdd #758
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?
Glasgow | 25-ITP-SEP | Alaa Tagi | Sprint 3 | Coursework/sprint 3 practice tdd #758
Conversation
jennethydyrova
left a comment
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.
Hi @Alaa-Tagi! Great job on translating instructions into functions. It was quite easy to read your PR, which is always a good thing for a reviewer!
A couple of things to note:
- You should try to remove all your testing and scratch work when pushing a PR (mostly console logs in your case).
- Test cases need to be more comprehensive. Think of it this way: when you write different test cases for your functions, you help yourself catch bugs early. For example, currently your
getOrdinalNumberfunction will most likely return"trueth"fornum=true, which I don't think is the expected behavior.
Sprint-3/2-practice-tdd/count.js
Outdated
| console.log(countChar('hello', 'l')); | ||
| console.log(countChar('hello', 'z')); | ||
| console.log(countChar('alaaaaa', 'a')); | ||
|
|
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.
Let's keep the PR clean and focused. Could you please remove all console logs from your PR?
| // When the function is called with these inputs, | ||
| // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. | ||
|
|
||
| test("should return 0 for no occurrences", () => { |
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.
This test is good but it doesn't test different possible function inputs. What if the inputs' types are not strings, the char string is longer than the str string, or you have an empty string for either of the inputs, etc.? Testing different inputs will show whether your function accounts for different scenarios, which is what makes a function robust.
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| num = num.toString(); | ||
| if (num.slice(-2) === '11' || num.slice(-2) === '12' || num.slice(-2) === '13') { |
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 there way not to repeat num.slice(-1) and num.slice(-2)?
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| }); | ||
|
|
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 like these test cases but again, what are other expected/unexpected inputs your function can receive and how will it behave? For example, what if num is undefined, a boolean, etc.? That's just two examples of num being not of a type you expect.
Sprint-3/2-practice-tdd/repeat.js
Outdated
| const str = arguments[0]; | ||
| const count = arguments[1]; |
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.
Are you sure this is the right way of getting values of function arguments?
| // When the repeat function is called with these inputs, | ||
| // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. | ||
|
|
||
| test("should return the original string when count is 1", () => { |
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.
This test suit are more comprehensive but can you think of other test cases?
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.
Hi @jennethydyrova i have fixed all the errors that you have mentioned to me.
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.
Have you tried running the tests you wrote?
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.
If you try to run your unit tests, you will see that some of them are failing both for this function and getOrdinalNumber. Can you try to fix tests/functions by reading output produced when you run tests?
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, I have and it passed all the tests.
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 unit tests in your screenshots do not match those in the PR. Take a look at Sprint-3/2-practice-tdd/get-ordinal-number.test.js file, for example. Your last test in this PR is
test("should handle decimal numbers", () => {
expect(getOrdinalNumber(21.5)).toEqual("21.5th");
});
and on the screenshot you sent the last test is
test("should return '33rd' for 33", () => {
expect(getOrdinalNumber(33)).toEqual("33rd");
});
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.
@jennethydyrova,
I have edited this code if you could check down
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.
Please always double check if you pushed your local changes, deleted all scratch work (including console logs) and ran all unit tests before requesting another round of review. It will reduce time I spend on reviewing your code and you going back to the same PR over and over again. File changes tab is quite useful for checking if you code is up to standard.
I don't see any new changes. I assume you made some local changes but you haven't pushed them.
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.
@jennethydyrova, I am sorry and I appreciate your time. But I am so confused too I make the changes, do push as usual and in here every thing appears.
Like this pic here it shows that the changes has been push and I do not see any unstage files.
Thanks for you patient with me
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.
No worries. Okay, I can see these changes and I can see from the function implementation, that this particular unit test on the screenshot you sent will fail but you can understand this by just running unit tests. You have these changes locally, right? If you have same changes locally and you run unit tests, some of them will fail in Sprint-3/2-practice-tdd folder indicating that some more work needs to be done.
| // Scenario: char string longer than str string | ||
| test("should return 0 when char is longer than the input string", () => { | ||
| const str = "a"; | ||
| const char = "abc"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); | ||
|
|
||
| // Scenario: Non-string inputs | ||
| test("should return 0 when inputs are not strings", () => { | ||
| expect(countChar(12345, "1")).toEqual(0); | ||
| expect(countChar("12345", 1)).toEqual(0); | ||
| expect(countChar(null, "a")).toEqual(0); | ||
| expect(countChar("hello", undefined)).toEqual(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.
This is fine but when you read this function's purpose, you might think that if char is longer than str, it should perhaps throw an error as there is no way to count char occurrence in this case. It's fine to leave Scenario: char string longer than str string test case as is but it's something to consider while designing your function.
Same for Scenario: Non-string inputs but this test case should definitely throw errors.
| }); | ||
|
|
||
| // Scenario: Case sensitivity | ||
| test("should count only exact case matches", () => { |
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.
Very thoughtful test case!
| console.log(getOrdinalNumber(1)); | ||
| console.log(getOrdinalNumber(2)); | ||
| console.log(getOrdinalNumber(3)); | ||
| console.log(getOrdinalNumber(4)); | ||
| console.log(getOrdinalNumber(11)); | ||
| console.log(getOrdinalNumber(22)); | ||
| console.log(getOrdinalNumber(33)); |
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.
Please let's remove these and all other console logs. These should be for your usage only and they should be deleted before pushing changes.
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.
okay, i did that. it was on my mind but i forgot to remove them before push it
| test("should handle undefined inputs gracefully", () => { | ||
| expect(() => repeat(undefined, 3)).toThrow(); | ||
| expect(() => repeat("hello")).toThrow(); | ||
| expect(() => repeat()).toThrow(); | ||
| }); |
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.
This doesn't look correct to me. Your function doesn't throw any errors in the cases you wrote here.
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 fixed the 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.
@jennethydyrova , Here the new code ( Editied )
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 have editing both get ordinal and repeat code . also i have tried both tests with different laptop it showed failed but in my laptop showed passed i dont know why but i will figure it out later. so, i editing the two codes and tried to run them on another laptop it show passed to all test after editing . |
|
Looks good to me, good job! Regarding not having same code on both computers, double check if you pull all changes from branch. If you work on one laptop and then continue on another one, your changes will not be automatically pulled. |

Learners, PR Template
Self checklist
Changelist
I have created a PR with completed tasks as required.
Questions
No questions