Skip to content

Manchester | 26-ITP-JAN | Abdu Mussa | Sprint 3 | 2-practice-tdd-complete#1174

Open
Abduhasen wants to merge 4 commits intoCodeYourFuture:mainfrom
Abduhasen:coursework/sprint-3-practice-tdd
Open

Manchester | 26-ITP-JAN | Abdu Mussa | Sprint 3 | 2-practice-tdd-complete#1174
Abduhasen wants to merge 4 commits intoCodeYourFuture:mainfrom
Abduhasen:coursework/sprint-3-practice-tdd

Conversation

@Abduhasen
Copy link

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

writing a function and testing the function.

Questions

N/A

@Abduhasen Abduhasen added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Structuring-And-Testing-Data The name of the module. labels Mar 4, 2026
Comment on lines +29 to +32
// Case 1: Numbers ending with 1 (but not 11)
// When the number ends with 1, except those ending with 11,
// Then the function should return a string by appending "st" to the number.
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

These comments do not match the test being carried out. Do you still need these comments?

The same comments appear at several places 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.

I did the first one and i cope and pasted it to save time but I forgot to change the cases i was doing

Comment on lines +33 to +43
test("should repeat the string is empty ", () => {
let word = "hello";
let times = 0;
const repeatedStr = repeatStr(word, times);
expect(repeatedStr).toBe("");
});
// Case: Handle negative count:
// Given a target string `str` and a negative integer `count`,
// When the repeatStr function is called with these inputs,
// Then it should throw an error, as negative counts are not valid.
test("should repeat the string return negative number not allowed ", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

These two test descriptions do not quite make sense.

Can you rephrase them, for example, in the format: should <expected_behavior> when <condition> ?

// When the repeatStr function is called with these inputs,
// Then it should return the original `str` without repetition.

test("should repeat the string count times", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about should return the original string when count is 1 (so that the description won't duplicate)?

Copy link
Author

Choose a reason for hiding this comment

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

It was not correctly described at first now it's fixed.

@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 Mar 14, 2026
@Abduhasen Abduhasen added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 14, 2026
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.

Changes look good. I just spotted something I missed in my previous review.

if (times > 0) {
return word.repeat(times);
} else if (times < 0) {
return "Error:negative number not allowed";
Copy link
Contributor

Choose a reason for hiding this comment

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

I overlooked this in my previous review.

When a function that is expected to return a string is designed to return a string on error,
how should the caller distinguish the return value of these two function calls?

  • repeatStr("Error:negative number not allowed", 1)
  • repeatStr("Hello World", -1)

They both return the same value.


The requirement is "to throw an error when count is negative". Can you update this implementation and the Jest test accordingly?

Copy link
Author

Choose a reason for hiding this comment

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

I changed the function and implemented jest test case for negative numbers.

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 14, 2026
@Abduhasen Abduhasen added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 14, 2026
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.

Changes look good.

// Given a target string `str` and a negative integer `count`,
// When the repeatStr function is called with these inputs,
// Then it should throw an error, as negative counts are not valid.
test("should return a string 'negative number not allowed' when negative number passed", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should also update the test description as well.

Copy link
Author

Choose a reason for hiding this comment

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

It is fixed now thank you very much for the feed backs

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 14, 2026
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. Module-Structuring-And-Testing-Data The name of the module. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants