Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exercises/practice/resistor-color-trio/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"SleeplessByte"
],
"contributors": [
"hayashi-ay"
"hayashi-ay",
"jagdish-15"
],
"files": {
"solution": [
Expand Down
17 changes: 14 additions & 3 deletions exercises/practice/resistor-color-trio/.meta/proof.ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const COLORS = [
];

const ONE_KILOOHM = 1000;
const ONE_MEGAOHM = 1000000;
const ONE_GIGAOHM = 1000000000;

class ArgumentError extends Error {}

Expand Down Expand Up @@ -44,9 +46,18 @@ export class ResistorColorTrio {

toString() {
const value = this.value;
return value < ONE_KILOOHM
? `${value} ohms`
: `${Math.floor(value / ONE_KILOOHM)} kiloohms`;

if (value >= ONE_GIGAOHM) {
return `${Math.floor(value / ONE_GIGAOHM)} gigaohms`;
}
if (value >= ONE_MEGAOHM) {
return `${Math.floor(value / ONE_MEGAOHM)} megaohms`;
}
if (value >= ONE_KILOOHM) {
return `${Math.floor(value / ONE_KILOOHM)} kiloohms`;
}

return `${value} ohms`;
}

/**
Expand Down
28 changes: 25 additions & 3 deletions exercises/practice/resistor-color-trio/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[d6863355-15b7-40bb-abe0-bfb1a25512ed]
description = "Orange and orange and black"
Expand All @@ -16,3 +23,18 @@ description = "Green and brown and orange"

[f5d37ef9-1919-4719-a90d-a33c5a6934c9]
description = "Yellow and violet and yellow"

[5f6404a7-5bb3-4283-877d-3d39bcc33854]
description = "Blue and violet and blue"

[7d3a6ab8-e40e-46c3-98b1-91639fff2344]
description = "Minimum possible value"

[ca0aa0ac-3825-42de-9f07-dac68cc580fd]
description = "Maximum possible value"

[0061a76c-903a-4714-8ce2-f26ce23b0e09]
description = "First two colors make an invalid octal number"

[30872c92-f567-4b69-a105-8455611c10c4]
description = "Ignore extra colors"
30 changes: 30 additions & 0 deletions exercises/practice/resistor-color-trio/resistor-color-trio.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ describe('Resistor Color Trio', () => {
);
});

xtest('Blue and violet and blue', () => {
expect(new ResistorColorTrio(['blue', 'violet', 'blue']).label).toEqual(
makeLabel({ value: 67, unit: 'megaohms' }),
);
});

xtest('Minimum possible value', () => {
expect(new ResistorColorTrio(['black', 'black', 'black']).label).toEqual(
makeLabel({ value: 0, unit: 'ohms' }),
);
});

xtest('Maximum possible value', () => {
expect(new ResistorColorTrio(['white', 'white', 'white']).label).toEqual(
makeLabel({ value: 99, unit: 'gigaohms' }),
);
});

xtest('First two colors make an invalid octal number', () => {
expect(new ResistorColorTrio(['black', 'grey', 'black']).label).toEqual(
makeLabel({ value: 8, unit: 'ohms' }),
);
});

xtest('Ignore extra colors', () => {
expect(
new ResistorColorTrio(['blue', 'green', 'yellow', 'orange']).label,
).toEqual(makeLabel({ value: 650, unit: 'kiloohms' }));
});

// optional: error
xtest('Invalid color', () => {
expect(
Expand Down