Join us on Meetup! http://www.meetup.com/xDD-CLE/
The Romans wrote their numbers with I, V, X, L, C, D, M. The straight lines made them easy to carve into stone.
Each character has a value:
I --> 1
V --> 5
X --> 10
L --> 50
C --> 100
D --> 500
M --> 1000
The numerals can also be combined to create numbers like so:
II --> 2
IIII --> 4
VI --> 6
LXVI --> 66
XVIIII --> 19
Your task is to create a function to convert numbers into roman numerals. The goal here is to practice TDD, so follow these steps.
- Write a failing test for the simplest case.
- Make the test pass.
- Shape the code with another failing test.
- Make that test pass, too.
- Refactor your code using your tests as a regression suite.
- Repeat steps 3-5 until a solution has emerged naturally!
Some tips!
- Always start by thinking about the design of your code.
- Write the code you wish you had, then build it!
- Write the simplest code you can to make each test pass.
- Avoid creating abstractions until you've learned as much as you can about the problem.
- Favor duplication until the abstractions become clear.
- Don't write any "I'm going to need this later" logic. If you need it, then write a test to describe it first.
- Try to write the code without conditionals!
- Refactor your code into the most elegant or terse solution you can. This MAY NOT produce the most ideal solution for maintainability, but you will be able to see the trade offs, and you might learn about a new library function!
- Write a function to convert roman numeral strings into numbers
- Write functions for conversions using 'subtractive notation'. This means that instead of writing
IIII
you writeIV
.
We've provided starting places for the following languages. They include a sample "prove the world exists" test. Feel free to delete that as you develop your test suite.
- Ruby
- Install Ruby
- Optional
- Bundler
gem install bundler
- Navigate to the ruby directory
bundle install
- Add tests under spec
- Add code under lib
- Run tests:
rspec
- Node.js + NPM
- Install Node.js
- Optional
- Navigate to the javascript directory
npm install
- Add tests under test
- Add code under lib
- Run tests:
npm test
- Elixir
- Navigate to the elixir directory
mix compile
- Add tests under test
- Add code under lib
- Run tests:
mix test