Write a method String convert(int) that takes a number and converts it to the according String representation.
1 ➔ I
2 ➔ II
3 ➔ III
4 ➔ IV
5 ➔ V
9 ➔ IX
21 ➔ XXI
50 ➔ L
100 ➔ C
500 ➔ D
1000 ➔ M
This kata lures a lot of people to implement features in the order of the numbers. But do not forget that it’s sometimes easier to start with a general case and add exceptions later.
You can test this proyect using go test
. Just run:
go test ./...