Skip to content

Commit 37c977d

Browse files
authored
Update tests resistor color trio (#2726)
* Sync test.toml * Update test file * Update proof solution * Running format.mjs
1 parent b53c860 commit 37c977d

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

exercises/practice/resistor-color-trio/.meta/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"SleeplessByte"
44
],
55
"contributors": [
6-
"hayashi-ay"
6+
"hayashi-ay",
7+
"jagdish-15"
78
],
89
"files": {
910
"solution": [

exercises/practice/resistor-color-trio/.meta/proof.ci.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const COLORS = [
1212
];
1313

1414
const ONE_KILOOHM = 1000;
15+
const ONE_MEGAOHM = 1000000;
16+
const ONE_GIGAOHM = 1000000000;
1517

1618
class ArgumentError extends Error {}
1719

@@ -44,9 +46,18 @@ export class ResistorColorTrio {
4446

4547
toString() {
4648
const value = this.value;
47-
return value < ONE_KILOOHM
48-
? `${value} ohms`
49-
: `${Math.floor(value / ONE_KILOOHM)} kiloohms`;
49+
50+
if (value >= ONE_GIGAOHM) {
51+
return `${Math.floor(value / ONE_GIGAOHM)} gigaohms`;
52+
}
53+
if (value >= ONE_MEGAOHM) {
54+
return `${Math.floor(value / ONE_MEGAOHM)} megaohms`;
55+
}
56+
if (value >= ONE_KILOOHM) {
57+
return `${Math.floor(value / ONE_KILOOHM)} kiloohms`;
58+
}
59+
60+
return `${value} ohms`;
5061
}
5162

5263
/**

exercises/practice/resistor-color-trio/.meta/tests.toml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

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

1724
[f5d37ef9-1919-4719-a90d-a33c5a6934c9]
1825
description = "Yellow and violet and yellow"
26+
27+
[5f6404a7-5bb3-4283-877d-3d39bcc33854]
28+
description = "Blue and violet and blue"
29+
30+
[7d3a6ab8-e40e-46c3-98b1-91639fff2344]
31+
description = "Minimum possible value"
32+
33+
[ca0aa0ac-3825-42de-9f07-dac68cc580fd]
34+
description = "Maximum possible value"
35+
36+
[0061a76c-903a-4714-8ce2-f26ce23b0e09]
37+
description = "First two colors make an invalid octal number"
38+
39+
[30872c92-f567-4b69-a105-8455611c10c4]
40+
description = "Ignore extra colors"

exercises/practice/resistor-color-trio/resistor-color-trio.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,36 @@ describe('Resistor Color Trio', () => {
3636
);
3737
});
3838

39+
xtest('Blue and violet and blue', () => {
40+
expect(new ResistorColorTrio(['blue', 'violet', 'blue']).label).toEqual(
41+
makeLabel({ value: 67, unit: 'megaohms' }),
42+
);
43+
});
44+
45+
xtest('Minimum possible value', () => {
46+
expect(new ResistorColorTrio(['black', 'black', 'black']).label).toEqual(
47+
makeLabel({ value: 0, unit: 'ohms' }),
48+
);
49+
});
50+
51+
xtest('Maximum possible value', () => {
52+
expect(new ResistorColorTrio(['white', 'white', 'white']).label).toEqual(
53+
makeLabel({ value: 99, unit: 'gigaohms' }),
54+
);
55+
});
56+
57+
xtest('First two colors make an invalid octal number', () => {
58+
expect(new ResistorColorTrio(['black', 'grey', 'black']).label).toEqual(
59+
makeLabel({ value: 8, unit: 'ohms' }),
60+
);
61+
});
62+
63+
xtest('Ignore extra colors', () => {
64+
expect(
65+
new ResistorColorTrio(['blue', 'green', 'yellow', 'orange']).label,
66+
).toEqual(makeLabel({ value: 650, unit: 'kiloohms' }));
67+
});
68+
3969
// optional: error
4070
xtest('Invalid color', () => {
4171
expect(

0 commit comments

Comments
 (0)