Skip to content

xDD-CLE/roman-numerals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

xDD Cleveland

Join us on Meetup! http://www.meetup.com/xDD-CLE/

Roman Numerals Kata

What is a Roman Numeral?

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

The Kata

Your task is to create a function to convert numbers into roman numerals. The goal here is to practice TDD, so follow these steps.

  1. Write a failing test for the simplest case.
  2. Make the test pass.
  3. Shape the code with another failing test.
  4. Make that test pass, too.
  5. Refactor your code using your tests as a regression suite.
  6. 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.

Extra Credit

  1. Try to write the code without conditionals!
  2. 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!
  3. Write a function to convert roman numeral strings into numbers
  4. Write functions for conversions using 'subtractive notation'. This means that instead of writing IIII you write IV.

Using This Repository

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

Requirements

How To

  1. Navigate to the ruby directory
  2. bundle install
  3. Add tests under spec
  4. Add code under lib
  5. Run tests: rspec

JavaScript

Requirements

How To

  1. Navigate to the javascript directory
  2. npm install
  3. Add tests under test
  4. Add code under lib
  5. Run tests: npm test

Elixir

Requirements

How To

  1. Navigate to the elixir directory
  2. mix compile
  3. Add tests under test
  4. Add code under lib
  5. Run tests: mix test

More Learning