Skip to content

Manchester | 26-ITP-Sep | Mathew Shaibu | Sprint 2 | Module data group sprint 2 - #1499

Open
MattCarolus10 wants to merge 60 commits into
CodeYourFuture:mainfrom
MattCarolus10:Module-data-group-sprint-2
Open

MattCarolus10 wants to merge 60 commits into
CodeYourFuture:mainfrom
MattCarolus10:Module-data-group-sprint-2

Conversation

@MattCarolus10

Copy link
Copy Markdown

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-1083

Changelist

I completed debugging task, implemented test and created function and interpreted codes

@Liam310 Liam310 added Reviewed Volunteer to add when completing a review with trainee action still to take. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 9, 2026
// implementation here
function createLookup(countryCurrencyPairs) {
const lookup = {};
for (const [country, currency] of countryCurrencyPairs) {

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.

Neat use of array destructuring!

Comment on lines +3 to +10
test("creates a country currency code lookup for multiple codes", () => {
expect(
createLookup([
["US", "USD"],
["CA", "CAD"],
])
).toEqual({ US: "USD", CA: "CAD" });
});

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.

One test is rarely enough to comprehensively cover all behaviours of a function. Can you think of what some other good test cases might be?

Comment thread Sprint-2/implement/querystring.js Outdated
Comment on lines +11 to +12
const k = decodeURIComponent(key.split("+").join(" "));
const v = decodeURIComponent(value.split("+").join(" "));

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.

Single-letter variable names are something we generally want to avoid - what would be more descriptive choices for these variable? What do k and v actually represent?

Comment thread Sprint-2/implement/tally.test.js Outdated
Comment on lines +4 to +11
test("tally on an empty array returns an empty object", () => {
expect(tally([])).toEqual({});
});

// Given a function called tally
// When passed an array of items
// Then it should return an object containing the count for each unique item
test("tally counts duplicate items", () => {
expect(tally(["a", "a", "a"])).toEqual({ a: 3 });
expect(tally(["a", "a", "b", "c"])).toEqual({ a: 2, b: 1, c: 1 });
});

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.

When building up tests with TDD, it isn't always as direct as "1 test per acceptance criteria". We want to think about the different behaviours of this function and increasing complexity of the inputs in small increments.

Your second test here contains two assertions which have notably different inputs. One of them has the same letter 3 times and that's it. The other one has multiple letters. You're checking two different things here:

  1. Can the function count multiple occurrences of the same letter?
  2. Can the function count occurrences of different letters?

Those are distinct behaviours, so they should be separate tests.

Comment on lines +14 to +17
expect(() => tally("banana")).toThrow("tally requires an array");
expect(() => tally(42)).toThrow("tally requires an array");
expect(() => tally()).toThrow("tally requires an array");
});

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.

A great example of using multiple assertions that are all checking the same behaviour - a non-array input.

Comment on lines +1 to +13
const invert = require("./invert.js");

test("swaps key with values", () => {
expect(invert({ x: 10, y: 20 })).toEqual({ 10: "x", 20: "y" });
});

test("handles single entry", () => {
expect(invert({ a: 1 })).toEqual({ 1: "a" });
});

test("handles an empty object", () => {
expect(invert({})).toEqual({});
});

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.

Extra credit for adding a test suite when we didn't ask! 🌟

Just a quick note on TDD test building. As I mentioned in an earlier comment, we want to start with simpler inputs and get more complex as we go. Here, your tests are all good but not in the right order. If you were building the function step-by-step with TDD, you'd have them in the exact reverse order.

You don't need to change this but I wanted to highlight it to remind you of good TDD practices.

@Liam310 Liam310 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 Nov 10, 2026
@Liam310

Liam310 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Hi @MattCarolus10 ! Sorry about the labels jumping around, I was using your PR to demonstrate a code review.

Good work overall, I've left some comments on a few things that could be improved. Take a look and let me know if you have any questions 🙂

@MattCarolus10 MattCarolus10 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants