Roman Numerals: First Test
Let's practice how to write tests for an existent function.
We'll cover the following...
Practice
Now that we’ve covered the basics of tests in Go, let’s see a practical example in which we’re going to add tests and refactor them. The exercise we’ll rely on is the Roman Numerals Converter kata.
Roman numeral conversion
This is by far one of the most popular katas available. However, let’s refresh its rules for the purposes of this lesson. The Roman symbols that we can use to represent numbers are summarized in the following table:
1 | 5 | 10 | 50 | 100 | 500 | 1000 |
I | IV | X | L | C | D | M |
Other rules are:
- We can’t have more than three equal adjacent symbols, which means that
4
is represented withIV
instead ofIIII
. - Valid numbers that can be converted are only within the
1
to3999
range (extremes included).
The following table has some conversion examples to help clarify the concept:
Decimal | Roman |
9 | IX |
45 | XLV |
99 | XCIX |
222 | CCXXII |
1054 | MLIV |
3999 | MMMCMXCIX |
Implementation
The goal of this exercise is to write a function ...