Skip to content

London | 26-ATP-Jan | Boualem Larbi Djebbour | Sprint 2 | coursework#1188

Open
djebsoft wants to merge 15 commits intoCodeYourFuture:mainfrom
djebsoft:sprint-2/coursework
Open

London | 26-ATP-Jan | Boualem Larbi Djebbour | Sprint 2 | coursework#1188
djebsoft wants to merge 15 commits intoCodeYourFuture:mainfrom
djebsoft:sprint-2/coursework

Conversation

@djebsoft
Copy link
Copy Markdown

@djebsoft djebsoft commented Apr 8, 2026

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

completed sprint-2 exercies in data groups module.

Questions

@github-actions

This comment has been minimized.

@djebsoft djebsoft added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 8, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 8, 2026
@djebsoft djebsoft changed the title London | 26-ATP-Jan | Boualem Larbi Djebbour | Sprint 2/coursework London | 26-ATP-Jan | Boualem Larbi Djebbour | Sprint 2 | coursework Apr 8, 2026
@djebsoft djebsoft added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 8, 2026
Comment on lines 45 to +50
// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
test("given invalid parameters, returns false or throws an error", () => {
expect(contains(["gitName", "position"], "gitName")).toEqual(false);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test does not yet confirm that the function correctly returns false when the first argument is an array.
This is because contains(["gitName", "position"], "gitName") could also return false simply because "gitName" is not a key of the array.

Arrays are objects, with their indices acting as keys. A proper test should use a valid
key to ensure the function returns false specifically because the input is an array, not because the key is missing.

After you fixed this test, make sure you also run the test to check your function.

Note: When testing invalid type of data, undefined and null are usually good candidates to test -- many functions fail because they could not handle undefined or null.

Copy link
Copy Markdown
Author

@djebsoft djebsoft Apr 9, 2026

Choose a reason for hiding this comment

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

thank you for the feedback
I just realised that the false returned cases should be the exception, so I changed the if condition to the other way around.
I removed the case of empty object (object length equals to zero) as it does not add any plus to the code.
I also added the case where the input is an array to return false.
and run the test to check the function.
added a test with null input for invalid type of data.

Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Apr 9, 2026

Choose a reason for hiding this comment

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

Why not also update the test (the one that tests array)?

Your function is correct, but we write tests not only to verify our current implementation, but also to ensure that future changes do not alter the function's expected behavior.

Copy link
Copy Markdown
Author

@djebsoft djebsoft Apr 9, 2026

Choose a reason for hiding this comment

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

thanks for the spot
sorry that I got confused about this point
i think the perfect example test is to test tricky arguments where the first argument looks like an object by having two elements and the second argument is string that match one the elements in the first argument
therefore, if the first argument wasn't an array than the test should return true. but because it an array, the function returns false as invalid input.
could you enlighten me about what I'm mistaken here ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

expect(contains(["gitName", "position"], "gitName")).toEqual(false);

The following function (changed in the future by someone else) could also pass the above test:

function contains(obj, key) {
    if (obj == null || typeof obj != "object") return false;
    return Object.hasOwn(obj, key);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test is supposed to fail when the function is implemented as:

function contains(obj, key) {
    if (obj == null || typeof obj != "object") return false;
    return Object.hasOwn(obj, key);
}

The new test still behaves the same as the previous one.

Arrays are objects, with their indices acting as keys. You should use a valid
key
to ensure the function returns false specifically because the input is an array, not because the key is missing.

@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 9, 2026
@djebsoft djebsoft added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Apr 9, 2026
@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 9, 2026
@djebsoft djebsoft 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 9, 2026
@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 9, 2026
@cjyuan cjyuan added the Reviewed Volunteer to add when completing a review with trainee action still to take. label Apr 9, 2026
@djebsoft djebsoft 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 9, 2026
@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 9, 2026
@djebsoft djebsoft 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 9, 2026
@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. labels Apr 10, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants