|
| 1 | +# Resistor Color |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +These colors are encoded as follows: |
| 6 | + |
| 7 | +- Black: 0 |
| 8 | +- Brown: 1 |
| 9 | +- Red: 2 |
| 10 | +- Orange: 3 |
| 11 | +- Yellow: 4 |
| 12 | +- Green: 5 |
| 13 | +- Blue: 6 |
| 14 | +- Violet: 7 |
| 15 | +- Grey: 8 |
| 16 | +- White: 9 |
| 17 | + |
| 18 | +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. |
| 19 | + |
| 20 | +More information on the color encoding of resistors can be found in the [Electronic color code Wikipedia article](https://en.wikipedia.org/wiki/Electronic_color_code) |
| 21 | + |
| 22 | +## Exception messages |
| 23 | + |
| 24 | +Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to |
| 25 | +indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not |
| 26 | +every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include |
| 27 | +a message. |
| 28 | + |
| 29 | +To raise a message with an exception, just write it as an argument to the exception type. For example, instead of |
| 30 | +`raise Exception`, you should write: |
| 31 | + |
| 32 | +```python |
| 33 | +raise Exception("Meaningful message indicating the source of the error") |
| 34 | +``` |
| 35 | + |
| 36 | +## Running the tests |
| 37 | + |
| 38 | +To run the tests, run `pytest resistor_color_test.py` |
| 39 | + |
| 40 | +Alternatively, you can tell Python to run the pytest module: |
| 41 | +`python -m pytest resistor_color_test.py` |
| 42 | + |
| 43 | +### Common `pytest` options |
| 44 | + |
| 45 | +- `-v` : enable verbose output |
| 46 | +- `-x` : stop running tests on first failure |
| 47 | +- `--ff` : run failures from previous test before running other test cases |
| 48 | + |
| 49 | +For other options, see `python -m pytest -h` |
| 50 | + |
| 51 | +## Submitting Exercises |
| 52 | + |
| 53 | +Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/resistor-color` directory. |
| 54 | + |
| 55 | +You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`. |
| 56 | + |
| 57 | +For more detailed information about running tests, code style and linting, |
| 58 | +please see [Running the Tests](http://exercism.io/tracks/python/tests). |
| 59 | + |
| 60 | +## Source |
| 61 | + |
| 62 | +Maud de Vries, Erik Schierboom [https://github.com/exercism/problem-specifications/issues/1458](https://github.com/exercism/problem-specifications/issues/1458) |
| 63 | + |
| 64 | +## Submitting Incomplete Solutions |
| 65 | + |
| 66 | +It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
0 commit comments