ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

# neiesc's solution

## to Resistor Color in the C# Track

Published at Mar 27 2019 · 0 comments
Instructions
Test suite
Solution

#### Note:

This exercise has changed since this solution was written.

Resistors have color coded bands, where each color maps to a number. The first 2 bands of a resistor have a simple encoding scheme: each color maps to a single number.

These colors are encoded as follows:

• Black: 0
• Brown: 1
• Red: 2
• Orange: 3
• Yellow: 4
• Green: 5
• Blue: 6
• Violet: 7
• Grey: 8
• White: 9

Mnemonics map the colors to the numbers, that, when stored as an array, happen to map to their index in the array: Better Be Right Or Your Great Big Values Go Wrong.

More information on the color encoding of resistors can be found in the Electronic color code Wikipedia article

## Running the tests

To run the tests, run the command `dotnet test` from within the exercise directory.

Initially, only the first test will be enabled. This is to encourage you to solve the exercise one step at a time. Once you get the first test passing, remove the `Skip` property from the next test and work on getting that test passing. Once none of the tests are skipped and they are all passing, you can submit your solution using `exercism submit ResistorColor.cs`

## Further information

For more detailed information about the C# track, including how to get help if you're having trouble, please visit the exercism.io C# language page.

## Source

Maud de Vries, Erik Schierboom https://github.com/exercism/problem-specifications/issues/1458

### ResistorColorTest.cs

``````// This file was auto-generated based on version 1.0.0 of the canonical data.

using Xunit;

public class ResistorColorTest
{
[Fact]
public void Black()
{
Assert.Equal(0, ResistorColor.ColorCode("black"));
}

[Fact(Skip = "Remove to run test")]
public void White()
{
Assert.Equal(9, ResistorColor.ColorCode("white"));
}

[Fact(Skip = "Remove to run test")]
public void Orange()
{
Assert.Equal(3, ResistorColor.ColorCode("orange"));
}

[Fact(Skip = "Remove to run test")]
public void Colors()
{
Assert.Equal(new[] { "black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white" }, ResistorColor.Colors());
}
}``````
``````ï»¿using System;

public static class ResistorColor
{
public static int ColorCode(string color)
{
return Array.FindIndex(Colors(), x => x == color);
}

public static string[] Colors()
{
return new[] { "black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white" };
}
}``````