Skip to content

Commit 0063246

Browse files
HuskyNatorlemoncurry
authored andcommitted
Implement Resistor Color Duo (exercism#1756)
* Implement Resistor Color Duo
1 parent aa1cc60 commit 0063246

8 files changed

Lines changed: 168 additions & 0 deletions

File tree

config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@
4949
"strings"
5050
]
5151
},
52+
{
53+
"slug": "resistor-color-duo",
54+
"uuid": "0ae1989d-df46-414d-ad1f-4bd0f0f78421",
55+
"core": false,
56+
"unlocked_by": "two-fer",
57+
"difficulty": 2,
58+
"topics": [
59+
"arrays",
60+
"strings",
61+
"enumerations"
62+
]
63+
},
5264
{
5365
"slug": "darts",
5466
"uuid": "4d400a44-b190-4a0c-affb-99fad8ea18da",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class ResistorColorDuo {
2+
private enum Color {
3+
black, brown, red, orange, yellow, green, blue, violet, grey, white;
4+
};
5+
6+
int value(String[] colors) {
7+
return 10 * Color.valueOf(colors[0]).ordinal() + Color.valueOf(colors[1]).ordinal();
8+
}
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.1.0
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Resistor Color Duo
2+
3+
If you want to build something using a Raspberry Pi, you'll probably use _resistors_. For this exercise, you need to know two things about them:
4+
5+
* Each resistor has a resistance value.
6+
* Resistors are small - so small in fact that if you printed the resistance value on them, it would be hard to read.
7+
To get around this problem, manufacturers print color-coded bands onto the resistors to denote their resistance values. Each band has a position and a numeric value. For example, if they printed a brown band (value 1) followed by a green band (value 5), it would translate to the number 15.
8+
9+
In this exercise you are going to create a helpful program so that you don't have to remember the values of the bands. The program will take color names as input and output a two digit number, even if the input is more than two colors!
10+
11+
12+
The band colors are encoded as follows:
13+
14+
- Black: 0
15+
- Brown: 1
16+
- Red: 2
17+
- Orange: 3
18+
- Yellow: 4
19+
- Green: 5
20+
- Blue: 6
21+
- Violet: 7
22+
- Grey: 8
23+
- White: 9
24+
25+
From the example above:
26+
brown-green should return 15
27+
brown-green-violet should return 15 too, ignoring the third color.
28+
29+
30+
## Setup
31+
32+
Go through the setup instructions for Java to install the necessary
33+
dependencies:
34+
35+
[https://exercism.io/tracks/java/installation](https://exercism.io/tracks/java/installation)
36+
37+
# Running the tests
38+
39+
You can run all the tests for an exercise by entering the following in your
40+
terminal:
41+
42+
```sh
43+
$ gradle test
44+
```
45+
46+
> Use `gradlew.bat` if you're on Windows
47+
48+
In the test suites all tests but the first have been skipped.
49+
50+
Once you get a test passing, you can enable the next one by removing the
51+
`@Ignore("Remove to run test")` annotation.
52+
53+
## Source
54+
55+
Maud de Vries, Erik Schierboom [https://github.com/exercism/problem-specifications/issues/1464](https://github.com/exercism/problem-specifications/issues/1464)
56+
57+
## Submitting Incomplete Solutions
58+
It's possible to submit an incomplete solution so you can see how others have
59+
completed the exercise.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apply plugin: "java"
2+
apply plugin: "eclipse"
3+
apply plugin: "idea"
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
testCompile "junit:junit:4.12"
11+
}
12+
13+
test {
14+
testLogging {
15+
exceptionFormat = 'full'
16+
events = ["passed", "failed", "skipped"]
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class ResistorColorDuo {
2+
int value(String[] colors) {
3+
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
4+
}
5+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import org.junit.Before;
2+
import org.junit.Test;
3+
import org.junit.Ignore;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class ResistorColorDuoTest {
8+
private ResistorColorDuo resistorColorDuo;
9+
10+
@Before
11+
public void setup() {
12+
resistorColorDuo = new ResistorColorDuo();
13+
}
14+
15+
@Test
16+
public void testBrownAndBlack() {
17+
String[] input = { "brown", "black" };
18+
int expected = 10;
19+
int actual = resistorColorDuo.value(input);
20+
21+
assertEquals(expected, actual);
22+
}
23+
24+
@Ignore("Remove to run test")
25+
@Test
26+
public void testBlueAndGrey() {
27+
String[] input = { "blue", "grey" };
28+
int expected = 68;
29+
int actual = resistorColorDuo.value(input);
30+
31+
assertEquals(expected, actual);
32+
}
33+
34+
@Ignore("Remove to run test")
35+
@Test
36+
public void testYellowAndViolet() {
37+
String[] input = { "yellow", "violet" };
38+
int expected = 47;
39+
int actual = resistorColorDuo.value(input);
40+
41+
assertEquals(expected, actual);
42+
}
43+
44+
@Ignore("Remove to run test")
45+
@Test
46+
public void testOrangeAndOrange() {
47+
String[] input = { "orange", "orange" };
48+
int expected = 33;
49+
int actual = resistorColorDuo.value(input);
50+
51+
assertEquals(expected, actual);
52+
}
53+
54+
@Ignore("Remove to run test")
55+
@Test
56+
public void testIgnoreAdditionalColors() {
57+
String[] input = { "green", "brown", "orange" };
58+
int expected = 51;
59+
int actual = resistorColorDuo.value(input);
60+
61+
assertEquals(expected, actual);
62+
}
63+
}

exercises/settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ include 'raindrops'
7676
include 'rational-numbers'
7777
include 'rectangles'
7878
include 'resistor-color'
79+
include 'resistor-color-duo'
7980
include 'reverse-string'
8081
include 'rna-transcription'
8182
include 'robot-name'

0 commit comments

Comments
 (0)