Skip to content

London | 26-ITP-Sep | Diana Ausiejute | Sprint 2 | Practice TDD - #1712

Open
ausiejute wants to merge 7 commits into
CodeYourFuture:mainfrom
ausiejute:coursework/sprint-2-practice-tdd
Open

ausiejute wants to merge 7 commits into
CodeYourFuture:mainfrom
ausiejute:coursework/sprint-2-practice-tdd

Conversation

@ausiejute

Copy link
Copy Markdown

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

Task code

CYF-1060

Changelist

Implemented functions and wrote required tests in Jest for 'Count', 'Repeat string' and 'Get ordinal number' exercises.

@ausiejute ausiejute added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 15, 2026
@hackertainment hackertainment 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 Oct 19, 2026

@hackertainment hackertainment left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you for your coursework. Please keep it up.

Comment on lines 13 to 18
test("should count multiple occurrences of a character", () => {
const str = "aaaaa";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(5);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a special case of str where it is all the char to count. Would it still count correctly if the char just exists in some part of the str?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This proves i still have a long way to go in developing an eye for detail when looking at code

Comment on lines +26 to +31
test("should count zero occurrences of a character", () => {
const str = "aaaa";
const char = "b";
const count = countChar(str, char);
expect(count).toEqual(0);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is a special str that would give 0 anyway. Please add that test case as well. Thank you.

Comment on lines +34 to +38
test("should append 'th' for the rest of the numbers", () => {
expect(getOrdinalNumber(9)).toEqual("9th");
expect(getOrdinalNumber(20)).toEqual("20th");
expect(getOrdinalNumber(108)).toEqual("108th");
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lines 13-15 of your code has not been included in this test suite. Please add test cases specifically for that part of the code. Thank you.

@hackertainment hackertainment Oct 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see you have added 11th, 12th, and 13th. Just it would be better to also include 3-digit number (e.g. 211th, 112th, and 213) ended in 11 or 12 or 13 as well. I will let you pass this time because your code is correct, but please improve test cases coverage in the future. Thank you.

Comment on lines +4 to +6
if (Number.isInteger(count) && count < 0) {
throw new Error(`Invalid input`);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think this part is accurate. Consider count = 4.5, would the result be the same as expected?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for that! You got me reading about the distinction between the tasks where one is required to take what's given and implement to handle only specific cases, and where one has to handle edge cases, validate inputs, throw errors for invalid.. . If the task required me to 'Handle edge cases' or, more specifically, 'handle non-integers', then it would be a must to rewrite my implementation and add a test accordingly. I would change that part into if (!Number.isInteger(count) || count < 0) { throw new Error(Invalid input); }

Comment on lines 12 to +41
test("should repeat the string count times", () => {
const str = "hello";
const count = 3;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("hellohellohello");
});

// Case: handle count of 1:
// Given a target string `str` and a `count` equal to 1,
// When the repeatStr function is called with these inputs,
// Then it should return the original `str` without repetition.

test("should repeat the string 1 time", () => {
const str = "hello";
const count = 1;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("hello");
});

// Case: Handle count of 0:
// Given a target string `str` and a `count` equal to 0,
// When the repeatStr function is called with these inputs,
// Then it should return an empty string.

test("should repeat the string 0 times", () => {
const str = "hello";
const count = 0;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("");
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your test cases are correct. Just for you to think a little bit more, besides const str = "hello", what special string should also be added to each of the test cases?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

An empty string, thank you:)

@hackertainment hackertainment added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 19, 2026
@ausiejute ausiejute added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 20, 2026
@hackertainment

Copy link
Copy Markdown

Congratulation, you have completed this PR successfully.

@hackertainment hackertainment 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 Oct 20, 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. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants