Resistor-color.test.ts enforces specific implementation and is not compliant with CONTRIBUTING.md

Removed assertion for the colors data structure and implemented tests for remaining colors

COLORS type should not be asserted if not explicitly typed in the template or mentioned in the docs

By asserting the structure of the data type this prevents correct solutions from passing the test and restricts developer freedom.

Asserting that colors is an string array makes the following data structure trigger a failure even if the colorCode method produces the correct result;

export const COLORS: { color: string; code: number }[] = [
  { color: "black", code: 0 },
  { color: "brown", code: 1 },
  { color: "red", code: 2 },
  { color: "orange", code: 3 },
  { color: "yellow", code: 4 },
  { color: "green", code: 5 },
  { color: "blue", code: 6 },
  { color: "violet", code: 7 },
  { color: "grey", code: 8 },
  { color: "white", code: 9 },
];

For reference, OP made the two PRs below in association with the post.

I’m not the TypeScript maintainer, but it’s worth noting that the tests for Resistor Color and almost all other practice exercises come from the upstream problem specifications repo that all 75+ Exercism tracks use to implement an exercise. Are you wanting to make this change specifically for the TypeScript implementation or to the problem specifications repo? The latter would involve a forum discussion and explicit approval from multiple maintainers to proceed with a PR. If it’s just the TypeScript implementation, it’s up to the track maintainers if they want to proceed.

From what I recall, this exercise was initially created as a simple array-focused exercise. Removing the COLORS test completely would remove that focus since there are plenty of ways to solve the exercise without using an array whether you use COLORS in colorCode or not.

3 Likes

Thank you for your post. I also saw the PRs (and added small response).

At the moment we have at least 4 different ways of constructing the COLORS array, so this does not “break the rules”. This set of exercises was written to teach people about arrays, indexing, etc., across multiple tracks.

We will not accept a PR to change this specific exercise to have a looser type. Exporting the known colours is part of the task, and that can only be tested if we limit the type.

3 Likes

The tests do not dictate implementation. You can implement the function internally any way you want. The test dictates that a variable of a specific type exists.

2 Likes

oop this was an accident - did not mean to publish multiple PR’s.

I understand my misinterpretation of the rules and appreciate the quick responses!

I will close my PR’s if they have not already been closed - going to review the comments from @SleeplessByte now!

Thanks everyone - again apologies for the misunderstanding on my part.

2 Likes

No worries, on the TS track this happens automatically!

We do appreciate you wanting to contribute so please feel free to open another forum post if you want to contribute a change, and feel free to ask here if you have more questions.

2 Likes